# Demo entry 6777894

test_IIR

Submitted by starrynightzyq on Dec 11, 2018 at 12:04
Language: Matlab. Code size: 1.9 kB.

```%%
clc;
clear;
T = 1; Fs = 1/T;
wpz = 0.2*pi;
wsz = 0.3*pi;
rp = 1;
rs = 10;

%%
%just for test
%
% wp = (2/T)*tan(wpz/2);
% ws = (2/T)*tan(wsz/2);
% [N, wc] = buttord(wp, ws, rp, rs, 's');
% [B, A] = butter(N, wc, 's');
% [Bz, Az] = bilinear(B, A, Fs);
% [N_my, wc_my] = mybuttord(wp, ws, rp, rs);
% [B_my, A_my] = mybutter(N_my, wc_my);
% [Bz_my, Az_my] = mybilinear(B_my, A_my, Fs);
%
% fvtool(Bz, Az);
% fvtool(Bz_my, Az_my);

%%
%使用双线性变换法设计滤波器
wp = (2/T)*tan(wpz/2);
ws = (2/T)*tan(wsz/2);
[N, wc] = buttord(wp, ws, rp, rs, 's');
[B, A] = butter(N, wc, 's');
[Bz, Az] = bilinear(B, A, Fs);
%画图
h = fvtool(Bz, Az);
title(sprintf('n = %d 使用双线性变换法设计滤波器',N));
%get(h);

%调用buttord和butter直接设计数字滤波器
[Nd, wdc] = buttord(wpz/pi, wsz/pi, rp, rs);
%画图
title(sprintf('n = %d 调用buttord和butter直接设计数字滤波器',Nd));

%使用自己写的函数（双线性变换法）设计滤波器
[Bz_my, Ad_my, N_my] = myIIR(wpz, wsz, rp, rs);
%画图
title(sprintf('n = %d 自己设计的巴特沃兹低通滤波器',N_my));

%%
%椭圆滤波器
[n_e,Wc_e] = ellipord(wp/pi,ws/pi,rp,rs);      % Gives mimimum order of filter
[B_e,A_e] = ellip(n_e,rp,rs,Wc_e);          % Elliptic filter design
%画图
%freqz(B_e,A_e,512,1000);                % Plots the frequency response
fvtool(B_e, A_e);
title(sprintf('n = %d Elliptic Lowpass Filter',n_e));

%%
%cheby1滤波器
[n_c1,Wc_c1] = cheb1ord(wp/pi,ws/pi,rp,rs);  % Gives mimimum order of filter
[B_c1,A_c1] = cheby1(n_c1,rp,Wc_c1,'low');        % Chebyshev Type I filter
fvtool(B_c1, A_c1);
title(sprintf('n = %d chebyshev1 Lowpass Filter',n_c1));

%%
%cheby2滤波器
[n_c2,Wc_c2] = cheb2ord(wp/pi,ws/pi,rp,rs);  % Gives mimimum order of filter
[B_c2,A_c2] = cheby2(n_c2,rs,Wc_c2,'low');        % Chebyshev Type II filter
fvtool(B_c2, A_c2);
title(sprintf('n = %d chebyshev2 Lowpass Filter',n_c2));
```

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.