matlab希尔伯特变换器,MATLAB库函数hilbert(希尔伯特变换)的C语言实现(FFT采用FFTW库)...

MATLAB库函数hilbert(希尔伯特变换)的C语言实现(FFT采用FFTW库)

MATLAB库函数hilbert(希尔伯特变换)的C语言实现(FFT采用FFTW库)

目录

希尔伯特变换原理公式

MATLAB官方帮助文档中希尔伯特变换算法

C语言实现(FFTW库的float版,double版类似)

希尔伯特变换原理公式

77920e7776f400c0e0c3ec0cf3432b5d.png

66b4b2b9194ea14db92554a5def7c876.png

MATLAB官方帮助文档中希尔伯特变换算法

hilbert uses a four-step algorithm:

Calculate the FFT of the input sequence, storing the result in a vector x.

Create a vector h whose elements h(i) have the values:

1 for i = 1, (n/2)+1

2 for i = 2, 3, ... , (n/2)

0 for i = (n/2)+2, ... , n

Calculate the element-wise product of x and h.

Calculate the inverse FFT of the sequence obtained in step 3 and returns the first n elements of the result.

C语言实现(FFTW库的float版,double版类似)

#include "fftw3.h"

/*

in - 输入数据指针

out - 希尔伯特变换结果数组指针

N - 数据长度

*/

void hilbert(float* in, fftwf_complex* out,int N)

{

// copy the data into the complex array

for (int i = 0; i < N; ++i)

{

out[i][REAL] = in[i];

out[i][IMAG] = 0;

}

//create a DFT plan and execute it

fftwf_plan plan = fftwf_plan_dft_r2c_1d(N, in, out, FFTW_ESTIMATE);

fftwf_execute(plan);

//destroy the plan to prevent a memory leak

fftwf_destroy_plan(plan);

int hN = N >> 1;// half of the length (N /2)

int numRem = hN;// the number of remaining elements

// multiply the appropriate values by 2

// (those that should be multiplied by 1 are left intact because they wouldn't change)

for (int i = 1; i < hN; ++i) // 1,2,...,N/2 - 1 的项乘以2

{

out[i][REAL] *= 2;

out[i][IMAG] *= 2;

}

// if the length is even, the number of remaining elements decreases by 1

if (N % 2 == 0)

numRem--;

// if it's odd and greater than 1, the middle value must be multiplied by 2

else if (N > 1) // 奇数非空

{

out[hN][REAL] *= 2;

out[hN][IMAG] *= 2;

}

// set the remaining values to 0

// (multiplying by 0 gives 0, so we don't care about the multiplicands)

memset(&out[hN + 1][REAL], 0, numRem * sizeof(fftwf_complex));

// create an IDFT plan and execute it

plan = fftwf_plan_dft_1d(N, out, out, FFTW_BACKWARD, FFTW_ESTIMATE);

fftwf_execute(plan);

// do some cleaning

fftwf_destroy_plan(plan);

fftwf_cleanup();

// scale the IDFT output

for (int i = 0; i < N; ++i)

{

out[i][REAL] /= N;

out[i][IMAG] /= N;

}

}

MATLAB库函数hilbert(希尔伯特变换)的C语言实现(FFT采用FFTW库)相关教程

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值