%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IIRフィルタ (ローパスフィルタの設計)
%
%                                                      2003.12.10 Katto Lab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;

% 変数設定
N = 5;              % Butterworth フィルタの次数
Fs = 1;             % サンプリング周波数 (Hz単位)

% プロトタイプアナログフィルタの作成
%% N 次の Butterworth ローパスフィルタ
[z,p,k] = buttap(N);
[num,den] = zp2tf(z,p,k);
%% 周波数特性と正規化
[h0,w0] = freqs(num,den);
w0 = w0 / Fs;

% インパルス不変法
[bz,az] = impinvar(num,den,Fs);
[h1,w1] = freqz(bz,az);

% 双一次変換
[bz,az] = bilinear(num,den,Fs);
[h2,w2] = freqz(bz,az);

% グラフ表示
figure;
plot(w0,abs(h0),'r'); hold on;
plot(w1,abs(h1),'g'); hold on;
plot(w2,abs(h2),'b'); hold on;
axis([0.0, pi, 0.0, 1.2]);
legend('Butterworth LPF', 'IIR (impulse)', 'IIR (bilinear)');
xlabel('normalized frequency');
ylabel('frequency response');









