Sei sulla pagina 1di 90

www.Vidyarthiplus.

com

PA R I VA K K A M , P O O N A M A L L E E , C H E N N A I - 5 6
CHENNAI 600 056

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

LAB CODE/NAME: EC2306 / DIGITAL SIGNAL PROCESSING LAB

NAME

REG NO

YEAR /SEM :

Third Year / Fifth Semester

www.Vidyarthiplus.com

www.Vidyarthiplus.com

SRINIVASA INSTITUTE OF ENGINEERING & TECHNOLOGY


PA R I VA K K A M , P O O N A M A L L E E , C H E N N A I - 5 6

REGISTER NUMBER:

BONAFIDE CERTIFICATE

Certified that this is a bonafide record of the work done by


--------------------------------------------------------------------------------

Third Year (Fifth Semester) of

Electronics and Communication Engineering Department in the DIGITAL


SIGNAL PROCESSING LABARTORY (EC2306) during academic year
2013- 2014.

Signature of the Staff

Signature of HOD

Submitted for the Practical Examination held on ---------------------------------------

Internal Examiner

External Examiner

www.Vidyarthiplus.com

www.Vidyarthiplus.com

INDEX
S.No

Date

Name Of The Experiment


USING MATLAB

1.

Study of Matlab functions

2.

Generation of signals

3.

Linear and circular convolution

4.

Sampling and effect of aliasing

5.

Design of FIR filter using hamming window

6.

Design of FIR filter using hanning window

7.

Design of FIR filter using blackmann window

8.

Design of butterworth IIR filter

9.

Design of chebyshev IIR filter

10.

Calculation of FFT and IFFT of a signal

11.

Decimation by polyphase decomposition

12.

Computation of DFT and IDFT

13.

Impulse invariant and Bilinear transformation

USING TMS320C5X

www.Vidyarthiplus.com

Page
No

Staff
Sign

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

STUDY OF MATLAB FUNCTIONS

AIM:
To study various MATLAB function.
FUNCTIONS:
clc: Clear the command window.
xlabel: Label for X-axis.
ylabel: Label for Y-axis.
title: Title to the graph.
gird: To display grid lines in graph.
abs (x): This command computes the absolute value of the element of
x,when x is complex abs(x) is the magnitude of the element of x
angle (x): This command computer the phase angle in radians of
vector x.
log10(x): This command computes the logarithm to the base 10 if the
element x.
rem(n,m): This command determines the remainder after dividing n
by N.
log (x): This command determines the remainder natural logarithm of
each element in x.
mod (m,N): This command computes m mod N.
ones (N): Its an N-by-N matrix of ones.
ones (m,n): Its an m-by-n matrix of ones.
zeros (n): Its an n-by-n matrix of zeros .
plot (x,y): Plot vector y versus vector x.
subplot (a,b,c): It breaks the figure window in a-by-b matrix if small
axis selects the Cth axis for the current point.
[b,w] freq z (b,a,N): It returns the N-point freq response vector h and
n-point freq vector w in redians/sample of fig filter described by (b,a)
where a and b are numerator and denominator co-efficient vector.
h = freqz (b,a,w): It returns the freq response at frequencies
designated in vector w in radians/samples.
h = filter (b,a,x): It filters the data in vector x with the filter data y by
the vector a and b to create the filtered data y.
y = conv (x,h): It computes the convolution of two sequence x and h.

www.Vidyarthiplus.com

www.Vidyarthiplus.com

h = impz (b,a,w): It computes N samples of the impules response of


the filter describe b and a.
y = fft (x): It computes the FFT of the vector and stores it in vector Y.
y = fft (x,n): It computes N-point FFT of the vector x by padding the
sequence x with zeros if the sequence length is less than the N-point
truncated if it has more and stores it in vector Y.
ifft (x): It computes the IFFT of the vector x.
ifft (x,N): It computes N-point IFFT of the vector x.
z plane (z,p): Plot the poles and zeros supplied by the column vector
z and p.
z plane (num,den): plots the poles and zeros of the transfer function
represented by the rows in num and dem.
h = impz (num,den,N): It computes the impulse response of the
digital filter transfer function represented by num and dem.
[N,Wn] = buttord (wp,ws,rp,rs): Find the lowest order N of digital
butterworth filter that loses no more than rp db in pass band and has
atleast rs db of attenuation in stop band, wp and ws are the passband
and stopband edge frequencies normalized from 0 to 1.
[B,A] = butter {N,Wn,high}: Design an Nth order high pass digital
butterworth filter.
[N,Wn] = cheb1ord (wp,ws,rp,rs): Finds the lowest order N of the
digital chebyshev type I filter that loses no more than rp db in pass
band and has atleast rs db of attenuation in stop band wp and ws are the
passband and stopband edge frequencies mormalised from 0 to 1.
[N,Wn] = cheb2ord (wp,ws,rp,rs): Finds the lowest order N of the
digital chebyshev type II filter that loses no more than rp db in pass
band and has atleast rs db of attenuation in stop band wp and ws are the
passband and stopband edge frequencies mormalised from 0 to 1.
[B,A] = cheby2 {N,R,Wn}: Design an Nth order low pass digital
chebyshev filter with the stop band ripple R describe down and stop
band edge frequency Wn.
[B,A] = cheby2 {N,R,Wn,high}: Design an Nth order high pass
digital chebyshev filter
[B,A] = cheby2 {N,R,Wn,stop}: Design an Nth order band stop
digital chebyshev filter if [w1 and w2].

www.Vidyarthiplus.com

www.Vidyarthiplus.com

[B,A] = cheby1 {N,R,Wn}: Design an Nth order low pass digital


chebyshev type I filter with R db of ripples in the stopband and R db
of ripple ine pass band, cheby1 returns the filter co-efficient N+1
vector with B (num) and A (den).
[B,A] = cheby1 {N,R,Wn,high}: Design an Nth order high pass
digital chebyshev type I filter.
[numd,dend] = bilinear(num,den,fs): Converts the s domain transfer
function specified by num and den containing numerator and
denominator transfer function coefficient into z domain transfer
function are store in the vetor numd, dend.
W = boxcar (N): Return the N point rectangular window.
W = Bartlett (N): Return the N point bartlett triangular window.
W = hamming (N): Return N point, symmetric hamming window in
coluwn vector.
hann (N): Return N point window symmetric hamming window in
coluwn vector.
hanning (N): Return N point symmetric hamming window in coluwn
vector. In this case the first and cast zero-weighted window samples
are not included.
blackman (N): Return N point symmetric blackman window in
coluwn vector.
B = firl (N,Wn): Design a N order low pass FIR digital filter and
return the filter, the filter coefficient in length N+1 vector B. The
cut-off freq Wn must be between 0 <Wn<10, with 1.0 corresponds to
half the sample rate.
B = firl (N,Wn,high): Design a N order FIR digital high pass filter
B = firl (N,Wn,stop): It is a bandstop filter if wn=[w,wn].
y = decimate (x,m): It resamples the sequence in the vector x at m
times the original sampling rate.

RESULT:
Thus, the MATLAB function used in the program are studied.

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
% program for Unit Step Signal
clc;
t=0:1:10;
y=ones(1,11);
subplot(3,2,1);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit step Signal');
% program for Unit ramp Signal
clc;
t1=0:1:10;
y1=t1;
subplot(3,2,2);
plot(t1,y1,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit Ramp Signal');
% program for Sine wave
clc;
t2=0:0.1:10;
y2=sin(t2);
subplot(3,2,3);
plot(t2,y2,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sine Wave');
% program for Cosine Wave
clc;
t3=0:0.1:10;
y3=cos(t3);
subplot(3,2,4);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

plot(t3,y3,'k');
xlabel('Time');
ylabel('Amplitude');
title('Cosine Wave');
% program for Square wave
clc;
t4=0:0.001:10;
y4=square(t4);
subplot(3,2,5);
plot(t4,y4,'k');
xlabel('Time');
ylabel('Amplitude');
title('Square Wave');
% program for Sawtooth Wave
clc;
t5=0:0.1:10;
y5=sawtooth(t5);
subplot(3,2,6);
plot(t5,y5,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sawtoth Wave');

% program for Unit Step Sequence


clc;
N=input('Enter the length of unit step sequence(N)= ');
n=0:1:N-1;
y=ones(1,N);
subplot(3,2,1);
stem(n,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit step Sequence');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

% program for Unit ramp Sequence


N1=input('Enter the length of the unit ramp sequence(N)= ');
n1=0:1:N1-1;
y1=n1;
subplot(3,2,2);
stem(n1,y1,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit Ramp Sequence');
% program for Sine wave
N2=input('Enter the length of sinosoidal sequence(N)= ');
n2=0:0.1:N2-1;
y2=sin(n2);
subplot(3,2,3);
stem(n2,y2,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sinosoidal Sequence');
% program for Cosine Wave
N3=input('Enter the length of cosine sequence(N)= ');
n3=0:0.1:N3-1;
y3=cos(n3);
subplot(3,2,4);
stem(n3,y3,'k');
xlabel('Time');
ylabel('Amplitude');
title('Cosine Sequence');
% program for exp sequence
N4=input('Enter the length of Exponential sequence(N)= ');
n4=0:1:N4-1;
a=input('Enter the value of Exponential sequence(a)= ');
y4=exp(a*n4);
subplot(3,2,5);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

stem(n4,y4,'k');
xlabel('Time');
ylabel('Amplitude');
title('Exponential Sequence');
% program for Unit Impulse
n5=-3:1:3;
y5=[zeros(1,3),ones(1,1),zeros(1,3)];
subplot(3,2,6);
stem(n5,y5,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit Impulse');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR GENERATION OF CONTINUOUS TIME SIGNAL:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR GENERATION OF DISCRETE TIME SIGNAL:


Enter the length of unit step sequence(N)= 10
Enter the length of the unit ramp sequence(N)= 10
Enter the length of sinosoidal sequence(N)= 10
Enter the length of cosine sequence(N)= 5
Enter the length of Exponential sequence(N)= 5
Enter the value of Exponential sequence(a)= 1

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
% PROGRAM FOR LINEAR CONVOLUTION
%input seq
clc;clear all;close all;
x=input('Enter the input sequence(n)= ');
N1=length(x);
n=0:1:(N1-1);
subplot(3,1,1);
stem(n,x,'k');
xlabel('n----->');
ylabel('Amplitude');
title('input sequence X(n)');
%impulse seq.
h=input('Enter the impulse sequence h(n)= ');
N2=length(h);
n1=0:1:N2-1;
subplot(3,1,2);
stem(n1,h,'k');
xlabel('n--->');
ylabel('Amplitude');
title('impulse sequence h(n)');
%Output conv.
y=conv(x,h);
N=N1+N2-1;
n2=0:1:N-1;
subplot(3,1,3);
stem(n2,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Linear Convolution of two sequence');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

% PROGRAM FOR CIRCULAR CONVOLUTION


clc;
clear all;
close all;
x=input('Enter the impluse sequence x1(n)= ');
N1=length(x);
h=input('Enter the impulse sequence x2(n)= ');
N2=length(h);
n=0:1:N1-1;
subplot(3,1,1);
stem(n,x);
xlabel('n--->');
ylabel('Amplitude');
title('x1(n) Sequence Response');
n=0:1:N2-1;
subplot(3,1,2);
stem(n,h);
xlabel('n--->');
ylabel('Amplitude');
title('x2(n) Sequence Response');
N=max(N1,N2);
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end

www.Vidyarthiplus.com

www.Vidyarthiplus.com

end
disp('Convolution of x1(n) & x2(n) is');
disp(y);
subplot(3,1,3);
stem(y);
xlabel('n--->');
ylabel('Amplitude');
title('Convolution of x1(n)&x2(n) Response');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR LINEAR CONVOLUTION:


Enter the input sequence(n)= [1 2 3 4]
Enter the impulse sequence h(n)= [4 3 2 1]

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR CIRCULAR CONVOLUTION:


Enter the impluse sequence x1(n)= [1 2 3 4 5 6]
Enter the impulse sequence x2(n)= [2 2 3 4]
Convolution of x1(n) & x2(n) is
45 44 37 24 35 46

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%prog for sampling and effect of alliasing
clc;close all; clear all;
% Time period of 50 Hz signal with 0.1s duration at 1000Hz
t=0:0.001:0.1;
fm = 15;
x=sin(2*pi*fm*t);
figure(1)
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Original Analog signal');
%Analog sig sampled at fs<<2fm
fs=10;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(2)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Undersampled fs<<2fm signal');

subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed undersampled fs<<2fm signal');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

%Analog sig sampled at fs=2fm


fs=30;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(3)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Sampled at Nyquist rate fs=2fm signal');

subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed Nyquist rate fs=2fm signal');

%Analog sig sampled at fs>>2fm


fs=500;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(4)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Oversampled fs>>2fm signal');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed oversampled fs>>2fm signal');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR SAMPING AND EFFECT OF ALIASING:


%Original Analog signal

%Undersampled fs<<2fm signal

www.Vidyarthiplus.com

www.Vidyarthiplus.com

%Sampled at Nyquist rate fs=2fm signal

%Oversampled fs>>2fm signal

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%FIR filter using HAMMING window
clc;
clear all;
close all;
wc=.5*pi;
N=input('Enter the length of sequence = ');
alpha=(N-1)/2;
eps=.001;
n=0:1:N-1;
%low pass filter
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wh=hamming(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(1);
plot(w/pi,abs(h),'-');
title('low pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('Low pass filter co-efficient');
disp(hn);
%high pass filter
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=hamming(N);
hn=hd.*wh';
w=0:.01:pi;

www.Vidyarthiplus.com

www.Vidyarthiplus.com

h=freqz(hn,1,w);
figure(2);
plot(w/pi,abs(h),'-');
title('high pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('high pass filter co-efficient');
disp(hn);
%band pass filter
wc1=.25*pi;wc2=.75*pi;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=hamming(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(3);
plot(w/pi,abs(h),'-');
title('Band pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band pass filter co-efficient');
disp(hn);
%band stop filter
hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps))+sin(pi*(nalpha+eps)))./(pi*(n-alpha+eps));
wh=hamming(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(4);
plot(w/pi,abs(h),'-');
title('Band reject filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band reject filter co-efficient');
disp(hn);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR FIR DIGITAL FILTER USING HAMMING WINDOW:


Enter the length of the sequence = 7
Low pass filter co-efficient
-0.0155 0.0001 0.2720 0.5000

0.2714 -0.0001 -0.0155

high pass filter co-efficient


0.0156 -0.0004 -0.2711

0.5000 -0.2723

0.0004

0.0155

band pass filter co-efficient


-0.0000 -0.1592 0.0006

0.5000 -0.0006 -0.1591

0.0000

band reject filter co-efficient


0.0001 0.1590 0.0003 0.5000 -0.0002

0.1593 -0.0001

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%FIR filter using HANNING window
clc;
clear all;
close all;
wc=.5*pi;
N=input('Enter the length of sequence = ');
alpha=(N-1)/2;
eps=.001;
n=0:1:N-1;
%low pass filter
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wh=hanning(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(1);
plot(w/pi,abs(h),'-');
title('low pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('Low pass filter co-efficient');
disp(hn);
%high pass filter
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=hanning(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(2);
plot(w/pi,abs(h),'-');
title('high pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('high pass filter co-efficient');
disp(hn);
%band pass filter
wc1=.25*pi;wc2=.75*pi;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=hanning(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(3);
plot(w/pi,abs(h),'-');
title('Band pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band pass filter co-efficient');
disp(hn);
%band stop filter
hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps))+sin(pi*(nalpha+eps)))./(pi*(n-alpha+eps));
wh=hanning(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(4);
plot(w/pi,abs(h),'-');
title('Band reject filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band reject filter co-efficient');
disp(hn);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR FIR DIGITAL FILTER USING HANNING WINDOW:


Enter the length of sequence = 7
Low pass filter co-efficient
-0.0085 0.0001 0.2453 0.5000 0.2449 -0.0001 -0.0085
high pass filter co-efficient
0.0085 -0.0002 -0.2446

0.5000 -0.2456

0.0002

0.0085

band pass filter co-efficient


-0.0000 -0.0987 0.0005

0.5000 -0.0005 -0.0986

0.0000

band reject filter co-efficient


0.0000 0.0986 0.0002

0.5000 -0.0002

0.0988 -0.0000

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%FIR filter using BLACKMAN window
clc;
clear all;
close all;
wc=.5*pi;
N=input('Enter the length of sequence = ');
alpha=(N-1)/2;
eps=.001;
n=0:1:N-1;
%low pass filter
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wh=blackman(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(1);
plot(w/pi,abs(h),'-');
title('low pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('Low pass filter co-efficient');
disp(hn);
%high pass filter
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=blackman(N);
hn=hd.*wh';
w=0:.01:pi;

www.Vidyarthiplus.com

www.Vidyarthiplus.com

h=freqz(hn,1,w);
figure(2);
plot(w/pi,abs(h),'-');
title('high pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('high pass filter co-efficient');
disp(hn);
%band pass filter
wc1=.25*pi;wc2=.75*pi;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(nalpha+eps));
wh=blackman(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);
figure(3);
plot(w/pi,abs(h),'-');
title('Band pass filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band pass filter co-efficient');
disp(hn);
%band stop filter
hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps))+sin(pi*(nalpha+eps)))./(pi*(n-alpha+eps));
wh=blackman(N);
hn=hd.*wh';
w=0:.01:pi;
h=freqz(hn,1,w);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(4);
plot(w/pi,abs(h),'-');
title('Band reject filter');
xlabel('Normalised frequency \omega/\pi');
ylabel('Magnitude');
disp('band reject filter co-efficient');
disp(hn);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR FIR DIGITAL FILTER USING BLACKMANN WINDOW:


Enter the length of sequence = 7
Low pass filter co-efficient
0 0.0000 0.2007 0.5000 0.2003 -0.0000
0
high pass filter co-efficient
0 -0.0001 -0.2001 0.5000 -0.2010

0.0001

band pass filter co-efficient


0 -0.0414 0.0004 0.5000 -0.0004 -0.0414

band reject filter co-efficient


0 0.0413 0.0002 0.5000 -0.0002

0.0414

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%PROGRAM FOR BUTTERWORTH FILTER
clear all;
clc;
close all;
format long
rp=input('Enter the ripple of pass band (rp)= ');
rs=input('Enter the ripple of stop band (rs)= ');
wp=input('Enter the frequency of pass band (fp)= ');
ws=input('Enter the frequency of stop band (fs)= ');
fs=input('Enter the sampling frequency (F)= ');
w1=2*wp/fs;
w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
disp('Filter order');
disp(n);
disp('Cut-off frequency');
disp(wn);

figure(1);
Subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in deciBel');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

xlabel('Normalized frequency in rad/sec');


title('Magnitude Plot (LPF)');
figure(1);
Subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency in rad/sec');
ylabel('Phase Angle in rad');
title('Phase Plot (LPF)');
%HIGH PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(2);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in deciBel');
xlabel('Normalized frequency in rad/sec');
title('Magnitude Plot (HPF)');
figure(2);
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency in rad/sec');
ylabel('Phase Angle in rad');
title('Phase Plot (HPF)');
%BAND PASS FILTER
[n]=buttord(w1,w2,rp,rs);
wn=[w1,w2];

www.Vidyarthiplus.com

www.Vidyarthiplus.com

[b,a]=butter(n,wn,'bandpass');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(3);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in deciBel');
xlabel('Normalized frequency in rad/sec');
title('Magnitude Plot (BPF)');
figure(3);
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency in rad/sec');
ylabel('Phase Angle in rad');
title('Phase Plot (BPF)');
%BAND STOP FILTER
[n]=buttord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=butter(n,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(4);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in deciBel');
xlabel('Normalized frequency in rad/sec');
title('Magnitude Plot (BSF)');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(4);
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalized frequency in rad/sec');
ylabel('Phase Angle in rad');
title('Phase Plot (BSF)');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR BUTTERWORTH IIR DIGITAL FILTER :


Enter the ripple of pass band (rp)= .5
Enter the ripple of stop band (rs)= 50
Enter the frequency of pass band (fp)= 1200
Enter the frequency of stop band (fs)= 2400
Enter the sampling frequency (F)= 10000
Filter order
8
Cut-off frequency
0.273047748609120

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%chebyshev filter
clear all;
clc;
close all;
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;
%LOW PASS FILTER
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
disp('Filter order');
disp(n);
disp('Cut-off frequency');
disp(wn);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db--->');
xlabel('(a)Normalized frequency--->');
title('Low pass filter');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)Normalized frequency--->');
ylabel('Phase in radians--->');
%HIGH PASS FILTER
[n,wn]= cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(2);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db--->');
xlabel('(a)Normalized frequency--->');
title('High pass filter');
figure(2);
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)Normalized frequency--->');
ylabel('Phase in radians--->');
%BAND PASS FILTER
[n]=cheb1ord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rs,wn,'bandpass');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

figure(3);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db--->');
xlabel('(a)Normalized frequency--->');
title('Band pass filter');
figure(3);
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)Normalized frequency--->');
ylabel('Phase in radians--->');
%BAND STOP FILTER
[n]=cheb1ord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.1/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(4);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in db--->');
xlabel('(a)Normalized frequency--->');
title('Bandstop filter');
figure(4);
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)Normalized frequency--->');
ylabel('Phase in radians--->');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR CHEBYSHEV IIR DIGITAL FILTER:


Enter the pass band ripple:0.02
Enter the stop band ripple:.03
Enter the pass band frequency:1200
Enter the stop band frequency:2400
Enter the sampling frequency:8000
Filter order
1
Cut-off frequency
0.300000000000000

www.Vidyarthiplus.com

www.Vidyarthiplus.com

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
% CALCULATION OF FFT AND IFFT
clc;
clear all;
close all;
N=input('Enter the length of sequence(N)= ');
x=input('Enter the input sequence(x)= ');
n=0:1:(N-1);
subplot(2,2,1);
stem(n,x,'k');
xlabel('N--->');
ylabel('Amplitude');
title('Input sequence');
k=0:1:(N-1);
X=fft(x,N);
subplot(2,2,2);
stem(k,abs(X),'k');
xlabel('k--->');
ylabel('Amplitude');
title('Magnitude Plot(FFT)');
subplot(2,2,3);
stem(k,angle(X),'k');
xlabel('k--->');
ylabel('Angle');
title('Phase Plot(FFT)');
n=0:1:(N-1);
x=ifft(X,N);
subplot(2,2,4);

www.Vidyarthiplus.com

www.Vidyarthiplus.com

stem(n,abs(x),'k');
xlabel('n--->');
ylabel('Amplitude');
title('Magnitude Plot');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR FFT AND IFFT:


Enter the length of sequence(N)= 8
Enter the input sequence(x)= [1 2 3 4 5 6 7 8]

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%program for decimation
clc;
close all;
clear all;
N=input('Enter the length of the samples(N)=');
t1=input('Enter the first time period(t1)=');
t2=input('Enter the second time period(t2)=');
D=input('Enter the Down sampling factor(D)=');
n=0:N-1;
X=sin(2*pi*n*t1) + sin(2*pi*n*t2);
Y=decimate(X,D);
subplot(2,1,1);
stem(n,X(1:N),'k');
title('Sample Signal');
xlabel('sample');
ylabel('Amplitude');
d=0:(N/D)-1;
subplot(2,1,2);
stem(d,X(1:N/D),'k');
title('Down sampled signal');
xlabel('Sample');
ylabel('Amplitude');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR DECIMATION BY POLYPHASE DECOMPOSTION:


Enter the length of the samples(N)=100
Enter the first time period(t1)=.03
Enter the second time period(t2)=.04
Enter the Down sampling factor(D)=3

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%program for DFT & IDFT
clc;
x1=input('Enter the input sequence ');
N=length(x1);
n=0:1:N-1;
k=0:1:N-1;
WN=exp(-1i*2*pi/N);
nk=n'*k;
WnNK=WN.^nk;
Xk=x1*WnNK;
Xkmag=abs(Xk);
WNnk=WN.^(-nk);
xn=Xk*WNnk/N;
subplot(3,1,1);
stem(n,x1);
xlabel('time period');
ylabel('Amplitude');
title('input sequence');
subplot(3,1,2);
stem(n,Xkmag);
xlabel('time period');
ylabel('Amplitude');
title('DFT');
subplot(3,1,3);
stem(n,xn);
xlabel('time period');
ylabel('Amplitude');
title('IDFT');

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR DFT & IDFT:


Enter the input sequence [1 1 0 0]

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

PROGRAM:
%Impluse invariant transformation
clc;
close all;
clear all;
b=input('Enter the numerator co-efficient of analog filter = ');
a=input('Enter the denominator co-efficient of analog filter = ');
fs=input('Sampling frequency = ');
[bz,az]=impinvar(b,a,fs);
disp('bz = ');
disp(bz);
disp('az = ');
disp(az);
Hz=tf(bz,az)
%Bilnear transformation transformation

b=input('Enter the numerator co-efficient of analog filter = ');


a=input('Enter the denominator co-efficient of analog filter = ');
fs=input('Sampling frequency = ');
[bz,az]=bilinear(b,a,fs);
disp('bz = ');
disp(bz);
disp('az = ');
disp(az);
Hz=tf(bz,az)

www.Vidyarthiplus.com

www.Vidyarthiplus.com

OUTPUT FOR IMPULSE INVARIANT AND BILINEAR


TRANFORMATION:
Enter the numerator co-efficient of analog filter = [1 2]
Enter the denominator co-efficient of analog filter = [1 5 11 15]
Sampling frequency = 5
bz =
0.0000 0.0290 -0.0195
az =
1.0000 -2.0570

1.4980 -0.3679

Transfer function:
5.551e-018 s^2 + 0.02904 s - 0.01953
-----------------------------------s^3 - 2.057 s^2 + 1.498 s - 0.3679
Enter the numerator co-efficient of analog filter = [ 2 ]
Enter the denominator co-efficient of analog filter = [1 3 2]
Sampling frequency = 1
bz =
0.1667 0.3333 0.1667
az =
1.0000 -0.3333

0.0000

Transfer function:
0.1667 s^2 + 0.3333 s + 0.1667
-----------------------------s^2 - 0.3333 s + 7.401e-017

RESULT:

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

www.Vidyarthiplus.com

Potrebbero piacerti anche