授之以渔: 几个例子弄清复立叶变换的应用

[复制链接]
53828|245
kubuco 发表于 2010-9-3 08:25 | 显示全部楼层
圈圈很久前有个讲傅立叶变换的帖子。。可以找来学习。。图文都有生动。。少了LZ 的这么多的代码。建议初学者入门看那个。
wlzhzhlm 发表于 2010-9-3 11:18 | 显示全部楼层
顶啊讲啊,不然我们到哪里学啊!
Xflyan 发表于 2010-9-3 11:30 | 显示全部楼层
搬个板凳 学习!
xixihaha0 发表于 2010-9-3 12:59 | 显示全部楼层
楼主的第一点记得是我毕业那一年吉林省的电子设计大赛的一原装题目,当时记得东北电力的学生直接拿的产品去,老师都帮学生做,哎,数字信息处理的基础都忘了,得翻书温习一下才有些概念
xixihaha0 发表于 2010-9-3 13:05 | 显示全部楼层
Quentin 发表于 2010-9-3 15:03 | 显示全部楼层
xuyiyi 发表于 2010-9-3 17:25 | 显示全部楼层
圈圈很久前有个讲傅立叶变换的帖子。。可以找来学习。。图文都有生动。。少了LZ 的这么多的代码。建议初学者入门看那个。
kubuco 发表于 2010-9-3 08:25



找来看看,写的不错。
圈圈的第三个AT91SAM7S64测试程序横空出世~~~FFT显示频谱~~~
https://bbs.21ic.com/viewthread.php?tid=119652&extra=&highlight=&page=4
zj1 发表于 2010-9-4 21:29 | 显示全部楼层
认真听课
张广伟 发表于 2010-9-4 21:36 | 显示全部楼层
想听听,不知道楼主什么时间开课!~期待,不要太监就好
我是大婶 发表于 2010-9-4 21:43 | 显示全部楼层
leexaut 发表于 2010-9-4 22:25 | 显示全部楼层
捧场,听讲。
wxw123321 发表于 2010-9-5 12:10 | 显示全部楼层
顶起,期待中
cuya 发表于 2010-9-5 21:53 | 显示全部楼层
本帖最后由 cuya 于 2010-9-5 22:04 编辑

 楼主| highgear 发表于 2010-9-5 22:08 | 显示全部楼层
已经讲完了, fft 没有太多的东西好讲。这样吧, 我放出定点c++ 的 fft 以及逆变换的程序,供大家参考

  1. class CComplex
  2. {
  3. public:
  4. short R;
  5. short I;
  6. CComplex() {}
  7. CComplex(short r, short i)  { R = r; I = i; }
  8. void Set(short r, short i) { R = r; I = i; }
  9. CComplex(CComplex& complex) { R = complex.R; I = complex.I; }
  10. inline void operator=(CComplex& complex)  { R = complex.R; I = complex.I; }
  11. void operator+=(CComplex& complex)
  12. {
  13.   R += complex.R;
  14.   I += complex.I;
  15. }
  16. void operator-=(CComplex& complex)
  17. {
  18.   R -= complex.R;
  19.   I -= complex.I;
  20. }
  21. inline void Add(CComplex& c1, CComplex& c2)
  22. {
  23.   R = c1.R + c2.R;
  24.   I = c1.I + c2.I;
  25. }
  26. inline void Sub(CComplex& c1, CComplex& c2)
  27. {
  28.   R = c1.R - c2.R;
  29.   I = c1.I - c2.I;
  30. }
  31. inline void Add(CComplex& c1, CComplex& c2, int shift)
  32. {
  33.   R = (c1.R + c2.R) >> shift;
  34.   I = (c1.I + c2.I) >> shift;
  35. }
  36. inline void Sub(CComplex& c1, CComplex& c2, int shift)
  37. {
  38.   R = (c1.R - c2.R) >> shift;
  39.   I = (c1.I - c2.I) >> shift;
  40. }

  41. inline void Mul(CComplex& c1, CComplex& c2, int shift)
  42. {
  43.   R = (c1.R * c2.R + c1.I * c2.I) >> shift;
  44.   I = (c1.I * c2.R - c1.R * c2.I) >> shift;
  45. }
  46. inline void MulConj(CComplex& c1, CComplex& c2, int shift)
  47. {
  48.   R = (c1.R * c2.R - c1.I * c2.I) >> shift;
  49.   I = (c1.I * c2.R + c1.R * c2.I) >> shift;
  50. }

  51. inline void Shift(int n) { R >>= n; I >>= n; }
  52. };


在嵌入式,构造函数中的 BitReversal, W 数组应该预先离线计算

  1. class CFFT
  2. {
  3. protected:
  4. static const int N = 32;
  5. CComplex W[N];
  6. int BitReversal[N];
  7. public:
  8. CComplex Y[N];
  9. protected:
  10. void ReverseBit()
  11. {
  12.   int rev = 0;
  13.   int t = N/2;
  14.   int mask;
  15.   for (int i = 0; i < N-1; i++) {
  16.    BitReversal = rev;
  17.    mask = t;
  18.    while (rev >= mask) {
  19.     rev -= mask;
  20.     mask >>= 1;
  21.    }
  22.    rev += mask;
  23.   }
  24.   BitReversal[N-1] = N-1;
  25. }
  26. public:
  27. CFFT()
  28. {
  29.   for (int i=0; i<N; i++) {
  30.    W.R = (short) ( ::cos(PI * 2*i / N) * 16384 + 0.5);
  31.    W.I = (short) (-::sin(PI * 2*i / N) * 16384 + 0.5);
  32.   }
  33.   ReverseBit();
  34. }
  35. void Calculate(short* x)
  36. {
  37.   short t;
  38.   int i, j, n, index1, index2, indexW, di;
  39.   CComplex result;
  40.   for(i=0; i<N; i++) {
  41.    n = BitReversal;
  42.    if(n > i) {
  43.     t = x;
  44.     x = x[n];
  45.     x[n] = t;
  46.    }
  47.    }
  48.   for (i=0; i<N; i+=2) {
  49.    t = x[i+1];
  50.    Y.Set(x + t, 0);
  51.    Y[i+1].Set(x - t, 0);
  52.   }
  53.   for (di=N>>2, n=2; n<N; n<<=1, di >>= 1) {
  54.    for (j=0; j<N; j+=(n<<1)) {
  55.     indexW = 0;
  56.     for (i=0; i<n; i++) {
  57.      index1 = i + j;
  58.      index2 = index1 + n;
  59.      result.Mul(Y[index2], W[indexW], 14);
  60.      Y[index2].Sub(Y[index1], result, 1);
  61.      Y[index1].Add(Y[index1], result, 1);
  62.      indexW += di;
  63.     }
  64.    }
  65.   }
  66. }
  67. void Inverse()
  68.     {
  69.   int i, j, n, index1, index2, indexW, di;
  70.   CComplex result;
  71.   for(i=0; i<N; i++) {
  72.    n = BitReversal;
  73.    if(n > i) {
  74.     result = Y;
  75.     Y = Y[n];
  76.     Y[n] = result;
  77.    }
  78.    }
  79.   for (i=0; i<N; i+=2) {
  80.    result = Y[i+1];
  81.    Y[i+1].Sub(Y, result, 1);
  82.    Y.Add(Y, result, 1);
  83.   }
  84.   for (di=N>>2, n=2; n<N; n<<=1, di >>= 1) {
  85.    for (j=0; j<N; j+=(n<<1)) {
  86.     indexW = 0;
  87.     for (i=0; i<n; i++) {
  88.      index1 = i + j;
  89.      index2 = index1 + n;
  90.      result.MulConj(Y[index2], W[indexW], 14);
  91.      Y[index2].Sub(Y[index1], result);
  92.      Y[index1].Add(Y[index1], result);
  93.      indexW += di;
  94.     }
  95.    }
  96.   }
  97.     }
  98. };

评分

参与人数 1威望 +1 收起 理由
xuyiyi + 1

查看全部评分

xuyiyi 发表于 2010-9-6 07:18 | 显示全部楼层
顶!
highgear老师的沙发!
原野之狼 发表于 2010-9-7 02:03 | 显示全部楼层
顶出水面
徒然一生 发表于 2010-9-7 08:54 | 显示全部楼层
看下,有那么点兴趣
johnwjl 发表于 2010-9-7 11:45 | 显示全部楼层
大师讲课果然不同凡响,我顶!
fover 发表于 2010-9-7 17:35 | 显示全部楼层
82# 粉丝
期待你与楼主的讨论切磋,或者更详细的解说,让我们能更深入的掌握单片机傅里叶
zhufdf 发表于 2010-10-6 15:47 | 显示全部楼层
好东西 我试试,先下了再说
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 在线客服 返回列表 返回顶部