You are on page 1of 71

Ex.

N DATE LIST OF EXPERIMENTS SIGNATURE


o
A) Generation and Plotting of Elementary Discrete Time signals using
1 MATLAB
B) Generation and Manipulation of Arbitrary Discrete Time Sequence
using MATLAB
A) Basic operations on Elementary Discrete Time sequence using
2 MATLAB
B) Computing Correlation of given Discrete Time Sequence using
MATLAB
A) Z’ Transform analysis of Discrete Time system using MATLAB
3
B) Plotting Magnitude and Phase response of Discrete Time system
using MATLAB
4 Linear and Circular Convolution using MATLAB

5 Design of IIR analog and digital filters using MATLAB


A) Design of FIR LPF and HPF filters using Rectangular
Windowing Technique
6 B) Design of FIR BPF and BSF using filters using Hamming
Windowing Technique
7 Design and Implementation of Traffic Light Controller using VHDL

8 Design and Implementation of Character Display in Seven segment


LED using VHDL
9 Design and Implementation of Character Display in LCD using VHDL

10 Basic Operations in Image Processing using MATLAB


%DELTA FUNCTION
clc;
clear all;
t=-20:20;
y1=zeros(1,20);
y2=1;
y3=zeros(1,20);
delta=[y1 y2 y3];
figure(1);
subplot(3,1,1);
stem(t,delta);
xlabel('n');
ylabel('amplitude');
title('DELTA FUNCTION');
%UNIT STEP FUNCTION
t=-20:20;
y1=zeros(1,20);
y2=ones(1,21);
stf=[y1 y2];
subplot(3,1,2);
stem(t,stf);
xlabel('n');
ylabel('amplitude');
title('UNIT STEP FUNCTION');
%a^nu(n) for (a=0.9)
n=-20:20;
sig=((0.9.^n).*stf);
subplot(3,1,3);
stem(n,sig);
xlabel('n');
ylabel('amplitude');
title('a^nu(n) for (a=0.9)');
%EXPONENTIAL
t=-5:0.01:5;
sig1=exp((3+4*i)*t);
figure(2);
subplot(3,1,1);
plot(t,abs(sig1));
xlabel('n');
ylabel('amplitude');
title('MAGNITUDE RESPONSE');
subplot(3,1,2);
plot(t,angle(sig1));
xlabel('n');
ylabel('phase');
title('PHASE RESPONSE ');
%TRIGNOMETRIC FUNCTION
n=0:0.01:10;
sig2=3*cos(0.4*pi*n)+2*sin(0.3*pi*n);
subplot(3,1,3);
plot(n,sig2);
xlabel('n');
ylabel('amplitude');
title('TRIGNOMETRIC FUNCTION');
%SYMMETRICAL SQUARE WAVE
t=0:0.1:4.9;
y1=zeros(1,25);
y2=ones(1,25);
s=[y1 y2];
sqrwav=[s s s s s ];
figure(3);
subplot(3,1,1);
plot((0:0.1:24.9),sqrwav);
xlabel('n');
ylabel('amplitude');
title('SYMMETRICAL SQUARE WAVE');
%RAMP FUNCTION
t=0:0.1:5;
sig3=t;
subplot(3,1,2);
stem(t,sig3);
xlabel('n');
ylabel('amplitude');
title('RAMP FUNCTION');
%SYMMETRICAL TRIANGULAR WAVE
t=-1:0.01:1;
tri=1-(abs(t));
triwav=[tri tri tri tri];
subplot(3,1,3);
plot((0:0.01:8.03),triwav);
xlabel('n');
ylabel('amplitude');
title('SYMMETRICAL TRIANGULAR WAVE');
%SINE FUNCTION
t=-4:0.0001:4;
sincfn=sin(pi*t)./(pi*t);
figure(4);
subplot(3,1,1);
plot(t,sincfn);
xlabel('n');
ylabel('amplitude');
title('SINC FUNCTION');
%RANDOM FUNCTION SIGNAL
x=rand(1,100);
y=4*x-2;
subplot(3,1,2);
plot(y);
xlabel('n');
ylabel('amplitude');
title('RANDOM SIGNAL ');
%GAUSSIAN RANDOM SIGNAL
x=randn(1,100);
subplot(3,1,3);
plot(x);
xlabel('n');
ylabel('amplitude');
title('GAUSSIAN RANDOM SIGNAL');
DELTA FUNCTION
1
amplitude

0.5

0
-20 -15 -10 -5 0 5 10 15 20
n
UNIT STEP FUNCTION
1
amplitude

0.5

0
-20 -15 -10 -5 0 5 10 15 20
n
anu(n) for (a=0.9)
1
amplitude

0.5

0
-20 -15 -10 -5 0 5 10 15 20
n
6
x 10 MAGNITUDE RESPONSE
4
amplitude

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
PHASE RESPONSE
5
phase

-5
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
TRIGNOMETRIC FUNCTION
5
amplitude

-5
0 1 2 3 4 5 6 7 8 9 10
n
SYMMETRICAL SQUARE WAVE
1
amplitude

0.5

0
0 5 10 15 20 25
n
RAMP FUNCTION
5
amplitude

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
n
SYMMETRICAL TRIANGULAR WAVE
1
amplitude

0.5

0
0 1 2 3 4 5 6 7 8 9
n
SINC FUNCTION
1
amplitude

0.5

-0.5
-4 -3 -2 -1 0 1 2 3 4
n
RANDOM SIGNAL
2

1
amplitude

-1

-2
0 10 20 30 40 50 60 70 80 90 100
n
GAUSSIAN RANDOM SIGNAL
4

2
amplitude

-2

-4
0 10 20 30 40 50 60 70 80 90 100
n
%SUPERPOSITION:
n=-10:10;
y1=[zeros(1,12),ones(1,1),zeros(1,8)];
y2=[zeros(1,5),ones(1,1),zeros(1,15)];
y=y1+y2;
figure(1);
subplot(2,1,1);
stem(n,y);
xlabel('n');
ylabel('amplitude');
title('super position');

%TIME SHIFTING:
n=-10:10;
y1=zeros(1,17);
y2=ones(1,1);
y3=zeros(1,3);
y=[y1 y2 y3];
subplot(2,1,2);
stem(n,y);
xlabel('n');
ylabel('amplitude');
title('time shifting');
%GENERATION OF 4*x(n-4)-2*x(n+3):
clear;
clc;
x=[1 3 5 7 2 4 6 8 1 2 3 4 ];
n=-20:20;
yt1=zeros(1,24);
x=x;
yt2=zeros(1,5);
y1=[yt1 x yt2];
y1=4*y1;
figure(2);
subplot(3,1,1);
stem(n,y1);
xlabel('n');
ylabel('amplitude');
title('4*x(n-4)');
n=-20:20;
yt3=zeros(1,17);
x=x;
yt4=zeros(1,12);
y2=[yt3 x yt4];
y2=2*y2;
subplot(3,1,2);
stem(n,y2);
xlabel('n');
ylabel('amplitude');
title('2*x(n+3');
y3=y1-y2;
subplot(3,1,3);
stem(n,y3);
xlabel('n');ylabel('amplitude');title('GENERATION OF 4*x(n-4)-2*x(n+3)');
superposition
amplitude 1

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
time shifting
1
amplitude

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
4*x(n-4)
40
amplitude

20

0
-20 -15 -10 -5 0 5 10 15 20
n
2*x(n+3
20
amplitude

10

0
-20 -15 -10 -5 0 5 10 15 20
n
GENERATION OF 4*x(n-4)-2*x(n+3)
50
amplitude

-50
-20 -15 -10 -5 0 5 10 15 20
n
Basic operations on Elementary Discrete Time sequence using MATLAB

%GENERATION OF x(n)=u(n)-u(n-2):
n=-10:10;
x=[zeros(1,10),ones(1,11)]-[zeros(1,12),ones(1,9)];
figure(1);
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('x(n)=u(n)-u(n-2)');
%GENERATION OF -u(n+3)+2u(n+1)-2u(n-1)+u(n-3):
n=-5:5;
figure(2);
a=[zeros(1,2),ones(1,9)];
b=[zeros(1,4),ones(1,7)];
c=[zeros(1,6),ones(1,5)];
d=[zeros(1,8),ones(1,3)];
e=-a;
f=2*b;
g=-2*c;
h=d;
subplot(2,2,1);
stem(n,e);
title('-u(n+3)');
xlabel('n');
ylabel('amplitude');
subplot(2,2,2);
stem(n,f);
title('+2u(n+1)');
xlabel('n');
ylabel('amplitude');
subplot(2,2,3);
stem(n,g);
title('2u(n-1)');
xlabel('n');
ylabel('amplitude');
subplot(2,2,4);
stem(n,h);
title('u(n-3)');
xlabel('n');
ylabel('amplitude');
figure(3);
subplot(2,1,1);
x=e+f+g+h;
stem(n,x);
title('x(n)=-u(n+3)+2u(n+1)-2u(n-1)+u(n-3)');
xlabel('n');ylabel('amplitude');
%RAISED COSINE SIGNAL:
t=-0.05:0.001:0.05;
x=cos(pi*0.1*t*2);
subplot(2,1,2);
plot(t,x);
title('raised cosine signal');
xlabel('n');
ylabel('x(n)');
%GENERATION OF UNIT EVEN AND ODD STEP SIGNAL:
n=-30:30;
x=[zeros(1,30),ones(1,31)]-[zeros(1,50),ones(1,11)];
y=fliplr(x);
xe=0.5*(x+y);
xo=0.5*(x-y);
figure(4);
subplot(2,1,1);
stem(n,xe);
title('even component');
xlabel('n');
ylabel('Xe(n)');
subplot(2,1,2);
stem(n,xo);
title('odd component');
xlabel('n');
ylabel('Xo(n)');
x(n)=u(n)-u(n-2)
1

0.5
x(n)

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
-u(n+3) +2u(n+1)
0 2

1.5
amplitude

amplitude
-0.5 1

0.5

-1 0
-5 0 5 -5 0 5
n n
2u(n-1) u(n-3)
0 1

-0.5
amplitude

amplitude

-1 0.5

-1.5

-2 0
-5 0 5 -5 0 5
n n
x(n)=-u(n+3)+2u(n+1)-2u(n-1)+u(n-3)
1

0.5
amplitude

-0.5

-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
raised cosine signal
1

0.9998
x(n)

0.9996

0.9994
-0.05 -0.04 -0.03 -0.02 -0.01 0 0.01 0.02 0.03 0.04 0.05
n
even component
1
Xe(n)

0.5

0
-30 -20 -10 0 10 20 30
n
odd component
0.5
Xo(n)

-0.5
-30 -20 -10 0 10 20 30
n
Computing Correlation of given Discrete Time Sequence using MATLAB

%CROSS CORRELATION:
clc;
clear all;
x1=[1 2 3 4];
x2=[4 3 2 1];
y=xcorr(x1,x2);
figure(1);
subplot(3,1,1);
i=0:1:3;
stem(i,x1);
title('x1(n)');
ylabel('amplitude');
xlabel('n');
subplot(3,1,2);
stem(i,x2);
title('x2(n)');
ylabel('amplitude');
xlabel('n');
subplot(3,1,3);
i=-3:1:3;
stem(i,y);
ylabel('amplitude');
xlabel('n');
title('cross correlation');
disp('the resultant signal is');
disp(y);
%AUTO CORRELATION FUNCTION:
x=[1 2 3 4 ];
y=xcorr(x,x);
figure(2);
subplot(2,1,1);
i=0:1:3;
stem(i,x);
ylabel('amplitude');
xlabel('n');
title('x');
subplot(2,1,2);
i=-3:1:3;
stem(i,y);
ylabel('amplitude');
xlabel('n');
title('auto correlation');
disp('the resultant signal is');
disp(y);
x1(n)
4
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
x2(n)
4
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
cross correlation
40
amplitude

20

0
-3 -2 -1 0 1 2 3
n
x
4

3
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
auto correlation
30

20
amplitude

10

0
-3 -2 -1 0 1 2 3
n

‘Z’ Transform analysis of Discrete Time system using MATLAB


%Transfer Function
num =[1,0];
den=[1,-0.9];
z=sym('z');
h=num(1)*z/(den(1)*z+den(2));
disp('Transfer function is:');
disp(h);
%Zero pole plot:
figure(1);
subplot (2,1,1);
zplane(num,den);
title ('Zero pole plot');
%Impulse response:
ip=[ones(1,1),zeros(1,50)];
y=filter(num,den,ip);
n=0:1:50;
subplot(2,1,2);
stem(n,y);
title('Impulse Response:');
ylabel('h(n)');
xlabel('n');
%transfer Function:
num=[1,0,-1];
den=[1,0,-0.81];
z=tf('z');
h=(1*z^2-1)/(1*z^2-0.81);
%Impulse response:
ip=[1,zeros(1,50)];
y=filter(num,den,ip);
n=0:1:50;
figure(2);
subplot(2,1,1);
stem(n,y);
title('Impulse Response:');
ylabel('h(n)');
xlabel('n');
%Step response:
stepIp=[ones(1,51)];
y=filter(num,den,stepIp);
subplot(2,1,2);
stem(n,y);
title('Step Response:');
ylabel('y(n)');
xlabel('n');
Zero pole plot
1

0.5
Imaginary Part

-0.5

-1
-3 -2 -1 0 1 2 3
Real Part
Impulse Response:
1

0.5
h(n)

0
0 5 10 15 20 25 30 35 40 45 50
n
Impulse Response:
1

0.5
h(n)

-0.5
0 5 10 15 20 25 30 35 40 45 50
n
Step Response:
1
y(n)

0.5

0
0 5 10 15 20 25 30 35 40 45 50
n
Plotting Magnitude and Phase response of Discrete Time system using MATLAB

%To plot the frequency response of first order system:


clear;
b=[1];
a=[1,-0.5];
w=0:1:2*pi;
[h]=freqz(b,a,w);
figure(3);
subplot(2,1,1);
plot(w/pi,abs(h));
grid on;
title('magnitude response of first order system h(n)=0.5^nu(n)');
ylabel('magnitude');
xlabel('normalised frequency');
subplot(2,1,2);
plot(w/pi,angle(h));
grid on;
ylabel('phase in radians');
xlabel('normalised frequency');
title('phase resoonse of first order system h(n)=0.5^nu(n)');
magnitude response of first order system h(n)=0.5nu(n)
2
magnitude

1.5

0.5
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
normalised frequency
phase resoonse of first order system h(n)=0.5nu(n)
1
phase in radians

0.5

-0.5

-1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
normalised frequency
LINEAR & CIRCULAR CONVOLUTION USING MATLAB
%Linear Convolution:
x=[1 2 3 4 5 6];
h=[1 2 3 4 5 6];
y=conv(x,h);
subplot(2,1,1);
stem(y);
title('y(n)=x(n)*h(n)');
xlabel('n')
ylabel('y(n)');
n=-5:15;
x=[zeros(1,7),ones(1,14)]-[zeros(1,12),ones(1,9)];
h=[zeros(1,5),ones(1,16)]-[zeros(1,15),ones(1,6)];
y=conv(x,h);
subplot(2,1,2);
stem(y);
title('y(n)=x(n)*h(n)');
xlabel('n');
ylabel('y(n)');
n=-5:15;
figure;
a=[zeros(1,3),ones(1,18)]-[zeros(1,17),ones(1,4)];
x=2*a;
b=[zeros(1,7),ones(1,14)]-[zeros(1,18),ones(1,3)];
h=(0.9.^n).*b;
y=conv(x,h);
subplot(2,1,1);
stem(y);
title('y(n)=x(n)*h(n)');
xlabel('n');
ylabel('y(n)');
x1=[3 1 6];
x2=[2 3 4 5];
y=conv(x1,x2);
subplot(2,1,2);
stem(y);
title('y(n)=x(n)*h(n)');
xlabel('n');
ylabel('y(n)');
y(n)=x(n)*h(n)
80

60

40
y(n)

20

0
1 2 3 4 5 6 7 8 9 10 11
n
y(n)=x(n)*h(n)
6

4
y(n)

0
0 5 10 15 20 25 30 35 40 45
n
y(n)=x(n)*h(n)
15

10
y(n)

0
0 5 10 15 20 25 30 35 40 45
n
y(n)=x(n)*h(n)
40

30
y(n)

20

10

0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n
CIRCULAR CONVOLUTION
clc;
clear all;
x=input('enter first sequence');
h=input('enter second sequence');
n1=length(x);
n2=length(h);
n3=max(n1,n2);
if n1>n2
h=[h,zeros(1,n1-n2)]
else
x=[x,zeros(1,n2-n1)]
n1=n2;
end;
for i=1:n3;
y(i)=0;
for n=1:n3;
k=i-n+1;
if k<=0
k=k+n3
end;
y(i)=y(i)+[x(n)*h(k)]
end;
figure(1);
subplot(3,1,1);
i=0:1:3;
stem(i,x);
xlabel('n');
ylabel('amplitude');
subplot(3,1,2);
stem(i,h);
xlabel('n');
ylabel('amplitude');
subplot(3,1,3);
xlabel('n');
ylabel('amplitude');
stem(y);
xlabel('n');
ylabel('amplitude');
title('circular convnolution');
disp('conv sequence');
end;
%enter first sequence [2 4 6 8]
%enter second sequence [1 3 5 7]
10
amplitude

0
0 0.5 1 1.5 2 2.5 3
n

10
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
circular convnolution
100
amplitude

50

0
1 1.5 2 2.5 3 3.5 4
n
%CIRCULAR CONVOLUTION USING DFT:
clc;
clear all;
x1=input('enter first sequence');
x2=input('enter second sequence');
n1=length(x1);
n2=length(x2);
if n1>n2
x2=[x2,zeros(1,n1-n2)];
else
x1=[x1,zeros(1,n1-n2)];
n1=n2
end;
x=fft(x1,n1);
h=fft(x2,n2);
y=(x.*h);
y1=ifft(y);
figure(2);
subplot(3,1,1);
i=0:1:3;
stem(i,x1);
xlabel('n');
ylabel('amplitude');
title('x(n)');
subplot(3,1,2);
stem(i,x2);
xlabel('n');
ylabel('amplitude');
title('h(n)');
subplot(3,1,3);
stem(i,y1);
xlabel('n');
ylabel('amplitude');
title('circular convolution using DFT');
disp(y1);

%enter first sequence[2 4 6 8]


%enter second sequence[1 3 5 7]
x(n)
10
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
h(n)
10
amplitude

0
0 0.5 1 1.5 2 2.5 3
n
circular convolution using DFT
100
amplitude

50

0
0 0.5 1 1.5 2 2.5 3
n
Iir analog and digital filters using matlab

%BUTTERWORTH LPF:
clc;
clear all;
close all;
format long;
rp=input('Enter the pass band ripple');
rs=input('Enter the stop band ripple');
wp=input('Enter the pass band frequency');
ws=input('Enter the stop band frequency');
fs=input('Enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
disp(n);
disp(wn);
[b,a]=butter(n,wn,'low','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);grid on;
ylabel('Gain in db');
xlabel('Normalised Frequency');
title('Frequency Response Of Butterworth Lowpass Filter');
subplot(2,1,2);
plot(om/pi,an);grid on;
ylabel('Phase In Radians');
xlabel('Normalised Frequency');
%Enter the pass band ripple 0.15
%Enter the stop band ripple 30
%Enter the pass band frequency 1500
%Enter the stop band frequency 3000
%Enter the sampling frequency 7000
FREQUENCY RESPONSE OF BUTTERWORTH LOWPASS FILTER
50

0
gain in db

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

2
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
%BUTTERWORTH HIGH PASS FILTER:
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,'s');
disp(n);
disp(wn);
[b,a]=butter(n,wn,'high','s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);grid on;
title('Frequency Response Of Butterworth High Pass Filter');
ylabel('Gain in db');
xlabel('Normalised Frequency');
subplot(2,1,2);
plot(om/pi,an);grid on;
ylabel('Phase in Radians');
xlabel(' Normalised Frequency');
%Enter the pass band ripple 0.15
%Enter the stop band ripple 30
%Enter the pass band frequency 1500
%Enter the stop band frequency 3000
%Enter the sampling frequency 7000
frequency response of butterworth high pass filter
0

-100
Gain in db

-200

-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised Frequency

2
Phase in Radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised Frequency
%BUTTER WORTH FILTER
clear all;
rp=0.5;rs=50;wp=1200;ws=2400;fs=10000;
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
disp(n);
disp(wn);
[z,p,k]=butter(n,wn,'high');
[b,a]=butter(n,wn,'high');
figure(1);
subplot(3,1,1);
zplane(z,p);
grid on;
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
title('Frequency response of Butterworth high pass filter');
subplot(3,1,2);
plot(om/pi,m);
xlabel('normalised frequency');
ylabel('gain in dB');
grid on;
subplot(3,1,3);
plot(om/pi,an);
xlabel('normalised frequency');
ylabel('angle in radians');
grid on;
%CHEBYSHEV TYPE I FILTER:
rp=3;rs=40;wp=1200;ws=2400;fs=8000;
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
disp(n);
disp(wn);
[z,p,k]=cheby1(n,rp,wn,'high');
[b,a]=cheby1(n,rp,wn,'high');
figure(2);
subplot(3,1,1);
zplane(z,p);
grid on;
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
title('Frequency Response of Chebyshew Type-I Filter');
subplot(3,1,2);
plot(om/pi,m);
xlabel('normalised frequency');
ylabel('gain in dB');
grid on;
subplot(3,1,3);
plot(om/pi,an);
xlabel('normalised frequency ');
ylabel('angle in radians');
grid on;
%CHEBYSHEV TYPE II FILTER:
rp=3;rs=40;wp=1200;ws=2400;fs=8000;
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs);
disp(n);
disp(wn);
[z,p,k]=cheby2(n,rs,wn,'high');
[b,a]=cheby2(n,rs,wn,'high');
figure(3);
subplot(3,1,1);
zplane(z,p);
grid on;
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h)/pi);
an=angle(h);
title('Frequency Response of Chebyshev Type=II Filter');
subplot(3,1,2);
plot(om/pi,m);
xlabel('normalised frequency');
ylabel('gain in dB');
grid on;
subplot(3,1,3);
plot(om/pi,an);
xlabel('normalised frequency');
ylabel('angle in radians');
grid on;
%ELLIPTIC FILTER:
rp=3;rs=50;wp=1500;ws=2400;fs=8000;
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=ellipord(w1,w2,rp,rs);
disp(n);
disp(wn);
[z,p,k]=ellip(n,rp,rs,wn,'high');
[b,a]=ellip(n,rp,rs,wn,'high');
figure(4);
subplot(3,1,1);
zplane(z,p);
grid on;
w=0:0.10:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
title('Frequency Response of Elliptic Filter');
subplot(3,1,2);
plot(om/pi,m);
xlabel('normalised frequency');
ylabel('gain in dB');
grid on;
subplot(3,1,3);
plot(om/pi,an);
xlabel('normalised frequency');
ylabel('angle in radians');
grid on;
Frequency response of Butterworth high pass filter
Imaginary Part

1
8
0

-1
-5 0 5
Real Part

500
gain in dB

-500
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
angle in radians

-5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
Frequency Response of Chebyshew Type-I Filter
Imaginary Part

1
4
0

-1
-5 0 5
Real Part

0
gain in dB

-200

-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
angle in radians

-5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
Frequency Response of Chebyshev Type=II Filter
1
Imaginary Part

-1
-6 -4 -2 0 2 4 6
Real Part

0
gain in dB

-100

-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

5
angle in radians

-5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
Frequency Response of Elliptic Filter
Imaginary Part

-1
-6 -4 -2 0 2 4 6
Real Part

0
gain in dB

-50

-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

5
angle in radians

-5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
DESIGN OF FIR FILTERS (LPF AND HPF) USING WINDOWING
TECHINIQUES
%FIR LPF using Rectangular and Hamming window
clear all;
wc=0.5*pi;
N=11;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
m=(n-alpha+eps);
hd=sin(wc*m)./(pi*m);
wr=boxcar(N);
hn=hd.*wr';
disp(hn);
w=0:0.01:pi;
h=freqz(hn,1,w);
figure(1);
i=-(N-1)/2:1:(N-1)/2;
stem(i,hn); grid on;
title('FILTER COEFFICIENTS');
xlabel('n');
ylabel('hn');
figure(2);
plot(w/pi,abs(h),'r');
grid on;
hold on;
wh=hamming(N);
disp(wh);
hn=hd.*wh';
disp(hn);
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');
grid on;
ylabel('magnitude');
xlabel('normalised frequency');
hold off;
title('FIR LPF using windowing technique');
%FIR HPF using Rectangular and Blackman window
clear all;
wc=0.5*pi;
N=11;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
m=(n-alpha+eps);
hd=(sin(pi*m)-sin(wc*m))./(pi*m);
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
figure(3);
i=-(N-1)/2:1:(N-1)/2;
stem(i,hn); grid on;
title('FILTER COEFFICIENTS');
xlabel('n');
ylabel('hn');
figure(4);
plot(w/pi,abs(h));
hold on;
wb=blackman(N);
hn=hd.*wb';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');
grid on;
ylabel('magnitude');
xlabel('normalised frequency');
hold off;
title('FIR HPF using windowing technique');
FILTER COEFFICIENTS
0.5

0.4

0.3

0.2
hn

0.1

-0.1

-0.2
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
FIR LPF using windowing technique
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
FIR HPF using windowing technique
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
FILTER COEFFICIENTS
0.5

0.4

0.3

0.2

0.1
hn

-0.1

-0.2

-0.3

-0.4
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
Design of FIR BPF and BSF using filters Using Hamming Windowing Technique

%FIR BPF using rectangular and hamming window


clear all;
wc1=.25*pi;
wc2=.75*pi;
N=11;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
m=(n-alpha+eps);
hd=(sin(wc2*m)-sin(wc1*m))./(pi*m);
wr=boxcar(N);
hn=hd.*wr';
disp(hn);
w=0:.01:pi;
h=freqz(hn,1,w);
figure(1);
i=-(N-1)/2:1:(N-1)/2;
stem(i,hn);
title('FIR BPF FILTER COEFFICIENTS');
xlabel('normalised frequency ');
ylabel('hn');
grid on;
figure(2);
plot(w/pi,abs(h),'red');
hold on;
wn=hamming(N);
hn=hd.*wn';
disp(hn);
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'blue');
grid on;
xlabel('normalised frequency');
ylabel('magnitude');
hold off;
title('FIR BPF using rectangular and hamming window');
%FIR BSF using rectangular and blackman window
clear all;
wc1=.25*pi;
wc2=.75*pi;
N=11;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
m=(n-alpha+eps);
hd=(sin(wc1*m)-sin(wc2*m)+sin(pi*m))./(pi*m);
wr=boxcar(N);
hn=hd.*wr';
disp(hn);
w=0:.01:pi;
h=freqz(hn,1,w);
figure(3);
i=-(N-1)/2:1:(N-1)/2;
stem(i,hn);
title('FIR BSF FILTER COEFFICIENTS');
xlabel('normalised frequency');
ylabel('hn');
grid on;
figure(4);
plot(w/pi,abs(h),'green');
hold on;
wb=blackman(N);
hn=hd.*wb';
disp(hn);
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'blue');
grid on;
xlabel('normalised frequency');
ylabel('magnitude');
hold off;
title('FIR BSF using rectangular and blackman window');
%kaiser window for different values alpha:
clear all;
wc=.5*pi;
N=25;
b=fir1(N,wc/pi,kaiser(N+1,.5));
w=0:.01:pi;
h=freqz(b,1,w);
figure(5);
plot(w/pi,20*log10(abs(h)),'red');
hold on;
b=fir1(N,wc/pi,kaiser(N+1,3.5));
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi,20*log10(abs(h)),'blue');
hold on;
b=fir1(N,wc/pi,kaiser(N+1,8.5));
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi,20*log10(abs(h)),'green');
grid on;
xlabel('normalised frequency')
ylabel('magnitude')
hold off;
title('kaiser window for different values of alpha')
FIR BPF using rectangular and hamming window
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
FIR BPF FILTER COEFFICIENTS
0.5

0.4

0.3

0.2

0.1
hn

-0.1

-0.2

-0.3

-0.4
-5 -4 -3 -2 -1 0 1 2 3 4 5
normalised frequency
FIR BSF FILTER COEFFICIENTS
0.6

0.5

0.4

0.3
hn

0.2

0.1

-0.1
-5 -4 -3 -2 -1 0 1 2 3 4 5
normalised frequency
FIR BSF using rectangular and blackman window
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
kaiser window for different values of alpha
20

-20

-40
magnitude

-60

-80

-100

-120

-140
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

You might also like