Professional Documents
Culture Documents
20BEC1042
EXPERIMENT 9
IIR FILTER DESIGN USING MATLAB
Aim:
To design a 3rd order Butterworth filter which eliminates sin(2π8t)
component from the signal x(t) = 2+sin(2π8t)
To design a lowpass Butterworth filter where fc = 40Hz, fc = 200Hz and
order of filter is N=4
To design a lowpass and highpass Butterworth filter of order 4 with a cut-
off frequency of 12.5Hzand filter the signal
x(t) = 0.25+2 sin(2π5t)+sin(2π12.5t)+1.5 sin(2π20t)+0.5 sin(2π35t),
and visualize the filtered signal
Program code:
clc
close all
clear all
%Butterworth filter Q1
N=3
t=0:0.01:10;
x=2+sin(2*pi*8*t);
[b1,a1]=butter(N,0.05,'low');
[h,w]=freqz(b1,a1);
figure(1)
subplot(5,1,1)
plot(x,'b','LineWidth',2)
xlim([0 100])
xlabel('t', 'fontsize', 10, 'fontweight', 'bold');
ylabel('Amplitude', 'fontsize', 10, 'fontweight', 'bold');
title('Signal','fontsize',12, 'fontweight', 'bold')
h1=fft(x);
subplot(5,1,2)
plot(abs(h1),'k','LineWidth',2)
xlim([0 100])
xlabel('Frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(f)|', 'fontsize', 10, 'fontweight', 'bold');
subplot(5,1,3)
plot(abs(h),'r','LineWidth',2)
xlim([0 100])
xlabel('frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(w)|', 'fontsize', 10, 'fontweight', 'bold');
title('Butterworth LowPass Filter','fontsize',12, 'fontweight',
'bold')
y=filter(b1,a1,x);
subplot(5,1,4)
plot(y,'m','LineWidth',2)
xlim([0 100])
xlabel('t', 'fontsize', 10, 'fontweight', 'bold');
ylabel('Amplitude', 'fontsize', 10, 'fontweight', 'bold');
title('Filtered signal','fontsize',12, 'fontweight', 'bold')
h2=fft(y);
subplot(5,1,5)
plot(abs(h2),'LineWidth',2)
xlim([0 100])
xlabel('Frquency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(f)|', 'fontsize', 10, 'fontweight', 'bold');
title('Frequency Spectrum of Filtered signal','fontsize',12,
'fontweight', 'bold')
%Butterworth filter Q2
N=4
fc1=40
fs=1000
%Wn=fc/(fs/2)=0.08
[b1,a1]=butter(N,0.08,'low');
[h,w]=freqz(b1,a1);
figure(2)
plot(abs(h),'k','LineWidth',2)
xlabel('frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(w)|', 'fontsize', 10, 'fontweight', 'bold');
title('Butterworth LPF','fontsize',12, 'fontweight', 'bold')
grid on
hold on
fc2=200
%Wn=fc/(fs/2)=0.4
[b1,a1]=butter(N,0.4,'low');
[h,w]=freqz(b1,a1);
plot(abs(h),'m','LineWidth',2)
legend('fc=40','fc=200')
h1=fft(x);
subplot(3,2,2)
plot(abs(h1),'k','LineWidth',2)
xlim([0 100])
xlabel('Frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(f)|', 'fontsize', 10, 'fontweight', 'bold');
title('Fequency spectrum of signal','fontsize',12, 'fontweight',
'bold')
subplot(3,2,3)
plot(abs(h),'r','LineWidth',2)
xlim([0 100])
xlabel('frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(w)|', 'fontsize', 10, 'fontweight', 'bold');
title('Butterworth LowPass Filter','fontsize',12, 'fontweight',
'bold')
y=filter(b1,a1,x);
subplot(3,2,4)
plot(y,'m','LineWidth',2)
xlim([0 100])
xlabel('t', 'fontsize', 10, 'fontweight', 'bold');
ylabel('Amplitude', 'fontsize', 10, 'fontweight', 'bold');
title('Filtered signal','fontsize',12, 'fontweight', 'bold')
h2=fft(y);
subplot(3,2,5)
plot(abs(h2),'LineWidth',2)
xlim([0 100])
xlabel('Frquency', 'fontsize', 10, 'fontweight', 'bold');
%HPF
N=4
t=0:0.01:10;
x=0.25+2*sin(2*pi*5*t)+sin(2*pi*12.5*t)+1.5*sin(2*pi*20*t)
+0.5*sin(2*pi*35*t);
fc=12.5
fs=500
%Wn=fc/(fs/2)=0.025
[b1,a1]=butter(N,0.0625,'high');
[h,w]=freqz(b1,a1);
figure(4)
subplot(3,2,1)
plot(x,'b','LineWidth',2)
xlim([0 100])
xlabel('t', 'fontsize', 10, 'fontweight', 'bold');
ylabel('Amplitude', 'fontsize', 10, 'fontweight', 'bold');
title('Signal','fontsize',12, 'fontweight', 'bold')
h1=fft(x);
subplot(3,2,2)
plot(abs(h1),'k','LineWidth',2)
xlim([0 100])
xlabel('Frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(f)|', 'fontsize', 10, 'fontweight', 'bold');
title('Fequency spectrum of signal','fontsize',12, 'fontweight',
'bold')
subplot(3,2,3)
plot(abs(h),'r','LineWidth',2)
xlim([0 100])
xlabel('frequency', 'fontsize', 10, 'fontweight', 'bold');
ylabel('|H(w)|', 'fontsize', 10, 'fontweight', 'bold');
title('Butterworth HighPass Filter','fontsize',12, 'fontweight',
'bold')
y=filter(b1,a1,x);
subplot(3,2,4)
plot(y,'m','LineWidth',2)
xlim([0 100])
xlabel('t', 'fontsize', 10, 'fontweight', 'bold');
ylabel('Amplitude', 'fontsize', 10, 'fontweight', 'bold');
title('Filtered signal','fontsize',12, 'fontweight', 'bold')
h2=fft(y);
subplot(3,2,5)
Output:
Butterworth filter of order 3 to eliminate sin(2π8t)
4th order Butterworth LPF with cut-off frequencies 40Hz and 200Hz
Result: We have thus designed the required Butterworth filters according to the
given specifications and their characteristics were observed. The filtered signals
were also visualized using MATLAB.
Output verification: