Matlab 之 FIR 濾波器設計與實現
description
Transcript of Matlab 之 FIR 濾波器設計與實現
![Page 1: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/1.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
Robot and Servo Drive Lab.
112/04/21
Matlab 之 FIR 濾波器設計與實現
老師 : 趙春棠學生 : 林奉機
![Page 2: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/2.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
112/04/21
Robot and Servo Drive Lab.2
OUTLINE
窗函數法 (Kaiser window)
等波紋法 (remez)
比較
結果分析
![Page 3: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/3.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
窗函數法 為了去除 FIR濾波器在通帶與拒帶的頻率響應震盪﹐有必要把不要的部
份予以截除 (Truncate)﹐ 而保留需要的部份﹐使用的方法簡單的說就是把希望的響應與一個適當的窗形函數進行環形摺積﹐使得處理後的響應能夠滿足規格要求
環形摺積對於一個希望得到的(Desired)濾波器頻率響應﹐其具有在通帶時為線性相位﹐在拒帶則完全阻絕信號通過
112/04/21
Robot and Servo Drive Lab.3
頻率w
頻率響應Td(w)
頻率響應T(w)
頻率w
環形摺積
Side lobe Main lobe截止頻率wc
窗形函數頻率響應希望的頻率響應
FIR濾波器頻率響應
a(w)
頻率w
![Page 4: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/4.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
112/04/21
Robot and Servo Drive Lab.4
窗函數法f p : Ω p1 =0.45pi , Ω p2 =0.65pi , α p : δ 1 <=1[dB] 。 f st :
Ω s1 =0.3pi , Ω s2 =0.8pi , δ p :δ 2 >=40[dB]
[n,wn,bta,ftype]=kaiserord([0.3 0.45 0.65 0.8],[0 1 0],[0.01 0.1087 0.01]);
h1=fir1(n,wn,ftype,kaiser(n+1,bta),'noscale');
[hh1,w1]=freqz(h1,1,256);
figure(1)
subplot(2,1,1)
plot(w1/pi,20*log10(abs(hh1)))
grid
xlabel('歸一化頻率 w');ylabel('幅度 /db');
subplot(2,1,2)
plot(w1/pi,angle(hh1))
grid
xlabel('歸一化頻率 w');ylabel('相位 /rad');
![Page 5: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/5.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
112/04/21
Robot and Servo Drive Lab.5
窗函數法
![Page 6: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/6.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
窗函數法我在輸入 freqz(h1,1,256)
112/04/21
Robot and Servo Drive Lab.6
![Page 7: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/7.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
等波紋法
所謂最佳化就是讓濾波器的頻率響應﹐在衰減帶的起伏 (Ripple) 等量平均的變化﹐稱為 Equiripple 。使用的演算法稱為 Parks-McClellan algorithm
112/04/21
Robot and Servo Drive Lab.7
![Page 8: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/8.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
等波紋法 [n,fpts,mag,wt]=remezord([0.3 0.45 0.65 0.8],[0 1 0],[0.01 0.1087 0.01]);
h2=remez(n,fpts,mag,wt);
[hh2,w2]=freqz(h2,1,256);
figure(2)
subplot(2,1,1)
plot(w2/pi ,20*log10(abs(hh2)))
grid
xlabel('歸一化頻率 w');ylabel('幅度 /db');
subplot(2,1,2)
plot(w2/pi,angle(hh2) )
grid
xlabel('歸一化頻率 w');ylabel('相位 /rad');
112/04/21
Robot and Servo Drive Lab.8
![Page 9: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/9.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
等波紋法
112/04/21
Robot and Servo Drive Lab.9
![Page 10: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/10.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
等波紋法我再輸入 freqz(h2,1,256)
112/04/21
Robot and Servo Drive Lab.10
![Page 11: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/11.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
比較
112/04/21
Robot and Servo Drive Lab.11
d)(H)(HE
2
- 實際理想窗
))(H-)()(HW(E 實際理想等波紋
幅度頻譜差值越小,實際濾波器就越接近理想濾波器。 而等波紋濾波器是通過最大加權誤差最小化來實現,其誤差為:
![Page 12: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/12.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
比較
112/04/21
Robot and Servo Drive Lab.12
對比二者的幅度頻譜可知,等波紋濾波器阻帶邊緣比用窗函數實現的更平滑(理想濾波器為垂直下降的)。 從設計的角度考慮,由於窗函數設計法都是通過已有的窗函數對理想濾波器的改造,因此,可以用手算的辦法方便的設計濾波器。而等波紋濾波器,其實現是通過大量的迭代運算來實現,這樣的方法一般只能通過軟件來設計。 項數的問題由於等波紋濾波器能較平均的分佈誤差,因此對於相同的阻帶衰減,其所需的濾波係數比窗函數的要少。
![Page 13: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/13.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
比較上面第一個圖是用 rad為單位畫出來的,下面的圖是用角度單位畫出來的。從圖形可以觀察到在 0.3 到0.8 數字頻率間兩個圖都是
嚴格的線性相位,至於上面的圖為什麼在這個區間會有跳變是因為 rad 的區間只有 -
pi —— pi ,當相位由 -pi 繼續增
加時只能跳到 pi 而不能大於 pi ,而角度表示則可以連續增大。
112/04/21
Robot and Servo Drive Lab.13
![Page 14: Matlab 之 FIR 濾波器設計與實現](https://reader033.fdocument.pub/reader033/viewer/2022061503/56814d58550346895dba9139/html5/thumbnails/14.jpg)
Department of Electrical Engineering Southern Taiwan University
Department of Electrical Engineering Southern Taiwan University
結果分析濾波器實現形式及特點:由於一般的濾波器在利用窗函數是其通帶波紋 和阻帶波紋不同(一般為第一個阻帶波紋最大)因此,在滿足第一個阻帶衰減旁瓣時,比其頻率高的旁瓣,它們的衰減都大大超出要求。而根據阻帶衰減與項數的近似關係 N = P(δ 2 )*f s /TW ,可得當阻帶衰減越大,所需項數越多
112/04/21
Robot and Servo Drive Lab.14