Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, June 2, 2016

IIR BUTTERWORTH BANDSTOP FILTER

PROGRAM:
clc;
close all;
clear all;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n]=buttord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=butter(n,wn,'stop');
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(om/pi,m);
ylabel('Gain in dB--->');
xlabel('Normalised frequency--->');
title('A. Magnitude Plot');
subplot(212);
plot(om/pi,an);
ylabel('Phase in radians--->');
xlabel('Normalised frequency--->');
title('B. Phase Plot');

 
SAMPLE OUTPUT:
Enter the passband ripple: 0.2
Enter the stopband ripple:75
Enter the passband frequency:1000
Enter the stopband frequency: 2500
Enter the sampling frequency: 7000

PLOT:



IIR BUTTERWORTH BANDPASS FILTER

PROGRAM: clc;
close all;
clear all;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n]=buttord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=butter(n,wn,'bandpass');
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(om/pi,m);
ylabel('Gain in dB--->');
xlabel('Normalised frequency--->');
title('A. Magnitude Plot');
subplot(212);
plot(om/pi,an);
ylabel('Phase in radians--->');
xlabel('Normalised frequency--->');
title('B. Phase Plot');

 
SAMPLE OUTPUT:
Enter the passband ripple: 0.3
Enter the stopband ripple: 40
Enter the passband frequency:1500
Enter the stopband frequency: 2000
Enter the sampling frequency: 9000

PLOT:



IIR BUTTERWORTH HIGHPASS FILTER

PROGRAM: clc;
close all;
clear all;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(om/pi,m);
ylabel('Gain in dB--->');
xlabel('Normalised frequency--->');
title('A. Magnitude Plot');
subplot(212);
plot(om/pi,an);
ylabel('Phase in radians--->');
xlabel('Normalised frequency--->');
title('B. Phase Plot');

 
SAMPLE OUTPUT:
Enter the passband ripple: 0.5
Enter the stopband ripple: 50
Enter the passband frequency:2400
Enter the stopband frequency: 1200
Enter the sampling frequency: 10000

PLOT:



IIR BUTTERWORTH LOWPASS FILTER

PROGRAM: clc;
clear all;
close all;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(om/pi,m);
ylabel('Gain in dB--->');
xlabel('Normalised frequency--->');
title('A. Magnitude Plot');
subplot(212);
plot(om/pi,an);
ylabel('Phase in radians--->');
xlabel('Normalised frequency--->');
title('B. Phase Plot');

SAMPLE OUTPUT:
Enter the passband ripple: 0.5
Enter the stopband ripple: 50
Enter the passband frequency: 1200
Enter the stopband frequency: 2400
Enter the sampling frequency: 10000

PLOT: