Design and implementation of IIR filter based on MATLAB
The design of IIR filter mainly has the classic design method, the direct design method and the maximum smoothing filter design method Three kinds of methods.
1, the classical design method is based on the transformation principle of the analog filter, first of all, according to the technical specifications of the filter to design the corresponding analog filter, and then discretized to meet the given technical indicators of the digital filter. The corresponding tool functions are composed of fully designed functions--butter, cheby1, Cheby2, Ellip, besself, order estimation function--buttord, Cheb1ord, Cheb2ord, Ellipord, low pass analog prototype filter function-- Buttap, Cheb1ap, Cheb2ap, ELLIPAP, frequency conversion function--LP2LP, lp2bp, lp2bs, filter discretization function--bilinear, Impinvar.
2, the direct design method is the least square approximation of the given amplitude-frequency characteristic in the discrete domain, and the corresponding tool function is yulewalk.
3, the maximum smoothing filter design method is to design a generalized low-pass filter, its 0 points more than the pole, the corresponding tool function is Maxflat.
Several examples are used to illustrate the application of three methods.
Example one, the classical method design filter has the impulse response invariance and the Bilinear transformation method two kinds of methods.
(1), impulse response does not reform
A low-pass filter is designed with elliptic filter prototype to meet Wp=0.2pi, rp=0.5db, Ws=0.3pi, as=20db. The code is as follows:
1wp=0.2*Pi;2Ws=0.3*Pi;3rp=0.5;4rs= -;5[N,wn]=ellipord (Wp,ws,rp,rs,'s');6[z,p,k]=ELLIPAP (n,rp,rs);7W=logspace (-1,1, +);8H=freqs (k*Poly (z), poly (p), W);9 SEMILOGX (W,abs (h));TenGrid
The waveform is as follows:
The command window can be:
n =
3
WN =
0.6283
(2), bilinear transformation method
The design of band-pass Chebyshev i-type digital filter requires that the pass band Boundary frequency is 100~200hz, the pass band Ripple is less than 3dB, the band attenuation is greater than 30dB, the transition bandwidth is 30Hz, and the sampling frequency is 1000Hz. The code is as follows:
1fs= +;2wp=[ - $]*2/FS;3ws=[ - -]*2/FS;4rp=3;5rs= -;6nn= -;7[n,wn]=Cheb1ord (Wp,ws,rp,rs)8[b,a]=cheby1 (N,RP,WN)9FREQZ (B,A,NN,FS)
The waveform is as follows:
The command window can be:
N =
3
WN =
0.2000 0.4000
b =
0.0066 0-0.0198 0 0.0198 0-0.0066
A =
1.0000-3.3130 6.1125-6.9677 5.3979-2.5753 0.6884
Example two, a multi-band digital filter is designed by direct method.
Amplitude-Frequency response value f=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]; M=[0 0 1 1 0 0 1 1 1 0 0];
The following steps: (1): Calculate the auxiliary molecular formula and denominator of the corresponding amplitude square response of the molecular polynomial, (2): Calculate the complete frequency response by the auxiliary molecular formula and the denominator formula, (3): Calculate the impulse response of the filter, (4): Adopt the least square method to fit the impulse response, and finally obtain the molecular polynomial of the
The code is as follows:
1Oder=Ten;2f=0:0.1:1;3m=[0 0 1 1 0 0 1 1 1 0 0];4[b,a]=Yulewalk (oder,f,m)5[H,w]=freqz (B,a, -)6Axes'position',[0.2 0.2 0.4 0.4]);7Plot (F,m,'B -', W/pi,abs (h),'m--');8Xlabel ('frequency (PI)');9Ylabel ('magnitude');TenTitle'Direct IIR Design-yulewalk'); OneLegend'Ideal Graphics','actual image'); AGrid
The waveform is as follows:
The command window can be:
b =
Columns 1 through 9
0.2774-0.0460-0.0761 0.1262-0.3949-0.0783 0.1008-0.0571 0.1488
Columns through 11
0.0512 0.0270
A =
Columns 1 through 9
1.0000-0.0185 0.4144 0.0393 0.3588 0.1016 0.2372-0.0633 0.1727
Columns through 11
0.0629 0.0496
h =
0.0335 + 0.0000i 0.0325-0.0013i 0.0295-0.0023i 0.0244-0.0029i 0.0173-0.0028i 0.0079-0.0018i
-0.0036 + 0.0006i-0.0175 + 0.0046i-0.0338 + 0.0109i-0.0525 + 0.0201i-0.0736 + 0.0329i-0.0970 + 0.0503i
-0.1223 + 0.0735i-0.1488 + 0.1038i-0.1753 + 0.1429i-0.1999 + 0.1925i-0.2196 + 0.2539i-0.2304 + 0.3281i
-0.2270 + 0.4142i-0.2034 + 0.5095i-0.1545 + 0.6079i-0.0773 + 0.7003i 0.0265 + 0.7762i 0.1505 + 0.8263i
0.2845 + 0.8453i 0.4175 + 0.8333i 0.5410 + 0.7943i 0.6497 + 0.7347i 0.7417 + 0.6608i 0.8172 + 0.5776i
0.8778 + 0.4886i 0.9250 + 0.3956i 0.9602 + 0.2995i 0.9837 + 0.2003i 0.9951 + 0.0978i 0.9931-0.0077i
0.9754-0.1156i 0.9391-0.2233i 0.8818-0.3265i 0.8025-0.4191i 0.7033-0.4933i 0.5899-0.5422i
0.4714-0.5620i 0.3580-0.5532i 0.2582-0.5209i 0.1767-0.4726i 0.1147-0.4161i 0.0703-0.3575i
0.0406-0.3013i 0.0219-0.2498i 0.0112-0.2038i 0.0057-0.1636i 0.0035-0.1287i 0.0030-0.0984i
0.0031-0.0720i 0.0031-0.0485i 0.0022-0.0273i 0.0002-0.0076i-0.0033 + 0.0114i-0.0085 + 0.0305i
-0.0154 + 0.0506i-0.0241 + 0.0725i-0.0343 + 0.0972i-0.0455 + 0.1259i-0.0572 + 0.1597i-0.0681 + 0.2001i
-0.0763 + 0.2482i-0.0793 + 0.3050i-0.0737 + 0.3708i-0.0550 + 0.4444i-0.0190 + 0.5228i 0.0382 + 0.6005i
0.1178 + 0.6698i 0.2173 + 0.7224i 0.3303 + 0.7512i 0.4478 + 0.7532i 0.5608 + 0.7295i 0.6624 + 0.6847i
0.7487 + 0.6250i 0.8189 + 0.5562i 0.8740 + 0.4832i 0.9160 + 0.4091i 0.9470 + 0.3361i 0.9691 + 0.2652i
0.9842 + 0.1968i 0.9936 + 0.1308i 0.9983 + 0.0670i 0.9992 + 0.0051i 0.9967-0.0555i 0.9910-0.1151i
0.9824-0.1743i 0.9707-0.2336i 0.9557-0.2933i 0.9367-0.3540i 0.9131-0.4158i 0.8840-0.4790i
0.8480-0.5434i 0.8036-0.6086i 0.7489-0.6734i 0.6820-0.7360i 0.6013-0.7932i 0.5059-0.8407i
0.3965-0.8730i 0.2765-0.8842i 0.1522-0.8694i 0.0326-0.8265i-0.0728-0.7579i-0.1561-0.6700i
-0.2133-0.5720i-0.2448-0.4730i-0.2543-0.3803i-0.2472-0.2983i-0.2288-0.2289i-0.2037-0.1719i
-0.1755-0.1263i-0.1464-0.0905i-0.1182-0.0630i-0.0917-0.0420i-0.0675-0.0264i-0.0458-0.0151i
-0.0267-0.0071i-0.0102-0.0017i 0.0039 + 0.0017i 0.0156 + 0.0034i 0.0249 + 0.0040i 0.0321 + 0.0037i
0.0372 + 0.0028i 0.0402 + 0.0015i
(due to too much data on the coefficient w, not given)
example Three, a general-purpose Butter-worth Low-pass filter is designed with Maxflat function, which satisfies the order of the system function is 8, the system function denominator order is 3 order and the cutoff frequency is 1pi. the code is as follows:
1 nb=8; 2 na=3; 3 wn=0.6; 4 [B,a]=maxflat (Nb,na,wn,'plots')5 maxflat (NB, Na,wn,'trace')
The waveform is as follows:
The command window can be:
b =
0.1650 0.5048 0.4100-0.1134-0.2329-0.0244 0.0202-0.0043 0.0004
A =
1.0000-0.1813 0.2073-0.3006
Table:
L M N wo_min/pi wo_max/pi
8.0000 0 3.0000) 0 0.2919
7.0000 1.0000 3.0000) 0.2919 0.4021
6.0000 2.0000 3.0000) 0.4021 0.5000
5.0000 3.0000 3.0000) 0.5000 0.5979
4.0000 4.0000 3.0000) 0.5979 0.7081
3.0000 5.0000 3.0000) 0.7081 1.0000
Ans =
0.1650 0.5048 0.4100-0.1134-0.2329-0.0244 0.0202-0.0043 0.0004
Another: In the search for FIR filter design and implementation to find Sunev Blogger, a blog post, recommended "FIR filter based on MATLAB design and implementation."
Design and implementation of IIR filter based on MATLAB