打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
网上找的纯C实现的FFT,与matlab计算结果完全一样

直接上代码了

fft.c

  1. #include "math.h"
  2. #include "fft.h"
  3. //精度0.0001弧度
  4. void conjugate_complex(int n,complex in[],complex out[])
  5. {
  6. int i = 0;
  7. for(i=0;i<n;i++)
  8. {
  9. out[i].imag = -in[i].imag;
  10. out[i].real = in[i].real;
  11. }
  12. }
  13. void c_abs(complex f[],float out[],int n)
  14. {
  15. int i = 0;
  16. float t;
  17. for(i=0;i<n;i++)
  18. {
  19. t = f[i].real * f[i].real + f[i].imag * f[i].imag;
  20. out[i] = sqrt(t);
  21. }
  22. }
  23. void c_plus(complex a,complex b,complex *c)
  24. {
  25. c->real = a.real + b.real;
  26. c->imag = a.imag + b.imag;
  27. }
  28. void c_sub(complex a,complex b,complex *c)
  29. {
  30. c->real = a.real - b.real;
  31. c->imag = a.imag - b.imag;
  32. }
  33. void c_mul(complex a,complex b,complex *c)
  34. {
  35. c->real = a.real * b.real - a.imag * b.imag;
  36. c->imag = a.real * b.imag + a.imag * b.real;
  37. }
  38. void c_div(complex a,complex b,complex *c)
  39. {
  40. c->real = (a.real * b.real + a.imag * b.imag)/(b.real * b.real +b.imag * b.imag);
  41. c->imag = (a.imag * b.real - a.real * b.imag)/(b.real * b.real +b.imag * b.imag);
  42. }
  43. #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
  44. void Wn_i(int n,int i,complex *Wn,char flag)
  45. {
  46. Wn->real = cos(2*PI*i/n);
  47. if(flag == 1)
  48. Wn->imag = -sin(2*PI*i/n);
  49. else if(flag == 0)
  50. Wn->imag = -sin(2*PI*i/n);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
快速傅里叶变换FFT的C程序代码实现
double_operator.cpp
从零开始学习FFT(快速傅里叶变换) 这也是我学习dft算法的心得,谢谢各位
一个类型问题
运算符重载
C 运算符重载探讨
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服