版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)習(xí)題目 fir和iir濾波器設(shè)計(jì) 班 級(jí): 信息08-1 姓 名: 學(xué) 號(hào): 04號(hào) 指導(dǎo)教師: 實(shí)驗(yàn)日期: 2011.12.5-2011.12.9 目 錄一、 實(shí)習(xí)目的2二、 實(shí)習(xí)要求2三、 濾波器的實(shí)現(xiàn)2(一)、有限沖激響應(yīng)濾波器(fir)的實(shí)現(xiàn)2(二)、無限沖激響應(yīng)濾波器(iir)的實(shí)現(xiàn)5五、 程序代碼及運(yùn)行結(jié)果8(一)、fir濾波器程序代碼81、fir低通濾波器實(shí)現(xiàn)82、fir高通濾波器實(shí)現(xiàn)103、fir帶通濾波器實(shí)現(xiàn)134、fir帶阻濾波器實(shí)現(xiàn)16(二)、iir濾波器程序代碼191、iir低通濾波器實(shí)現(xiàn)192、iir高通濾波器實(shí)現(xiàn)203、iir帶通濾波器實(shí)現(xiàn)224、iir帶阻濾波器
2、實(shí)現(xiàn)23六、 實(shí)習(xí)總結(jié)25七、 實(shí)習(xí)心得26七、參考文獻(xiàn)27fir和iir濾波器設(shè)計(jì)一、 實(shí)習(xí)目的1、 掌握數(shù)字濾波器的設(shè)計(jì)過程;2、 了解fir和iir的原理和特性;3、 熟悉設(shè)計(jì)fir和iir數(shù)字濾波器的原理和方法。二、 實(shí)習(xí)要求1、 通過matlsb設(shè)計(jì)確定fir和iir濾波器系數(shù);2、 dsp初始化。3、 a/d采樣;4、 fir和iir運(yùn)算,觀察濾波器前后的波形變化;5、 對(duì)帶有噪聲的不同輸入信號(hào)進(jìn)行fir和iir濾波,觀察濾掉后噪聲后的波形;6、 熟練使用ccs 對(duì)程序進(jìn)行調(diào)試。3、 濾波器的實(shí)現(xiàn) (一)、有限沖激響應(yīng)濾波器(fir)的實(shí)現(xiàn) 1、fir濾波器的基本結(jié)構(gòu) 數(shù)字濾波是將
3、輸入的信號(hào)序列,按規(guī)定的算法進(jìn)行處理,從而得到所期望的輸出序列。 一個(gè)線性位移不變系統(tǒng)的輸出序列y(n)和輸入序列x(n)之間的關(guān)系,應(yīng)滿足常系數(shù)線性差分方程: 其中x(n)為輸入序列,y(n)為輸出序列,ai、bi為濾波器系數(shù)n為濾波器的階數(shù)。 當(dāng)上式所有的ai均為0,則得fir濾波器的差分方程: 對(duì)式進(jìn)行z變換,可得fir濾波器的傳遞函數(shù): fir濾波器的結(jié)構(gòu)圖如圖1所示。 圖1 fir濾波器的結(jié)構(gòu) 2、有限沖激響應(yīng)濾波器的matlab設(shè)計(jì) fir濾波器系數(shù)的產(chǎn)生可以通過matlab得到。matlab是math works公司用于數(shù)值計(jì)算和信號(hào)處理的數(shù)學(xué)計(jì)算工具包,可以方便直觀地進(jìn)行分析、
4、計(jì)算和系統(tǒng)仿真 。 fir濾波器設(shè)計(jì)有兩種實(shí)現(xiàn)方法:方法1:直接通過matlab的濾波器設(shè)計(jì)函數(shù),其語法如下: b=fir1(n,wn) b=fir1(n,wn,ftype) b=fir1(n,wn,window) b=fir1(n,wn,ftype,window) 其中n為濾波器的階數(shù),wn為濾波器的截止頻率,ftype用來決定濾波器的類型, 當(dāng)ftype=high時(shí),可設(shè)計(jì)高通濾波器; 當(dāng)ftype=stop時(shí),可設(shè)計(jì)帶阻濾波器。window用來指定濾波器采用的窗函數(shù)類型,其默認(rèn)值為漢明(hamming)窗。 方法2:采用濾波器設(shè)計(jì)工具箱來設(shè)計(jì)濾波器的參數(shù),可以方便地得到所需濾波器。該方法
5、按照如下步驟來實(shí)現(xiàn): (1) 打開matlab濾波器設(shè)計(jì)工具箱中的濾波器設(shè)計(jì)與分析工具(fdatool)。 (2) 在濾波器設(shè)計(jì)頁(yè)面中設(shè)置濾波器參數(shù): 濾波器類型選擇帶通;設(shè)計(jì)方法選擇fir(有限沖激響應(yīng)濾波器)、窗函數(shù)法設(shè)計(jì);濾波器階數(shù)選擇最小階數(shù),窗類型采用kaiser窗;頻率選擇歸一化頻率,阻帶1設(shè)為0.15,通帶1設(shè)為0.2,通帶2設(shè)為0.5,阻帶2設(shè)為0.55;幅度單位選分貝,阻帶1設(shè)為20db,通帶設(shè)為1db,阻帶2設(shè)為20db。(3) 單擊設(shè)計(jì)濾波器按鈕,在右上窗口可以看到所設(shè)計(jì)濾波器的幅頻、相頻等各種圖形。 (4) 在file菜單,選擇“export”子菜單出現(xiàn)export窗口
6、,選擇輸出到text-file,單擊“ok”按鈕即可將參數(shù)輸出到指定文件中。本次實(shí)習(xí)選用方法1來求fir濾波器的系數(shù)。 3、fir濾波器dsp實(shí)現(xiàn) fir濾波器的輸出表達(dá)式: y(n)=b0x(n)+b1x(n-1)+ +bn-1x(n-n+1) 其中bi為濾波器系數(shù),x(n)為濾波器在n時(shí)刻的輸入,y(n)為n時(shí)刻的輸出。 其基本算法: 采用乘法累加運(yùn)算。即不斷地輸入樣本x(n),經(jīng)過z-1延時(shí)后,再進(jìn)行乘法-累加,最后輸出濾波結(jié)果y(n)。 fir濾波器的dsp實(shí)現(xiàn)有三種方法:方法一:獨(dú)立編寫匯編語言。方法二:獨(dú)立編寫c語言。方法三:調(diào)用dsplib庫(kù)函數(shù)。其調(diào)用形式有:ushort of
7、lag = fir (data *x, data *h, data *r, data *dbuffer, ushort nx,ushort nh) 其中xnx 為輸入向量,其個(gè)數(shù)為nx,hnh為濾波器的系數(shù),其階數(shù)為nh,rnx為輸出向量,個(gè)數(shù)為nx,dbuffernh+2是延時(shí)緩沖區(qū),其長(zhǎng)度為nh = nh + 2。ushort oflag = fir2 (data *x, data *h, data *r, data *dbuffer, ushort nx,ushort nh) 4、fir濾波器程序流程圖 圖2 fir濾波器程序流程圖 (二)、無限沖激響應(yīng)濾波器(iir)的實(shí)現(xiàn) 1、iir
8、濾波器的基本結(jié)構(gòu) 無限沖激響應(yīng)濾波器的差分方程如下: 在零初始條件下,對(duì)上式進(jìn)行z變換,得到系統(tǒng)的傳遞函數(shù): 無限沖激響應(yīng)濾波器的結(jié)構(gòu)如圖2所示。圖3 iir濾波器結(jié)構(gòu) 2、無限沖激響應(yīng)濾波器(iir)的matlab設(shè)計(jì) 同有限沖激響應(yīng)濾波器一樣,無限沖激響應(yīng)濾波器也可以在matlab中通過兩種不同的方法進(jìn)行設(shè)計(jì)。 方法1:利用濾波器設(shè)計(jì)函數(shù)直接生成濾波器。matlab中提供了多種iir濾波器的設(shè)計(jì)方法,包括巴特沃斯濾波器,切比雪夫型、切比雪夫型濾波器,橢圓濾波器等,本次實(shí)習(xí)采用橢圓濾波器求濾波器的系數(shù)ak和bk。 方法2:采用濾波器設(shè)計(jì)與分析工具設(shè)計(jì)濾波器。其具體步驟為: (1) 打開fda
9、tool ;(2) 設(shè)置濾波器參數(shù) ;(3) 單擊設(shè)計(jì)濾波器按鈕;(4) 單擊file菜單,選擇“export”子菜單,選擇輸出到“text-file”,單擊“ok” 。在本次實(shí)習(xí)中選擇方法一。 3、iir濾波器dsp實(shí)現(xiàn) 1)、iir濾波器的dsp實(shí)現(xiàn)方法 iir濾波器的dsp實(shí)現(xiàn)有三種方法: 方法一:獨(dú)立編寫匯編語言。 方法二:獨(dú)立編寫c語言。 方法三:調(diào)用dsplib庫(kù)函數(shù)。其調(diào)用形式有: ushort oflag = iircas5 (data *x, data *h, data *r, data *dbuffer, short nbiq,ushort nx),其中h的存放系數(shù)順序?yàn)閔
10、 = a11 a21 b21 b01 b11 . a1i a2i b2i b0i b1i。 ushort oflag = iircas51 (data *x, data *h, data *r, data *dbuffer, ushort nbiq,ushort nx),其中h的存放系數(shù)順序?yàn)閔 = b01 b11 b21 a11 a21 .b0i b1i b2i a1i a2i。 2)、高階iir濾波器的實(shí)現(xiàn) 一個(gè)高階iir濾波器可以由若干個(gè)二階基本節(jié)相級(jí)聯(lián)或并聯(lián)構(gòu)成。由于調(diào)整每個(gè)二階基本節(jié)的系數(shù),只涉及這個(gè)二階基本節(jié)的一對(duì)極點(diǎn)和零點(diǎn),不影響其他極、零點(diǎn),因此用二階基本節(jié)構(gòu)成的iir濾波器便
11、于系統(tǒng)的性能調(diào)整,受量化噪聲影響小,因而得到了廣泛的應(yīng)用。其方法是將高階iir濾波器分解成若干個(gè)二階基本節(jié),然后進(jìn)行級(jí)聯(lián)來實(shí)現(xiàn)。若干個(gè)二階基本節(jié)的結(jié)構(gòu)如圖3所示。 圖4 i個(gè)二階基本節(jié) 3、iir濾波器程序流程圖 圖5 程序流程圖5、 程序代碼及運(yùn)行結(jié)果 (一)、fir濾波器程序代碼ccs軟件環(huán)境下主程序代碼如下 #include math.h#include tms320.h#include dsplib.h#include test.hshort i;short eflag1= pass;short eflag2= pass;data rnx;data *dbptr = &db0;void
12、 main() int i; short xnx; for(i=0;inx;i+)xi=0; for (i=0;inx;i+) xi=(short)(1+sin(pi*3000*i/10000)*sin(pi*4000*i/10000)*32768/3) ; for (i=0; inx; i+) ri = 0; / clear output buffer (optional) for (i=0; inh+2; i+) dbi = 0; / clear delay buffer (a must) fir2(x, h, r, dbptr, nx, nh);/雙mac運(yùn)算,速度快 while(1);
13、 1、fir低通濾波器實(shí)現(xiàn) (1)matlab程序代碼 clear allclcwp=0.4;ws=0.6;b=ws-wp;%計(jì)算過渡帶寬n=ceil(6.6*pi/b) %按哈明窗計(jì)算濾波器長(zhǎng)度wc=(ws+wp)/2;b=fir1(n-1,wc);%80 point hamming window fir filter, wn=0.2fvtool(b,1)%flter visualization tool可心以查看幅度響應(yīng)、沖激響應(yīng)等 h=buffer(round(b*32768),8); %參數(shù)*215,把小數(shù)點(diǎn)移最高位后面后取整,然后排成8個(gè) %一行便于輸出。 csvwrite(tabl
14、e.txt,h) %參數(shù)表輸出到文件中 %然后只要把參數(shù)表從table.txt中拷到代碼中,每行前面加上 .word 運(yùn)行結(jié)果如下:n=104生成table.txt文檔-11,-12,12,13,-15,-16,18,20-23,-26,29,33,-37,-42,47,52-59,-65,73,81,-89,-99,109,120-132,-145,158,173,-189,-207,226,247-269,-294,321,352,-385,-423,466,515-572,-639,719,816,-938,-1095,1307,1612-2087,-2936,4911,14758,14
15、758,4911,-2936,-20871612,1307,-1095,-938,816,719,-639,-572515,466,-423,-385,352,321,-294,-269247,226,-207,-189,173,158,-145,-132120,109,-99,-89,81,73,-65,-5952,47,-42,-37,33,29,-26,-2320,18,-16,-15,13,12,-12,-11圖形如圖1.1所示。圖1.1 幅頻響應(yīng)(2)、ccs軟件程序代碼 text.h代碼#define nx 320#define nh 104#define maxerror 10#
16、define pi 3.1415926#pragma data_section(h,.coeffs)data hnh=-11,-12,12,13,-15,-16,18,20,-23,-26,29,33,-37,-42,47,52,-59,-65,73,81,-89,-99,109,120,-132,-145,158,173,-189,-207,226,247,-269,-294,321,352,-385,-423,466,515,-572,-639,719,816,-938,-1095,1307,1612,-2087,-2936,4911,14758,14758,4911,-2936,-208
17、7,1612,1307,-1095,-938,816,719,-639,-572,515,466,-423,-385,352,321,-294,-269,247,226,-207,-189,173,158,-145,-132,120,109,-99,-89,81,73,-65,-59,52,47,-42,-37,33,29,-26,-23,20,18,-16,-15,13,12,-12,-11;#pragma data_section(db,.dbuffer)data dbnh+2 ;data rtestnx;data rnx;運(yùn)行結(jié)果如圖1.2所示:圖a 濾波前x的波形圖b 濾波后r的波形圖
18、1.2 濾波前后的波形 2、fir高通濾波器實(shí)現(xiàn) (1)、matlab程序代碼clear allclcwp=0.3;ws=0.2;b=wp-ws;%計(jì)算過渡帶寬n0=ceil(6.6*pi/b);n=n0+mod(n0+1,2) wc=(ws+wp)/2;b=fir1(n-1,wc,high);fvtool(b,1)%flter visualization tool可心以查看幅度響應(yīng)、沖激響應(yīng)等h=buffer(round(b*32768),8) ;csvwrite(table.txt,h) 運(yùn)行結(jié)果:n=209 生成table.txt文檔0,6,8,6,0,-6,-9,-70,8,11,8,
19、0,-9,-14,-100,12,18,13,0,-15,-23,-170,19,29,22,0,-24,-36,-270,30,45,34,0,-37,-56,-410,46,68,50,0,-55,-82,-610,67,99,73,0,-80,-118,-880,96,141,104,0,-114,-168,-1240,135,200,148,0,-161,-239,-1770,193,286,212,0,-234,-347,-2580,287,428,320,0,-360,-541,-4080,469,715,548,0,-654,-1021,-8060,1043,1725,1468,
20、0,-2454,-5211,-737524578,-7375,-5211,-2454,0,1468,1725,10430,-806,-1021,-654,0,548,715,4690,-408,-541,-360,0,320,428,2870,-258,-347,-234,0,212,286,1930,-177,-239,-161,0,148,200,1350,-124,-168,-114,0,104,141,960,-88,-118,-80,0,73,99,670,-61,-82,-55,0,50,68,460,-41,-56,-37,0,34,45,300,-27,-36,-24,0,22
21、,29,190,-17,-23,-15,0,13,18,120,-10,-14,-9,0,8,11,80,-7,-9,-6,0,6,8,60,0,0,0,0,0,0,0圖形如圖1.2所示。圖1.3 幅頻響應(yīng) (2)、ccs程序代碼 text.h代碼 #define nx 320 #define nh 209#define maxerror 10#define pi 3.1415926#pragma data_section(h,.coeffs)data hnh=0,6,8,6,0,-6,-9,-7,0,8,11,8,0,-9,-14,-10,0,12,18,13,0,-15,-23,-17,0
22、,19,29,22,0,-24,-36,-27,0,30,45,34,0,-37,-56,-41,0,46,68,50,0,-55,-82,-61,0,67,99,73,0,-80,-118,-88,0,96,141,104,0,-114,-168,-124,0,135,200,148,0,-161,-239,-177,0,193,286,212,0,-234,-347,-258,0,287,428,320,0,-360,-541,-408,0,469,715,548,0,-654,-1021,-806,0,1043,1725,1468,0,-2454,-5211,-7375,24578,-7
23、375,-5211,-2454,0,1468,1725,1043,0,-806,-1021,-654,0,548,715,469,0,-408,-541,-360,0,320,428,287,0,-258,-347,-234,0,212,286,193,0,-177,-239,-161,0,148,200,135,0,-124,-168,-114,0,104,141,96,0,-88,-118,-80,0,73,99,67,0,-61,-82,-55,0,50,68,46,0,-41,-56,-37,0,34,45,30,0,-27,-36,-24,0,22,29,19,0,-17,-23,-
24、15,0,13,18,12,0,-10,-14,-9,0,8,11,8,0,-7,-9,-6,0,6,8,6,0;#pragma data_section(db,.dbuffer)data dbnh+2 ;data rtestnx;data rnx; 運(yùn)行結(jié)果如圖1.4所示。圖a 濾波前x的波形圖b 濾波后r的波形圖1.4濾波前后的波形 3、fir帶通濾波器實(shí)現(xiàn) (1)、matlab程序代碼wp1=0.2;wp2=0.5;ws1=0.1;ws2=0.6;wp=wp1,wp2;ws=ws1,ws2;b=wp1-ws1;%計(jì)算過渡帶寬n0=ceil(6.6*pi/b);n=n0+mod(n0+1,
25、2)wc1=(ws1+wp1)/2;wc2=(ws2+wp2)/2;wc=wc1,wc2;b=fir1(n-1,wc,hamming(n);fvtool(b,1)h=buffer(round(b*32768),8) csvwrite(table.txt,h) 運(yùn)行結(jié)果: n =209 生成table.txt文檔3,15,9,-5,0,5,-10,-18-4,0,-12,-4,19,14,0,1624,-5,-20,0,-7,-40,-25,130,-14,32,57,12,0,40,11-62,-45,0,-50,-77,16,62,022,121,76,-38,0,42,-92,-162-3
26、3,0,-111,-31,167,119,0,130199,-40,-158,0,-56,-302,-188,940,-102,223,392,79,0,267,74-402,-286,0,-314,-484,98,388,0140,761,478,-241,0,271,-604,-1083-224,0,-799,-230,1297,967,0,11931978,-439,-1928,0,-943,-6515,-5822,556113098,5561,-5822,-6515,-943,0,-1928,-4391978,1193,0,967,1297,-230,-799,0-224,-1083,
27、-604,271,0,-241,478,761140,0,388,98,-484,-314,0,-286-402,74,267,0,79,392,223,-1020,94,-188,-302,-56,0,-158,-40199,130,0,119,167,-31,-111,0-33,-162,-92,42,0,-38,76,12122,0,62,16,-77,-50,0,-45-62,11,40,0,12,57,32,-140,13,-25,-40,-7,0,-20,-524,16,0,14,19,-4,-12,0-4,-18,-10,5,0,-5,9,153,0,0,0,0,0,0,0 程序
28、運(yùn)行結(jié)果如圖1.5所示.圖1.5 幅頻特性 (2)、ccs程序代碼 text.h代碼#define nx 320#define nh 209/#define fname t6#define maxerror 10#define pi 3.1415926#pragma data_section(h,.coeffs)data hnh=3,15,9,-5,0,5,-10,-18,-4,0,-12,-4,19,14,0,16,24,-5,-20,0,-7,-40,-25,13,0,-14,32,57,12,0,40,11,-62,-45,0,-50,-77,16,62,0,22,121,76,-38,
29、0,42,-92,-162,-33,0,-111,-31,167,119,0,130,199,-40,-158,0,-56,-302,-188,94,0,-102,223,392,79,0,267,74,-402,-286,0,-314,-484,98,388,0,140,761,478,-241,0,271,-604,-1083,-224,0,-799,-230,1297,967,0,1193,1978,-439,-1928,0,-943,-6515,-5822,5561,13098,5561,-5822,-6515,-943,0,-1928,-439,1978,1193,0,967,129
30、7,-230,-799,0,-224,-1083,-604,271,0,-241,478,761,140,0,388,98,-484,-314,0,-286,-402,74,267,0,79,392,223,-102,0,94,-188,-302,-56,0,-158,-40,199,130,0,119,167,-31,-111,0,-33,-162,-92,42,0,-38,76,121,22,0,62,16,-77,-50,0,-45,-62,11,40,0,12,57,32,-14,0,13,-25,-40,-7,0,-20,-5,24,16,0,14,19,-4,-12,0,-4,-1
31、8,-10,5,0,-5,9,15,3;#pragma data_section(db,.dbuffer)data dbnh+2 ;data rtestnx;data rnx;運(yùn)行結(jié)果如圖1.6所示圖1.6 濾波前后的的波形 4、fir帶阻濾波器實(shí)現(xiàn) (1)、 matlab程序代碼 ws1=0.2;ws2=0.5;wp1=0.1;wp2=0.6;wp=wp1,wp2;ws=ws1,ws2;b=ws1-wp1;%計(jì)算過渡帶寬n0=ceil(6.6*pi/b);n=n0+mod(n0+1,2)wc1=(ws1+wp1)/2;wc2=(ws2+wp2)/2;wc=wc1,wc2;b=fir1(n-1
32、,wc,stop);%80 point hamming window fir filter, wn=0.2fvtool(b,1) h=buffer(round(b*32768),8) csvwrite(table.txt,h) 運(yùn)行結(jié)果如下:n=209 生成的table.txt文檔-3,-15,-9,5,0,-5,10,184,0,13,4,-19,-14,0,-16-24,5,20,0,7,40,25,-130,14,-32,-57,-12,0,-40,-1162,45,0,50,77,-16,-62,0-22,-121,-76,38,0,-42,92,16233,0,111,31,-167
33、,-119,0,-130-199,40,158,0,56,303,188,-940,102,-224,-393,-79,0,-267,-74402,287,0,315,485,-98,-388,0-140,-762,-478,241,0,-272,605,1085224,0,800,231,-1298,-969,0,-1194-1981,439,1930,0,945,6523,5829,-556919672,-5569,5829,6523,945,0,1930,439-1981,-1194,0,-969,-1298,231,800,0224,1085,605,-272,0,241,-478,-
34、762-140,0,-388,-98,485,315,0,287402,-74,-267,0,-79,-393,-224,1020,-94,188,303,56,0,158,40-199,-130,0,-119,-167,31,111,033,162,92,-42,0,38,-76,-121-22,0,-62,-16,77,50,0,4562,-11,-40,0,-12,-57,-32,140,-13,25,40,7,0,20,5-24,-16,0,-14,-19,4,13,04,18,10,-5,0,5,-9,-15-3,0,0,0,0,0,0,0 程序運(yùn)行結(jié)果如圖1所示。圖1.7 幅頻響應(yīng)
35、(2)、ccs程序代碼 test.h程序代碼#define nx 320#define nh 209/#define fname t6#define maxerror 10#define pi 3.1415926#pragma data_section(h,.coeffs)data hnh=-3,-15,-9,5,0,-5,10,18,4,0,13,4,-19,-14,0,-16,-24,5,20,0,7,40,25,-13,0,14,-32,-57,-12,0,-40,-11,62,45,0,50,77,-16,-62,0,-22,-121,-76,38,0,-42,92,162,33,0,
36、111,31,-167,-119,0,-130,-199,40,158,0,56,303,188,-94,0,102,-224,-393,-79,0,-267,-74,402,287,0,315,485,-98,-388,0,-140,-762,-478,241,0,-272,605,1085,224,0,800,231,-1298,-969,0,-1194,-1981,439,1930,0,945,6523,5829,-5569,19672,-5569,5829,6523,945,0,1930,439,-1981,-1194,0,-969,-1298,231,800,0,224,1085,6
37、05,-272,0,241,-478,-762,-140,0,-388,-98,485,315,0,287,402,-74,-267,0,-79,-393,-224,102,0,-94,188,303,56,0,158,40,-199,-130,0,-119,-167,31,111,0,33,162,92,-42,0,38,-76,-121,-22,0,-62,-16,77,50,0,45,62,-11,-40,0,-12,-57,-32,14,0,-13,25,40,7,0,20,5,-24,-16,0,-14,-19,4,13,0,4,18,10,-5,0,5,-9,-15,-3;#pra
38、gma data_section(db,.dbuffer)data dbnh+2 ;data rtestnx;data rnx; 運(yùn)行結(jié)果如圖1.8所示:圖1.8 濾波前后的波形 (二)、iir濾波器程序代碼ccs軟件環(huán)境下主程序代碼 #define pi 3.1415926#include #include #include tms320.h#include dsplib.h#include t8.hshort i;short eflag = pass;/ error flag or index into r vector where errorvoid main() for (i=0;in
39、x;i+) ri =0; for (i=0; i5*nbiq; i+) dbufferi = 0; / clear delay buffer (a must) for(i=0;inx;i+)xi=0; for (i=0;inx;i+) xi=(short)(1+sin(pi*3000*i/12000)*sin(pi*4000*i/12000)*32768/3) ; iircas51(x, h, r, dp, nbiq, nx); while(1); 1、iir低通濾波器實(shí)現(xiàn) (1)、 matlab程序代碼clearclcwp=0.5;ws=0.4;n,wc=ellipord(wp,ws,3,8
40、0)b,a=ellip(n,3,80,wc)freqz(b,a,512,10000)s, g=tf2sos(b,a)s1=round(s/4*32768)k=s1(:,1:3),s1(:,5:6)s3=k(1,:),k(2,:),k(3,:),k(4,:)h1=buffer(s3,8) csvwrite(iirlow.txt,h1) 程序運(yùn)行結(jié)果如下: 生成iirlow.txt文檔8192,8192,0,-6022,0,8192,12450,8192-7816,5556,8192,7398,8192,-2514,7031,81925145,8192,-180,7881,0,0,0,0 程序運(yùn)行
41、結(jié)果如圖2.1所示.圖2.1 幅頻和相頻特性 (2)、將生成的iirhigh.txt文檔粘貼到頭文件中的 data h5*nbiq8192,8192,0,-6022,0,8192,12450,8192,-7816,5556,8192,7398,8192,-2514,7031,8192, 5145,8192,-180,7881 中,然后將nbiq的值改為4。.運(yùn)行結(jié)果如圖2.2所示。圖2.2 濾波前后的波形 2、iir高通濾波器實(shí)現(xiàn) (1)、matlab程序代碼clearclcws=0.1wp=0.2%n,wn=cheb1ord(wp,ws,3,80)%b,a=cheby1(n,3,wn,hig
42、h)n,wc=ellipord(wp,ws,3,80)b,a=ellip(n,3,80,wc,high)freqz(b,a,512,10000)s, g=tf2sos(b,a)%s2=s/20*32768s1=round(s/4*32768)k=s1(:,1:3),s1(:,5:6)s3=k(1,:),k(2,:),k(3,:)h1=buffer(s3,8) csvwrite(iirhigh.txt,h1) 運(yùn)行結(jié)果如下:生成iirhigh.txt文檔 8192,-16277,8192,-237,2948,8192,-15678,8192 -10398,6810,8192,-15204,819
43、2,-12912,7894,0運(yùn)行結(jié)果如圖1所示圖2.3 幅頻和相頻特性 (2)、將生成的iirhigh.txt文檔粘貼到頭文件中的 data h5*nbiq 8192,-16277,8192,-237,2948,8192,-15678,8192, -10398,6810,8192,-15204,8192,-12912,7894 中,然后將nbiq的值改為3。程序運(yùn)行結(jié)果如圖2.4所示。圖2.4 濾波前后的波形圖 3、iir帶通濾波器實(shí)現(xiàn) (1)、matlab程序代碼 clear clcwp=0.2,0.5;ws=0.1,0.6;n,wc=ellipord(wp,ws,3,80)b,a=ell
44、ip(n,3,80,wc,bandpass)freqz(b,a,512,10000)s, g=tf2sos(b,a)%s2=s/20*32768s1=round(s/4*32768)k=s1(:,1:3),s1(:,5:6)s3=k(1,:),k(2,:),k(3,:),k(4,:),k(5,:),k(6,:)h1=buffer(s3,8) csvwrite(iirbandpass.txt,h1) 程序運(yùn)行結(jié)果如下 生成iirbandpass.txt文檔 8192,14384,8192,-5594,6913,8192,-16161,8192-9581,7105,8192,7753,8192,-
45、1969,7378,8192-15192,8192,-12046,7650,8192,5014,8192,-1507940,8192,-14644,8192,-13081,8042,0,0 程序運(yùn)行結(jié)果如圖2.5所示.圖2.5 幅頻和相頻特性 (2)、將生成的iirhigh.txt文檔粘貼到頭文件中的 data h5*nbiq 8192,14384,8192,-5594,6913,8192,-16161,8192-9581,7105,8192,7753,8192,-1969,7378,8192-15192,8192,-12046,7650,8192,5014,8192,-150 7940,81
46、92,-14644,8192,-13081,8042 中,然后將nbiq的值改為5。程序運(yùn)行結(jié)果如圖2.6所示。圖2.6 濾波前后的波形 4、iir帶阻濾波器實(shí)現(xiàn) (1)、matlab程序代碼 clearclcws=0.3,0.5;wp=0.2,0.6;%n,wn=cheb1ord(wp,ws,3,80)%b,a=cheby1(n,3,wn,high)n,wc=ellipord(wp,ws,3,80)b,a=ellip(n,3,80,wc,stop)freqz(b,a,512,10000)s, g=tf2sos(b,a)%s2=s/20*32768s1=round(s/4*32768)k=s1(:,1:3),s1(:,5:6)s3=k(1,:),k(2,:),k(3,:),k(4,:),k(5,:),k(6,:)h1=buffer(s3,8) csvwrite(iirstop.txt,h1) 程序運(yùn)行結(jié)果:生成iirstop.txt文檔 81
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024高考?xì)v史一輪復(fù)習(xí)第1講中國(guó)早期政治制度的特點(diǎn)及走向“大一統(tǒng)”的秦漢政治學(xué)案含解析人民版
- 2024高考地理一輪復(fù)習(xí)第二十二單元環(huán)境保護(hù)考法精練含解析
- 小學(xué)一年級(jí)數(shù)學(xué)教學(xué)計(jì)劃
- 拖欠工資起訴書范文5篇
- 二零二五年環(huán)保產(chǎn)業(yè)創(chuàng)業(yè)合伙人合同3篇
- 大豆加工行業(yè)現(xiàn)狀分析報(bào)告
- 二零二五年度特色餐廳場(chǎng)地租賃經(jīng)營(yíng)合同范本2篇
- 2024年隴南市武都區(qū)第一人民醫(yī)院高層次衛(wèi)技人才招聘筆試歷年參考題庫(kù)頻考點(diǎn)附帶答案
- 二零二五版企業(yè)股份分配與員工激勵(lì)協(xié)議3篇
- 2024年河南檢察職業(yè)學(xué)院高職單招語文歷年參考題庫(kù)含答案解析
- 幼兒戶外自主游戲觀察與指導(dǎo)的實(shí)踐研究課題開題報(bào)告
- GP12控制作業(yè)指導(dǎo)書
- 集團(tuán)公司垂直管理辦法
- 《滑炒技法-尖椒炒肉絲》教學(xué)設(shè)計(jì)
- 【人生哲學(xué)與傳統(tǒng)道德4200字(論文)】
- 116個(gè)公共信息圖形通用符號(hào)
- 勞動(dòng)仲裁證據(jù)目錄清單
- DB11T 1832.11-2022建筑工程施工工藝規(guī)程 第11部分幕墻工程
- 怎樣移動(dòng)重物幻燈片
- GB/T 29529-2013泵的噪聲測(cè)量與評(píng)價(jià)方法
- GB/T 29494-2013小型垂直軸風(fēng)力發(fā)電機(jī)組
評(píng)論
0/150
提交評(píng)論