You are on page 1of 3

clc;

clear all;
close all;

% butterworth filter design


%% low pass filter %% band pass filter
rp = 2;
rs = 10; rp = 0.5;
wp = 20; rs = 50;
ws = 30; wp = [1400 2100];
fs = 3000; ws = [1050 2450];
w1 = 2*wp/fs; fs = 7000;
w2 = 2*ws/fs; w1 = 2*wp/fs;
[h, wn] = buttord(w1, w2, rp, rs); w2 = 2*ws/fs;
[b, a] = butter(h, wn); [h, wn] = buttord(w1, w2, rp, rs);
w = 0:.01:pi; [b, a] = butter(h, wn, 'BANDPASS');
[h, om] = freqz(b,a,w); w = 0:.01:pi;
m = 20*log10(abs(h)); [h, om] = freqz(b,a,w);
an = angle(h); m = 20*log10(abs(h));
subplot(421); an = angle(h);
plot(om/pi, m); subplot(425);
ylabel('Gain in dB'); plot(om/pi, m);
xlabel('Normalized frequency'); ylabel('Gain in dB');
subplot(422); xlabel('Normalized frequency');
plot(om/pi, an); subplot(426);
xlabel('Normalized frequency'); plot(om/pi, an);
ylabel('Phase in radian'); xlabel('Normalized frequency');
ylabel('Phase in radian');
%% high pass filter
rp = 1; %% band reject filter
rs = 50; rp = 0.6;
wp = 1050; rs = 45;
ws = 600; wp = [2100 4500];
fs = 3500; ws = [2700, 3900];
w1 = 2*wp/fs; fs = 12000;
w2 = 2*ws/fs; w1 = 2*wp/fs;
[h, wn] = buttord(w1, w2, rp, rs); w2 = 2*ws/fs;
[b, a] = butter(h, wn, 'high'); [h, wn] = buttord(w1, w2, rp, rs);
w = 0:.01:pi; [b, a] = butter(h, wn, 'stop');
[h, om] = freqz(b,a,w); w = 0:.01:pi;
m = 20*log10(abs(h)); [h, om] = freqz(b,a,w);
an = angle(h); m = 20*log10(abs(h));
subplot(423); an = angle(h);
plot(om/pi, m); subplot(427);
ylabel('Gain in dB'); plot(om/pi, m);
xlabel('Normalized frequency'); ylabel('Gain in dB');
subplot(424); xlabel('Normalized frequency');
plot(om/pi, an); subplot(428);
xlabel('Normalized frequency'); plot(om/pi, an);
ylabel('Phase in radian'); xlabel('Normalized frequency');
ylabel('Phase in radian');

You might also like