void fft(COMPLEX *x, int m)
{
COMPLEX *w; /* used to store the w complex array */
int mstore = 0; /* stores m for future reference */
int n = 1; /* length of fft stored for future */
COMPLEX u,temp,tm;
COMPLEX *xi,*xip,*xj,*wptr;
int i,j,k,l,le,windex;
double arg,w_real,w_imag,wrecur_real,wrecur_imag,wtemp_real;
if(m != mstore) {
/* free previously allocated storage and set new m */
if(mstore != 0) free(w);
mstore = m;
if(m == 0) return; /* if m=0 then done */
/* n = 2**m = fft length */
n = 1 << m;
le = n/2;
/* allocate the storage for w */
w = (COMPLEX *) calloc(le-1,sizeof(COMPLEX));
if(!w) {
printf("\nUnable to allocate complex W array\n");
exit(1);
}
/* calculate the w values recursively */
arg = 4.0*atan(1.0)/le; /* PI/le calculation */
wrecur_real = w_real = cos(arg);
wrecur_imag = w_imag = -sin(arg);
xj = w;
for (j = 1 ; j < le ; j++) {
xj->real = (float)wrecur_real;
xj->imag = (float)wrecur_imag;
xj++;
wtemp_real = wrecur_real*w_real - wrecur_imag*w_imag;
wrecur_imag = wrecur_real*w_imag + wrecur_imag*w_real;
wrecur_real = wtemp_real;
}
}
/* start fft */
le = n;
windex = 1;
for (l = 0 ; l < m ; l++) {
le = le/2;
/* first iteration with no multiplies */
for(i = 0 ; i < n ; i = i + 2*le) {
xi = x + i;
xip = xi + le;
temp.real = xi->real + xip->real;
temp.imag = xi->imag + xip->imag;
xip->real = xi->real - xip->real;
xip->imag = xi->imag - xip->imag;
*xi = temp;
}
/* remaining iterations use stored w */
wptr = w + windex - 1;
for (j = 1 ; j < le ; j++) {
u = *wptr;
for (i = j ; i < n ; i = i + 2*le) {
xi = x + i;
xip = xi + le;
temp.real = xi->real + xip->real;
temp.imag = xi->imag + xip->imag;
tm.real = xi->real - xip->real;
tm.imag = xi->imag - xip->imag;
xip->real = tm.real*u.real - tm.imag*u.imag;
xip->imag = tm.real*u.imag + tm.imag*u.real;
*xi = temp;
}
wptr = wptr + windex;
}
windex = 2*windex;
}
/* rearrange data by bit reversing */
j = 0;
for (i = 1 ; i < (n-1) ; i++) {
k = n/2;
while(k <= j) {
j = j - k;
k = k/2;
}
j = j + k;
if (i < j) {
xi = x + i;
xj = x + j;
temp = *xj;
*xj = *xi;
*xi = temp;
}
}
free(w);
w=NULL;
}
分享到:
相关推荐
fft c语言实现,快速傅里叶运算的c语言实现
fft的c语言实现
快速傅里叶变换的C语言实现 给出了封装好的接口 方便直接调用。
采用频域分解法的快速傅里叶变化(FFT)进行了C语言的实现,可用于频域分析(如电力中的电压电流谐波分析)。
这是一个基于C语言的FFT程序,完美实现了FFT变换,适合作为信号系统的作业。
快速傅立叶变化的fft算法的C语言实现。
FFT算法的C语言实现,采用倒位序算法,蝶形运算实现谐波计算
C语言实现FFT,实测效果极好,可经过修改实现二维FFT,以及FFT反变换。
FFT算法的C语言实现 很好很强大 很不错的
FFT的C语言算法实现,FFT的C语言算法实现,FFT的C语言算法实现。
自己编写的,能够实现任意点数的FFT运算的函数 结果和用MATLAB计算结果一样
一个利用C语言,仿真实现定点FFT算法的程序:)
快速傅里叶变换 (fast Fourier transform), 即利用计算机计算离散傅里叶变换(DFT...本程序以C语言为平台,实现了按时间抽取的基-2FFT算法(蝶形算法)。具体见https://blog.csdn.net/SXGY_07/article/details/87902235
C语言实现FFT变换
128点FFT的C语言实现,附详细的FFT实现过程讲解
c语言实现的fft算法,代码中先做码位置换,再做蝶形运算
7128点 :3.09864ms使用方法指导:1,需要两个文件,fft_fp.c和fft_fp.h2,根据需求修改fft_fp.h中的采样点数FFT_N,采样点数以宏定义的方式定义3,外部声明两个全局变量,已经在fft_fp.c中定义extern struct compx ...
这是在DSP上有c语言实现FFT变换的代码