[討論] fdatool設計IIR濾波器

看板MATLAB作者 (超哥)時間12年前 (2013/03/12 14:37), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
各位板友大家好: 我最近想設計一個cut-off frequency為0.5的Low pass filter,我使用了fdatool IIR butterworth,設計出的濾波器為 Order=13, sections=7的 Direct-FormII Second-Order Sections的濾波器。而產生出的C header file如下: #define MWSPT_NSEC 15 const int NL[MWSPT_NSEC] = { 1,3,1,3,1,3,1,3,1,3,1,3,1,2,1 }; const float NUM[MWSPT_NSEC][3] = { //分子的係數 { 0.001711965189, 0, 0 //Gain }, { 1, 2, 1 //Numerator }, { 0.001679621288, 0, 0 //Gain }, { 1, 2, 1 //Numerator }, { 0.001651172643, 0, 0 }, { 1, 2, 1 }, { 0.001627864782, 0, 0 }, { 1, 2, 1 }, { 0.001610610518, 0, 0 }, { 1, 2, 1 }, { 0.001600023941, 0, 0 }, { 1, 2, 1 }, { 0.03995568678, 0, 0 }, { 1, 1, 0 }, { 1, 0, 0 } }; const int DL[MWSPT_NSEC] = { 1,3,1,3,1,3,1,3,1,3,1,3,1,2,1 }; const float DEN[MWSPT_NSEC][3] = { //分母 { 1, 0, 0 //Gain }, { 1, -1.973319173, 0.9801670909 //Denominator }, { 1, 0, 0 //Gain }, { 1, -1.93603766, 0.942756176 //Denominator }, { 1, 0, 0 }, { 1, -1.903245926, 0.9098505974 }, { 1, 0, 0 }, { 1, -1.876379848, 0.8828913569 }, { 1, 0, 0 }, { 1, -1.856491446, 0.8629338741 }, { 1, 0, 0 }, { 1, -1.844288707, 0.8506888151 }, { 1, 0, 0 }, { 1, -0.9200886488, 0 }, { 1, 0, 0 } }; 我想問的是,像它有7個section,每個section為second order,是要將訊號經過七次的 section做係數運算,如y(k)=b1y(k-1)+a0x(k)+a1x(k-1),並在各section的係數運算前 還要經過Gain值的運算。如: int16 iir_filter(int16 in) { uint16 i; x[0][0] = in; for(i=0;i<MWSPT_NSEC;i++) { y[0]= x[i][0]*NUM[i][0]+x[i][1]*NUM[i][1] +x[i][2]*NUM[i][2]-y[1]*DEN[i][1]-y[2]*DEN[i][2]; y[0] /= DEN[i][0]; y[2]=y[1];y[1]=y[0]; x[i+1][2]=x[i][1];x[i+1][1]=x[i][0]; x[i+1][0] = y[0]; } if( x[MWSPT_NSEC][0]>32767) x[MWSPT_NSEC][0]=32767; if( x[MWSPT_NSEC][0]<-32768) x[MWSPT_NSEC][0]=-32768; return ((int16)x[MWSPT_NSEC][0]); } 請問是這樣應用上去的嗎?? 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 120.126.41.105 ※ 編輯: jeffchen106 來自: 120.126.41.105 (03/12 15:24)
文章代碼(AID): #1HFiqs9j (MATLAB)