0
本帖最后由 agdhun 于 2016-4-24 22:32 编辑
今天把FFT又看了几遍,FFT实质是对一些特殊方阵的快速算法;FFT有两种方向一种是时域抽取,一种是频域抽取,而相同点是顺序会被打乱,但是打乱的顺序还是有规律的,为位反序,例如8位的{0,1,2,3,4,5,6,7},出来乱序为{0,4,2,6,1,5,3,7},可以发现:0 000 0 000
1 001 4 100
2 010 2 010
3 011 6 110
4 100 1 001
5 101 5 101
6 110 3 011
7 111 7 111
如果但是计算时可就没这幸运了,得一步一步反向计算;DSPF_sp_fftSPxSP_r2c函数有一些参数,事实上需要的不过是输入输出信号,和变换点数N;
N:FFT的点数;*ptr_x:输入信号;
*ptr_w:优化的旋转因子表;
*ptr_y:输出信号;
*brev:倒置数组;
n_min:若N是4的n次幂,取4,否则取2;
offset:通常为0;
n_max:N;
而brev和ptr_w是内定的。
brev数组:
- unsigned char brev[64] =
- {
- 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
- 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
- 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
- 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
- 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
- 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
- 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
- 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f
- };
复制代码
优化额旋转因子表生成函数:
- void tw_gen(float *w, int n)
- {
- int i, j, k;
- for(i = 1, k = 0; i < n >> 2; i++)
- {
- w[k ] = sin(2 * PI * i / n);
- w[k + 1] = cos(2 * PI * i / n);
- k += 2;
- }
- for(j = 1; j <= n >> 3; j = j << 2)
- {
- for(i = 0; i < n >> 3; i += j)
- {
- w[k] = (float)sin( 4 * PI * i / n);
- w[k + 1] = (float)cos( 4 * PI * i / n);
- w[k + 2] = (float)sin( 8 * PI * i / n);
- w[k + 3] = (float)cos( 8 * PI * i / n);
- w[k + 4] = (float)sin(12 * PI * i / n);
- w[k + 5] = (float)cos(12 * PI * i / n);
- k += 6;
- }
- }
- }
复制代码
接着用板子测试一下:
|
|