FFT算法的完整DSP实现
DFT计算X(k)需要N^2次复数乘法和N(N-1)次复数加法
FFT算法的流程图如下图,总结为3过程3循环:
(1)3过程:单点时域分解(倒位序过程) + 单点时域计算单点频谱 + 频域合成
(2)3循环:外循环——分解次数,中循环——sub-DFT运算,内循环——2点蝶形算法
分解过程或者说倒位序的获得参考下图理解:
FFT的DSP实现
下面为使用C语言实现的FFT及IFFT算法实例,能计算任意以2为对数底的采样点数的FFT,算法参考上面给的流程图。
/*
* zx_fft.h
*
* Created on: 2013-8-5
* Author: monkeyzx
*/
#ifndef ZX_FFT_H_
#define ZX_FFT_H_
typedef float FFT_TYPE;
#ifndef PI
#define PI (3.14159265f)
#endif
typedef struct complex_st {
FFT_TYPE real;
FFT_TYPE img;
} complex;
int fft(complex *x, int N);
int ifft(complex *x, int N);
void zx_fft(void);
#endif /* ZX_FFT_H_ */
[cpp] view plain copy
/*
* zx_fft.c
*
* Implementation of Fast Fourier Transform(FFT)
* and reversal Fast Fourier Transform(IFFT)
*
* Created on: 2013-8-5
* Author: monkeyzx
*/
#include "zx_fft.h"
#include <math.h>
#include <stdlib.h>
/*
* Bit Reverse
* === Input ===
* x : complex numbers
* n : nodes of FFT. @N should be power of 2, that is 2^(*)
* l : count by bit of binary format, @l=CEIL{log2(n)}
* === Output ===
* r : results after reversed.
* Note: I use a local variable @temp that result @r can be set
* to @x and won't overlap.
*/