FILTERS USING KAISER WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the passband ripple:');
rs=input('Eter the stopband ripple:');
fp=input('Enter the passband frequency:');
fs=input('Enter the stopband frequency:');
f=input('Enter the sampled frequency:');
beta=input('Enter Beta Value:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=kaiser(n1,beta);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(b)normalised frequency');
title('High Pass');

%Band Pass

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(c)normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(d)normalised frequency');
title('Band Stop ');

Input:

Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:

FILTERS USING BLACKMAN WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the passband ripple:');
rs=input('Eter the stopband ripple:');
fp=input('Enter the passband frequency:');
fs=input('Enter the stopband frequency:');
f=input('Enter the sampled frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=blackman(n1);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(b)normalised frequency');
title('High Pass');

%Band Pass

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(c)normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(d)normalised frequency');
title('Band Stop ');


Input:

Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:

FILTERS USING TRIANGULAR WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the passband ripple:');
rs=input('Eter the stopband ripple:');
fp=input('Enter the passband frequency:');
fs=input('Enter the stopband frequency:');
f=input('Enter the sampled frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=bartlett(n1);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(b)normalised frequency');
title('High Pass');

%Band Pass

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(c)normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(d)normalised frequency');
title('Band Stop ');


Input:


Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:


FILTERS USING RECTANGULAR WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the passband ripple:');
rs=input('Eter the stopband ripple:');
fp=input('Enter the passband frequency:');
fs=input('Enter the stopband frequency:');
f=input('Enter the sampled frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs));
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=boxcar(n1);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(b)normalised frequency');
title('High Pass');

%Band Pass

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(c)normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('gain in db');
xlabel('(d)normalised frequency');
title('Band Stop ');


Input:

Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:

FILTERS USING HANNING WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the Passband Ripple:');
rs=input('Enter the Stopband Ripple:');
fp=input('Enter the Passband Frequency:');
fs=input('Enter the Stopband Frequency:');
f=input('Enter the Sampling Frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hanning(n1);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(a)Normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(b)Normalised frequency');
title('High Pass');

%Band Pass

wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(c)Normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(d)Normalised frequency');
title('Band Stop’);

Input:

Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:

FILTERS USING HAMMING WINDOW

clc;
clear all;
close all;
format long;
rp=input('Enter the Passband Ripple:');
rs=input('Enter the Stopband Ripple:');
fp=input('Enter the Passband Frequency:');
fs=input('Enter the Stopband Frequency:');
f=input('Enter the Sampling Frequency:');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs));
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hamming(n1);

%Low Pass

b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(221);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(a)Normalised frequency');
title('Low Pass');

%High Pass

b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(222);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(b)Normalised frequency');
title('High Pass');

%Band Pass

wn=[wp,ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(223);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(c)Normalised frequency');
title('Band Pass');

%Band Stop

wn=[wp,ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(224);
plot(o/pi,m);
ylabel('Gain in dB');
xlabel('(d)Normalised frequency');
title('Band Stop’);

Input:


Enter the Passband Ripple:.01
Enter the Stopband Ripple:.2
Enter the Passband Frequency:1200
Enter the Stopband Frequency:1700
Enter the Sampling Frequency:9000

Output:

CHEBYSHEV TYPE-II STOPBAND FILTER

clc;
clear all;
close all;
format long;
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]=cheb2ord(w1,w2,rp,rs,'s');
wn=[w1,w2];
[b,a]=cheby2(n,rp,wn,'stop','s');
w=0:0.1:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in radians');
xlabel('(b)normalised frequency');

Input:


Enter the Passband Ripple:.01
Enter the Stopband Ripple:20
Enter the Passband Frequency:1000
Enter the Stopband Frequency:2000
Enter the Sampling Frequency:5000

Output: