標題: 快速FFT變換C語言程序 [打印本頁]

作者: IQ_kuo    時間: 2019-5-31 15:03
標題: 快速FFT變換C語言程序
快速FFT變換源程序
  1. #include <stdio.h>
  2. #include <math.h>

  3. typedef struct                                                                                        //定義復數(shù)結(jié)構(gòu)體變量
  4. {
  5.         double real;
  6.         double imag;
  7. }complex;

  8. #define N 5

  9. #define PI 3.1514926535897932384626433832795028841971        //定義圓周率

  10. void c_plus(complex, complex, complex *);                                //復數(shù)加運算
  11. void c_sub(complex, complex, complex *);                                //復數(shù)減運算o
  12. void c_mul(complex, complex, complex *);                                //復數(shù)乘運算
  13. void Wn_i(int, int, complex *);                                                    //旋轉(zhuǎn)因子

  14. int main()
  15. {
  16.         complex f[N] = { 1, 2, 2, 3 };
  17.         complex wn;
  18.         Wn_i(8, 3, &wn);
  19.         c_mul(f[0], wn, &f[2]);
  20.         c_sub(f[1], f[2], &(f[3]));
  21.         c_plus(f[1], f[2], &(f[4]));
  22.         printf("f[%d]為:%lf + %lf        \n", 2, f[2].real, f[2].imag);
  23.         printf("f[%d]為:%lf + %lf        \n", 3, f[3].real, f[3].imag);
  24.         printf("f[%d]為:%lf + %lf        \n", 4, f[4].real, f[4].imag);
  25.         return 0;
  26. }

  27. void c_plus(complex a, complex b, complex *c)                        //復數(shù)加法
  28. {
  29.         c->real = a.real + b.real;
  30.         c->imag = a.imag + b.imag;
  31. }
  32. void c_sub(complex a, complex b, complex *c)                        //復數(shù)減法
  33. {
  34.         c->real = a.real - b.real;
  35.         c->imag = a.imag - b.imag;
  36. }
  37. void c_mul(complex a, complex b, complex *c)                        //復數(shù)乘法
  38. {
  39.         c->real = a.real*b.real - a.imag*b.imag;
  40.         c->imag = a.real*b.imag + a.imag*b.real;
  41. }

  42. void Wn_i(int n1, int i, complex *Wn)                                        //定義旋轉(zhuǎn)因子
  43. {
  44.         Wn->real = cos(2 * PI*i / n1);
  45.         Wn->imag = -sin(2 * PI*i / n1);
  46. }
復制代碼

全部資料51hei下載地址:
fft.zip (699 Bytes, 下載次數(shù): 43)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1