You are on page 1of 44

The Laboratory Notebook:

Each student must have their own laboratory notebook. All pre-lab exercises and laboratory reports are to be entered into your notebook. Your notebook must be clearly labelled on the cover with the following information:

Module: Digital Signal Processing Name: Roll No: Class:

Introduction
There are 2 hours allocated to a laboratory session in Digital Signal Processing. It is a necessary part of the course at which attendance is compulsory. Here are some guidelines to help you perform the experiments and to submit the reports: 1. Read all instructions carefully and carry them all out. 2. Ask a demonstrator if you are unsure of anything. 3. Record actual results (comment on them if they are unexpected!) 4. Write up full and suitable conclusions for each experiment. 5. If you have any doubt about the safety of any procedure, contact the demonstrator beforehand. 6. THINK about what you are doing!

LIST OF EXPERIMENTS
1. 2. 3.
To write a program to represent basic signal (unit step, unit impulse, ramp, exponential, Sine sequence, Cosine sequence). To perform the discrete convolution of sequences. To write a program for discrete correlation. (a)Program for computing cross correlation of the sequences (b) Program for computing auto correlation.

4.

To design (a) Program for low pass IIR butterworth filter (b) Program for high pass IIR butterworth filter

5.

To Design a digital filter using rectangular window method. (a) Program for low pass filter (b) Program for high pass filter (c) Program for band pass filter (d) Program for band stop filter

6.

To design (a) Program for low pass filter (b) Program for high pass filter (c) Program for band pass filter

(d) Program for band stop filter

EXPERIMENT NO. 1 AIM:


To write a program to represent basic signal (unit step, unit impulse, ramp,

exponential, Sine sequence, Cosine sequence)

APPARATUS REQUIRED:

MATLAB SOFTWARE, PC

Program: clc; clearall; close all; n=input('enter the N value'); t=0:1:n-1; y1=ones(1,n);subplot(2,2,1); stem(t,y1); ylabel('Amplitude -->'); xlabel('(a) n -->'); title('unit step signal'); t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,2); stem(t,y); ylabel('Amplitude -->'); xlabel('(b)n -->'); title('unit impulse signal'); n1=input('eneter the length of ramp sequence'); t=0:n1; subplot(2,2,3); stem(t,t); ylabel('Amplitude -->');

xlabel('(c)n -->'); title('Unit ramp sequence'); n2=input('enter the length exponential sequence'); t=0:n2; a=input('enter the value of a'); y2=exp(a*t); subplot(2,2,4); stem(t,y2); ylabel('Amplitude -->'); xlabel('(d)n -->'); title('exponential sequence');

Output:enter the N value7 eneter the length of ramp sequence7 enter the length exponential sequence7 enter the value of a1

EXPERIMENT NO. 1 (Figure)

Program to represent basic signal (unit step, unit impulse, ramp, exponential, Sine sequence, Cosine sequence).

Program:n=0:.01:pi; y=sin(2*pi*n); subplot(2,2,1); stem(n,y); xlabel('(a)n'); ylabel('Amplitude -->'); title('Sine Sequence'); n=0:.01:pi; y1=cos(2*pi*n); subplot(2,2,2); stem(n,y1); xlabel('(b)n'); ylabel('Amplitude -->'); title('cosine sequence');

EXPERIMENT NO. 1 (Figure)

Program to represent basic signal (Sine sequence, Cosine sequence)

EXPERIMENT NO. 2

AIM:

To perform the discrete convolution of sequences. MATLAB SOFTWARE, PC

APPARATUS REQUIRED:-

Program for linear convolution of the sequence x and h


clc; clear all; close all; x=input('enter the first sequence'); h=input('enter the second sequence'); y=conv(x,h) figure; subplot(3,1,1); stem(x); ylabel('amplitude '); xlabel ('(a)n'); subplot(3,1,2); stem(h); ylabel('amplitude '); xlabel ('(b)n'); subplot(3,1,3); stem(y); ylabel('amplitude '); xlabel ('(c)n'); disp (The resultant signal is ); y title('convolution');

Output:enter the first sequence [1 2] enter the second sequence [1 2 4] The resultant signal is y=1488

EXPERIMENT NO. 2(Figure)


Program for convolution of two discrete sequences

EXPERIMENT NO. 3

AIM:

To write a program for discrete correlation. MATLAB SOFTWARE, PC

APPARATUS REQUIRED:

(A)Program for computing cross correlation of the sequences


clc; clear all; close all; x=input('enter the first sequence'); h=input('enter the second sequence'); y=xcorr(x,h); figure; subplot(3,1,1); stem(x); xlabel('(a) n -->'); ylabel('Amplitude -->'); title('First Input sequence'); subplot(3,1,2); stem(h); xlabel('(b) n -->'); ylabel('Amplitude -->'); title('Second Input sequence'); subplot(3,1,3); stem(y); xlabel('(c) n -->'); ylabel('Amplitude -->'); title('Output sequence'); disp ('The resultant signal is'); y

Output:enter the first sequence[1 2 3 4] enter the second sequence[4 3 2 1] The resultant signal is y= Columns 1 through 3 1.0000 4.0000 10.0000 Columns 4 through 6 20.0000 25.0000 24.0000 Column 7 16.0000

EXPERIMENT NO. 3(A) (Figure)


( A)Program for computing cross correlation of the sequences

(B)Program for computing auto correlation


clc; clear all; close all; x=input('enter the sequence'); y=xcorr(x,x); figure; subplot(2,1,1); stem(x); xlabel('(a) n -->'); ylabel('Amplitude -->'); subplot(2,1,2); stem(y); xlabel('(b) n -->'); ylabel('Amplitude -->'); disp ('The resultant signal is'); y

Output:enter the sequence[1 2 3 4] The resultant signal is y= Columns 1 through 3 4.0000 11.0000 20.0000 Columns 4 through 6 30.0000 20.0000 11.0000 Column 7 4.0000

EXPERIMENT NO. 3(B) (Figure)


(B)Program for computing auto correlation function

EXPERIMENT NO. 4 AIM: To design IIR butterworth filter.


APPARATUS REQUIRED:
MATLAB SOFTWARE, PC

(A) Program for low pass IIR butterworth filter


clc; close all; clear all; rs=input('enter the stop band ripple '); rp=input('enter the pass band ripple '); ws=input('enter the stop band frequency '); wp=input('enter the pass band freequency '); fs=input('enter the sampling frequency '); w1=2*wp/fs; w2=2*ws/fs; %to find the cutoff frequency and order of the filter [n,wn]=buttord(w1,w2,rp,rs); %system function of the filter [b,a]=butter(n,wn) w=0:0.01:pi; [h,om]=freqz(b,a,w); m=abs(h); an=angle(h);

subplot(2,1,1); plot(om/pi,20*log10(m));grid ylabel('gain in db '); xlabel('(a) normalised frequency '); subplot(2,1,2); plot(om/pi,an);grid ylabel('phase in radian'); xlabel('(b) normalised frequency ');

OUTPUT: enter the stop band ripple 30 enter the pass band ripple 0.40 enter the stop band frequency 800 enter the pass band freequency 400 enter the sampling frequency 2000 b =0.1518 a = 1.0000 0.6073 0.6418 0.9109 0.6165 0.6073 0.1449 0.1518 0.025

EXPERIMENT NO. 4(A) (Figure)


(A) Program for low pass IIR butterworth filter

(B) Program for high pass IIR butterworth filter


clc; close all; clear all; rs=input('enter the stop band ripple '); rp=input('enter the pass band ripple '); ws=input('enter the stop band frequency '); wp=input('enter the pass band freequency '); fs=input('enter the sampling frequency '); w1=2*wp/fs; w2=2*ws/fs; %to find the cutoff frequency and order of the filter [n,wn]=buttord(w1,w2,rp,rs); %system function of the filter [b,a]=butter(n,wn,'high') w=0:0.01:pi; [h,om]=freqz(b,a,w); m=abs(h); an=angle(h); subplot(2,1,1); plot(om/pi,20*log10(m));grid ylabel('gain in db '); xlabel('(a) normalised frequency '); subplot(2,1,2); plot(om/pi,an);grid ylabel('phase in radian'); xlabel('(b) normalised frequency ');

OUTPUT:enter the stop band ripple 30 enter the pass band ripple .4 enter the stop band frequency 800 enter the pass band freequency 400 enter the sampling frequency 2000 b =0.0535 -0.2139 a =1.0000 0.6418 0.3209 -0.2139 0.6165 0.1449 0.0535 0.0259

EXPERIMENT NO. 4(B) (Figure)


(B) Program for high pass IIR butterworth filter

EXPERIMENT NO. 5

AIM: To Design a digital filter using rectangular window method. APPARATUS REQUIRED:
MATLAB SOFTWARE, PC

(A) Program for low pass filter


clc; close all; clear all; wc=0.5*pi;%cut off frequency N=25; alpha=(N-1)/2; eps=0.001;%to avoid indeterminate form n=0:1:N-1; hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps)); wr=boxcar(N);%rectangular window sequence hn=hd.*wr';%filter coefficients w=0:0.01:pi; h=freqz(hn,1,w); %plot magnitude response m=abs(h); subplot(2,1,1); plot(w/pi,m);grid xlabel('normalized frequency'); ylabel('magnitude'); title('magnitude response of low pass filter using rectangular window'); an=angle(h);

subplot(2,1,2); plot(w/pi,an);grid xlabel('normalized frequency'); ylabel('phase shift'); title('phase response of low pass filter using rectangular window');

EXPERIMENT NO. 5(A) (Figure)


(A) Program for low pass filter

(B) Program for high pass filter


clc; close all; clear all; wc=0.5*pi;%cut off frequency N=25; alpha=(N-1)/2; eps=0.001;%to avoid indeterminate form n=0:1:N-1; hd=sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps)); wr=boxcar(N);%rectangular window sequence hn=hd.*wr';%filter coefficients w=0:0.01:pi; h=freqz(hn,1,w); %plot magnitude response m=abs(h); subplot(2,1,1); plot(w/pi,m);grid xlabel('normalized frequency'); ylabel('magnitude'); title('magnitude response of high pass filter using rectangular window'); %plot phase response an=angle(h); subplot(2,1,2); plot(w/pi,an);grid xlabel('normalized frequency'); ylabel('phase shift'); title('phase response of high pass filter using rectangular window');

EXPERIMENT NO. 5(B) (Figure)


(B) program for high pass filter

(C) Program for band pass filter


clc; close all; clear all; wc1=0.25*pi; wc2=0.75*pi; N=25; alpha=(N-1)/2; eps=0.001;%to avoid indeterminate form n=0:1:N-1; hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps)); wr=boxcar(N);%rectangular window sequence hn=hd.*wr';%filter coefficients w=0:0.01:pi; h=freqz(hn,1,w); %plot magnitude response m=abs(h); subplot(2,1,1); plot(w/pi,m);grid xlabel('normalized frequency'); ylabel('magnitude'); title('magnitude response of band pass filter using rectangular window'); %plot phase response an=angle(h); subplot(2,1,2); plot(w/pi,an);grid xlabel('normalized frequency'); ylabel('phase shift'); title('phase response of band pass filter using rectangular window');

EXPERIMENT NO. 5(C) (Figure)


(C) Program for band pass filter

(D) Program for band stop filter


clc; close all; clear all; wc1=0.25*pi; wc2=0.75*pi; N=25; alpha=(N-1)/2; eps=0.001;%to avoid indeterminate form n=0:1:N-1; hd=(sin(pi*(n-alpha+eps))+sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps)))./(pi*(nalpha+eps)); wr=boxcar(N);%rectangular window sequence hn=hd.*wr';%filter coefficients w=0:0.01:pi; h=freqz(hn,1,w); %plot magnitude response m=abs(h); subplot(2,1,1); plot(w/pi,m);grid xlabel('normalized frequency'); ylabel('magnitude'); title('magnitude response of band stop filter using rectangular window'); %plot phase response an=angle(h); subplot(2,1,2); plot(w/pi,an);grid xlabel('normalized frequency'); ylabel('phase shift');

title('phase response of band stop filter using rectangular window');

EXPERIMENT NO. 5(D) (Figure)


(D) Program for band stop filter

EXPERIMENT NO. 6 AIM: To design the program for analog butterworth filter.
APPARATUS REQUIRED:
(A) Program for low pass filter
clc; clear all; close all; rs=input('enter the stopband ripple='); rp=input('enter the passband ripple='); ws=input('enter the stopband frequency='); wp=input('enter the passband frequency='); fs=input('enter the sampling frequency='); w1=2*wp/fs; w2=2*ws/fs; %find the order and cut off frequency [n,wn]=buttord(w1,w2,rs,rp,'s'); %calculating system function [b,a]=butter(n,wn,'s'); %plot frequency response w=0:0.01:pi; [h,w]=freqs(b,a,w); m=20*log10(abs(h)); subplot(2,1,1); plot(w/pi,m);grid MATLAB SOFTWARE, PC

ylabel('Gain in dB--'); xlabel('Normalised Frequency--'); title('Magnitude Response of low pass filter'); an=angle(h); subplot(2,1,2); plot(w/pi,an); grid ylabel('Phase in radians--'); xlabel('Normalised Frequency--'); title('Phase Response of low pass filter');

OUTPUT:enter the stopband ripple=.25 enter the passband ripple=60 enter the stopband frequency=3000 enter the passband frequency=2000 enter the sampling frequency=9000 n =21 wn =0.4798

EXPERIMENT NO. 6(A) (Figure)


(A) Program for low pass filter

(B) Program for high pass filter


clc; clear all; close all; rs=input('enter the stopband ripple='); rp=input('enter the passband ripple='); ws=input('enter the stopband frequency='); wp=input('enter the passband frequency='); fs=input('enter the sampling frequency='); w1=2*wp/fs; w2=2*ws/fs; %find the order and cut off frequency [n,wn]=buttord(w1,w2,rs,rp,'s'); %calculating system function [b,a]=butter(n,wn,'high','s'); %plot frequency response w=0:0.01:pi; [h,w]=freqs(b,a,w); m=20*log10(abs(h)); subplot(2,1,1); plot(w/pi,m);grid ylabel('Gain in dB--'); xlabel('Normalised Frequency--'); title('Magnitude Response of high pass filter'); an=angle(h); subplot(2,1,2); plot(w/pi,an); grid ylabel('Phase in radians--');

xlabel('Normalised Frequency--'); title('Phase Response of high pass filter');

OUTPUT:enter the stopband ripple=.25 enter the passband ripple=60 enter the stopband frequency=3000 enter the passband frequency=2000 enter the sampling frequency=9000 n = 21 wn =0.4798

EXPERIMENT NO. 6(B) (Figure)


(B) Program for high pass filter

(C) Program for band pass filter


clc; clear all; close all; rs=input('enter the stopband ripple='); rp=input('enter the passband ripple='); ws=input('enter the stopband frequency='); wp=input('enter the passband frequency='); fs=input('enter the sampling frequency='); w1=2*wp/fs; w2=2*ws/fs; %find the order and cut off frequency [n]=buttord(w1,w2,rs,rp,'s') wn=[w1,w2] %calculating system function [b,a]=butter(n,wn,'bandpass','s'); %plot frequency response w=0:0.01:pi; [h,w]=freqs(b,a,w); m=20*log10(abs(h)); subplot(2,1,1); plot(w/pi,m);grid ylabel('Gain in dB--'); xlabel('Normalised Frequency--'); title('Magnitude Response of band pass filter'); an=angle(h); subplot(2,1,2); plot(w/pi,an); grid

ylabel('Phase in radians--'); xlabel('Normalised Frequency--'); title('Phase Response of band pass filter');

OUTPUT:enter the stopband ripple=50 enter the passband ripple=60 enter the stopband frequency=70 enter the passband frequency=80 enter the sampling frequency=90 n=9 wn = 1.7778 1.5556

EXPERIMENT NO. 6(C) (Figure)


(C) Program for band pass filter

(D) Program for band stop filter


clc; clear all; close all; rs=input('enter the stopband ripple='); rp=input('enter the passband ripple='); ws=input('enter the stopband frequency='); wp=input('enter the passband frequency='); fs=input('enter the sampling frequency='); w1=2*wp/fs; w2=2*ws/fs; %find the order and cut off frequency [n]=buttord(w1,w2,rs,rp,'s') wn=[w1,w2] %calculating system function [b,a]=butter(n,wn,'stop','s'); %plot frequency response w=0:0.01:pi; [h,w]=freqs(b,a,w); m=20*log10(abs(h)); subplot(2,1,1); plot(w/pi,m);grid ylabel('Gain in dB--') xlabel('Normalised Frequency--') title('Magnitude Response of band stop filter'); an=angle(h); subplot(2,1,2); plot(w/pi,an); grid

ylabel('Phase in radians--') xlabel('Normalised Frequency--') title('Phase Response of band stop filter');

OUTPUT:enter the stopband ripple=50 enter the passband ripple=60 enter the stopband frequency=70 enter the passband frequency=80 enter the sampling frequency=90 n=9 wn = 1.7778 1.5556

EXPERIMENT NO. 6(D) (Figure)


(D) Program for band stop filter

You might also like