GD32F303之无限冲击响应滤波

[复制链接]
995|1
 楼主| zeshoufx 发表于 2019-9-3 20:50 | 显示全部楼层 |阅读模式
本帖最后由 zeshoufx 于 2019-9-3 20:51 编辑

一、信号输入
test_in=arm_sin_f32(2*3.1415926*50*i/1000)+arm_sin_f32(2*3.1415926*250*i/1000);
二、测试函数
  1. #include "dsp_filter.h"


  2. #define length 320
  3. #define numstatas 2


  4. static float32_t test_in[320];
  5. static float32_t test_out[320];
  6. static float32_t iir_stata[8];

  7. const float32_t IIRCoeffs32LP[5*numstatas] = {
  8. 1.0f, 2.0f, 1.0f, 1.4797988943972167f, -0.68867695305386178f,
  9. 1.0f, 2.0f, 1.0f, 1.2128120926202184f, -0.38400416228655354f
  10. };

  11. void filter_test(void)
  12. {
  13.         u32 i=0;
  14.         arm_biquad_casd_df1_inst_f32 S;
  15.         float32_t Proportion;
  16.         

  17.         for(i=0;i<length;i++)
  18.         {
  19.                 test_in[i]=arm_sin_f32(2*3.1415926*50*i/1000)+arm_sin_f32(2*3.1415926*250*i/1000);
  20.         }
  21.         arm_biquad_cascade_df1_init_f32(&S,numstatas,(float32_t *)&IIRCoeffs32LP[0],&iir_stata[0]);
  22.         arm_biquad_cascade_df1_f32(&S,test_in,test_out,320);
  23.         Proportion= 0.052219514664161221f * 0.04279801741658381f;
  24.         for(i=0;i<length;i++)
  25.         {
  26.                 printf("%f\r\n",test_out[i]*Proportion);
  27.         }
  28. }



三、结果
185445d6e61516ff87.png
四、主函数

  1. /*
  2.     昆明电器科学研究所 张恩寿 2019年5月3日
  3.         
  4.         
  5. */
  6. #include "bitband.h"
  7. #include "led_config.h"
  8. #include "systick.h"
  9. #include "usart.h"
  10. #include "spi_flash.h"
  11. #include "tft.h"
  12. #include "key_lookup.h"
  13. #include "dsp_filter.h"




  14. int main(void)
  15. {                        
  16.         systick_config(120);
  17.         nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
  18.         usart0_init(115200);
  19.     led_init();
  20.         filter_test();
  21.         
  22.         while(1)
  23.         {
  24.                 led_on();
  25.                 delay_nms(600);
  26.                 led_off();
  27.                 delay_nms(600);
  28.         }
  29.                
  30. }




五、MATLAB函数
  1. gd32=[0.000000
  2. 0.002925
  3. 0.020893
  4. 0.070248
  5. 0.153351
  6. 0.258624
  7. 0.382087
  8. 0.526850
  9. 0.677789
  10. 0.800785
  11. 0.871091
  12. 0.880735
  13. 0.818354
  14. 0.669428
  15. 0.441693
  16. 0.166833
  17. -0.126544
  18. -0.419203
  19. -0.680922
  20. -0.871749
  21. -0.969688
  22. -0.975598
  23. -0.889837
  24. -0.709505
  25. -0.451699
  26. -0.154097
  27. 0.152185
  28. 0.448280
  29. 0.706214
  30. 0.889093
  31. 0.977894
  32. 0.975770
  33. 0.884423
  34. 0.701365
  35. 0.443376
  36. 0.147382
  37. -0.156390
  38. -0.449879
  39. -0.705684
  40. -0.887207
  41. -0.975468
  42. -0.973478
  43. -0.882702
  44. -0.700396
  45. -0.443127
  46. -0.147681
  47. 0.155777
  48. 0.449177
  49. 0.705069
  50. 0.886780
  51. 0.975261
  52. 0.973466
  53. 0.882827
  54. 0.700589
  55. 0.443327
  56. 0.147845
  57. -0.155672
  58. -0.449136
  59. -0.705079
  60. -0.886824
  61. -0.975318
  62. -0.973520
  63. -0.882868
  64. -0.700612
  65. -0.443334
  66. -0.147838
  67. 0.155686
  68. 0.449152
  69. 0.705093
  70. 0.886834
  71. 0.975323
  72. 0.973521
  73. 0.882866
  74. 0.700608
  75. 0.443329
  76. 0.147834
  77. -0.155690
  78. -0.449154
  79. -0.705094
  80. -0.886834
  81. -0.975323
  82. -0.973521
  83. -0.882865
  84. -0.700609
  85. -0.443330
  86. -0.147835
  87. 0.155688
  88. 0.449153
  89. 0.705092
  90. 0.886832
  91. 0.975320
  92. 0.973517
  93. 0.882862
  94. 0.700605
  95. 0.443326
  96. 0.147832
  97. -0.155692
  98. -0.449155
  99. -0.705094
  100. -0.886832
  101. -0.975320
  102. -0.973517
  103. -0.882862
  104. -0.700605
  105. -0.443326
  106. -0.147833
  107. 0.155690
  108. 0.449154
  109. 0.705093
  110. 0.886832
  111. 0.975321
  112. 0.973519
  113. 0.882863
  114. 0.700607
  115. 0.443328
  116. 0.147833
  117. -0.155691
  118. -0.449155
  119. -0.705095
  120. -0.886835
  121. -0.975324
  122. -0.973521
  123. -0.882866
  124. -0.700608
  125. -0.443329
  126. -0.147834
  127. 0.155690
  128. 0.449155
  129. 0.705095
  130. 0.886835
  131. 0.975324
  132. 0.973522
  133. 0.882866
  134. 0.700608
  135. 0.443328
  136. 0.147833
  137. -0.155692
  138. -0.449157
  139. -0.705098
  140. -0.886838
  141. -0.975327
  142. -0.973524
  143. -0.882867
  144. -0.700608
  145. -0.443327
  146. -0.147831
  147. 0.155694
  148. 0.449159
  149. 0.705099
  150. 0.886840
  151. 0.975329
  152. 0.973527
  153. 0.882871
  154. 0.700614
  155. 0.443335
  156. 0.147839
  157. -0.155687
  158. -0.449154
  159. -0.705096
  160. -0.886838
  161. -0.975328
  162. -0.973527
  163. -0.882872
  164. -0.700616
  165. -0.443336
  166. -0.147841
  167. 0.155684
  168. 0.449150
  169. 0.705090
  170. 0.886830
  171. 0.975319
  172. 0.973517
  173. 0.882862
  174. 0.700606
  175. 0.443329
  176. 0.147837
  177. -0.155684
  178. -0.449147
  179. -0.705086
  180. -0.886827
  181. -0.975318
  182. -0.973519
  183. -0.882866
  184. -0.700611
  185. -0.443332
  186. -0.147837
  187. 0.155688
  188. 0.449153
  189. 0.705092
  190. 0.886832
  191. 0.975320
  192. 0.973517
  193. 0.882862
  194. 0.700606
  195. 0.443330
  196. 0.147838
  197. -0.155684
  198. -0.449148
  199. -0.705089
  200. -0.886831
  201. -0.975321
  202. -0.973521
  203. -0.882866
  204. -0.700609
  205. -0.443330
  206. -0.147834
  207. 0.155690
  208. 0.449154
  209. 0.705093
  210. 0.886832
  211. 0.975319
  212. 0.973516
  213. 0.882861
  214. 0.700605
  215. 0.443328
  216. 0.147835
  217. -0.155688
  218. -0.449153
  219. -0.705094
  220. -0.886835
  221. -0.975325
  222. -0.973523
  223. -0.882867
  224. -0.700609
  225. -0.443328
  226. -0.147832
  227. 0.155692
  228. 0.449156
  229. 0.705096
  230. 0.886835
  231. 0.975324
  232. 0.973522
  233. 0.882868
  234. 0.700613
  235. 0.443335
  236. 0.147841
  237. -0.155684
  238. -0.449150
  239. -0.705093
  240. -0.886835
  241. -0.975326
  242. -0.973525
  243. -0.882870
  244. -0.700613
  245. -0.443333
  246. -0.147836
  247. 0.155690
  248. 0.449155
  249. 0.705096
  250. 0.886837
  251. 0.975326
  252. 0.973525
  253. 0.882870
  254. 0.700614
  255. 0.443335
  256. 0.147840
  257. -0.155684
  258. -0.449150
  259. -0.705091
  260. -0.886832
  261. -0.975321
  262. -0.973519
  263. -0.882863
  264. -0.700605
  265. -0.443327
  266. -0.147834
  267. 0.155687
  268. 0.449148
  269. 0.705084
  270. 0.886822
  271. 0.975311
  272. 0.973511
  273. 0.882861
  274. 0.700609
  275. 0.443335
  276. 0.147843
  277. -0.155681
  278. -0.449148
  279. -0.705092
  280. -0.886837
  281. -0.975329
  282. -0.973528
  283. -0.882871
  284. -0.700612
  285. -0.443331
  286. -0.147835
  287. 0.155688
  288. 0.449151
  289. 0.705090
  290. 0.886830
  291. 0.975321
  292. 0.973522
  293. 0.882870
  294. 0.700618
  295. 0.443341
  296. 0.147847
  297. -0.155679
  298. -0.449147
  299. -0.705091
  300. -0.886833
  301. -0.975323
  302. -0.973521
  303. -0.882866
  304. -0.700609
  305. -0.443332
  306. -0.147840
  307. 0.155680
  308. 0.449142
  309. 0.705082
  310. 0.886824
  311. 0.975316
  312. 0.973520
  313. 0.882870
  314. 0.700618
  315. 0.443341
  316. 0.147847
  317. -0.155678
  318. -0.449144
  319. -0.705086
  320. -0.886827
  321. ];
  322. fs=1000;
  323. N=320;
  324. n=0:N-1;
  325. t=n/fs;
  326. f=n*fs/N;
  327. b=fir1(28,0.25);
  328. x=sin(2*pi*50*t)+sin(2*pi*250*t);
  329. x1=sin(2*pi*50*t);
  330. y=filter(b,1,x);
  331. subplot(311)
  332. plot(t,x),title('未滤波效果'),xlabel('时间'),ylabel('幅值'),grid;
  333. subplot(312)
  334. plot(t,x1),title('MATLAB 基波'),xlabel('时间'),ylabel('幅值'),grid;
  335. subplot(313)
  336. plot(t,gd32),title('GD32F303 IIR滤波效果'),xlabel('时间'),ylabel('幅值'),grid;



780415d6e61296d77d.png

评论

自己顶一个  发表于 2019-9-5 11:04
您需要登录后才可以回帖 登录 | 注册

本版积分规则

67

主题

1991

帖子

15

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