使用FFTW作FFT变换

通常FFT分析,都是求一个时间历程的频率成分,php

用FFTW中的ui

fftw_plan_dft_r2c_1dspa

输入是一个实数列向量in[N],blog

输出是一个复数空间二维矩阵out[N][2],第1列是实数、第2列是复数。ci

 

求幅值时,要对复数向量的每一个,取向量模,乘以2,再除以点数N。get

注意:table

1. 若是采样时间不到 1 s, 就设法补成 1 s。方法

一种方法是补零,(参考 彭真明 老师博文 link2 )im

还有一种方法,若是已知频率大概范围,折算出周期后,用正周期的时间历程估计。d3

 

2. 若是有直流项(平均值大于零),须要把直流项滤掉。

 

   fftw_complex *out = NULL;
   fftw_plan p;
   in  = (double *)fftw_malloc(sizeof(double) * len);
   out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * len);
 
   p = fftw_plan_dft_r2c_1d(len, in, out, FFTW_ESTIMATE);
   fftw_execute(p);
 
   for (int i = 0; i < len; i++)
   {
         amp  = sqrt(out[i][0]*out[i][0] + out[i][1]*out[i][1]);
         amp  = 2.0* amp/len;
         freq  =  i*1.0/t1;
   }
相关文章
相关标签/搜索