Title | DSP Lab Manual 2020-21 |
---|---|
Author | Natthu Prasad |
Course | Digital Signal Processing |
Institution | Visvesvaraya Technological University |
Pages | 43 |
File Size | 2.3 MB |
File Type | |
Total Downloads | 116 |
Total Views | 157 |
laboratory manual for students fhbjdnkml,;/kjbjkl;dkfvjb bnk nm bn...
18ECL57
Digital Signal Processing Lab
DIGITAL SIGNAL PROCESSING LAB B.E., V Semester, Electronics & Communication Engineering
As per the Choice Based Credit System (CBCS) 2018 Scheme
Course Code
18ECL57
CIE Marks
40
No. of hours per week Exam duration
2T + 2L = 4 hours 3 hours
SEE Marks Credits
60 02
Course Objectives This course will enable the students to:
Simulate discrete time signals and verify the sampling theorem. Compute the DFT for a discrete time signal and verify its properties Find solution to the difference equations and compute the convolution and correlation of signals, and verify their properties. Compute and display the filtering operations and compare with the theoretical values. Implement the DSP computations on hardware and verify the results
Laboratory Experiments The following experiments are to be done using MATLAB / SCILAB / OCTAVE or equivalent software 1. Verification of sampling theorem. 2. Linear and circular convolution of two given sequences, commutative, distributive and associative property of convolution. 3. Auto and cross correlation of two sequences and verification of their properties. 4. Solving a given difference equation. 5. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum (using DFT equation and verify it by built-in routine). 6. (i) Verification of DFT properties (like Linearity and Parseval’s theorem, etc.) (ii) DFT computation of square pulse and Sinc function etc. 7. Design and implementation of FIR filter to meet given specifications (using different window techniques). 8. Design and implementation of IIR filter to meet given specifications.
Dept. of ECE, MITK
Page 1
18ECL57
Digital Signal Processing Lab
The following Experiments to be done using DSP kit 9. Linear convolution of two sequences 10. Circular convolution of two sequences 11. N-point DFT of a given sequence 12. Impulse response of first order and second order system 13. Generation of Sine wave and standard test signals Course Outcomes On the completion of this laboratory course, the students will be able to:
Conduct the experiments on Sampling Theorem, DFT and interpret the data. Verify the properties of discrete time signals and systems. Verify the result of discrete computations and generate the standard test signals using DSP processor. Realize the digital filters using a simulation tool and analyze the response of the filter for an audio signal.
Conduct of Practical Examination For becoming eligible to appear for SEE, a student has to score a minimum of 50% marks in CIE, i.e., 20 out of 40. All laboratory experiments are to be included for practical examination. Students will be allowed to pick one experiment from the lot. Strictly follow the instructions as printed on the cover page of answer script for breakup of marks.
Change of experiment is allowed only once and the marks allotted to the procedure part to be made zero For passing the practical course, a student has to score a minimum of 40% marks out of the maximum prescribed marks in SEE.
Dept. of ECE, MITK
Page 2
18ECL57
Digital Signal Processing Lab
TABLE OF CONTENTS EXP. NO.
TITLE OF THE EXPERIMENT
PAGE NO.
Programs using MATLAB *
Familiarization with MATLAB
4
1
Sampling Theorem
8
2 3
Linear and Circular Convolutions Auto and Cross Correlations
10 14
4 5
Solving Difference Equation N-point DFT & its Properties
17 20
6
FIR Filter Design
22
7
IIR Filter Design
30 Simulation Programs using DSP kit
* 1
Procedure for the execution of programs using DSP Kit Linear Convolution
34 35
2 3
Circular Convolution N-point DFT
36 38
4 5
Impulse Response Generation of Sine wave and standard test signals
39 40
Content Beyond the syllabus
43
Reference Books: 1. 2. 3.
Digital Signal Processing using MATLAB, Sanjeet Mitra, TMH, 2001 Digital Signal Processing using MATLAB, J. G. Proakis & Ingle, MGH, 2000 Digital Signal Processors, B. Venkataramani and Bhaskar, TMH, 2002
Dept. of ECE, MITK
Page 3
18ECL57
Digital Signal Processing Lab
PROGRAMS USING MATLAB FAMILIARIZATION WITH MATLAB AIM: To familiarize with MATLAB software, general functions and signal processing toolbox functions. The name MATLAB stands for MATrix LABoratory produced by Mathworks Inc., USA. It is a matrix-based powerful software package for scientific and engineering computation and visualization. Complex numerical problems can be solved in a fraction of the time that required with other high level languages. It provides an interactive environment with hundreds of built -in –functions for technical computation, graphics and animation. In addition to built-in-functions, user can create his own functions. MATLAB offers several optional toolboxes, such as signal processing, control systems, neural networks etc.It is command driven software and has online help facility. MATLAB has three basic windows normally; command window, graphics window and edit window. Command window is characterized by the prompt ‘>>’. All commands and the ready to run program filename can be typed here. Graphic window gives the display of the figures as the result of the program. Edit window is to create program files with an extension .m. Some important commands in MATLAB and its Function Command Function help List topics on which help is available help command name Provides help on the topic selected demo Runs the demo program who Lists variables currently in the workspace whos Lists variables currently in the workspace with their size clear Clears the workspace, all the variables are removed clear x,y,z Clears only variables x,y,z quit Quits MATLAB SL.NO. 1
3
FUNCTION/COMMAND a=[values followed by space] t = 0:2:20 (Initial Value: step size: Final Value) t =1:10
4
k =2:-0.5:-1
5
b = a + 2
6 7
c = a + b Polynomial: It is represented
2
Dept. of ECE, MITK
OPERATION Creating a vector Creating a vector evenly spaced by 2
Displaying value of ‘t’ from 1 to 10 Displaying the value of ‘k’ from 2 to 1 in steps of 0.5 Add 2 to each of the elements in vector 'a' Adding two vectors Write coefficient in descending order
Page 4
18ECL57
Digital Signal Processing Lab
9 10 11 12 13 14
by a vector polyval: Syntax is z=(polyval([. . . .],2) roots([. . . .]) y=polyder(a) X=sqrt(value) T=poly(value) z = conv(x,y) [xx, R] = deconv(z,y)
15
A=[1 2 3;4 5 6;7 8 9]
16 17 18 19
B=A’ C=A*B D=B*A E=A+B
20
F=A-B
21
G=A/B
22
H=A./B
23
I=A\B
24
J=A.\B
25 26
K=A.*B L=A^2
27 28 29 30 31
M=A.^2 N=inv(A) O=eig(A) N1=det(A) N2=rank(A)
32
P=poly(A)
33 34 35 36 37 38 39 40
Q=roots(P) S=A (2,:) A1=A(6) A2=A(3,2) A3=exp(3) A4=A(:,2) A5=[A;B] [r,c] = size(A) A+B==B+A, (A+B)+C==A+(B+C), A*(B+C)==(A*B)+(A*C) zeros(M,N), x = zeros(1,3);i.e x =0 0 0 ones(M,N), x = ones(1,3); i.e x =111
8
41 42 43 44
rand(M,N), x = rand(1,3), x = 0.9501 0.2311 0.6068
Dept. of ECE, MITK
inside the square bracket. It finds the value of polynomial at 2 Extracting the roots of a polynomial Taking derivative of a polynomial finds square root finds polynomial of a ch.eqn Multiplying two polynomials Dividing two polynomials Creating Matrix of 3*3 matrix followed by semicolon after 3 elements Taking transpose of matrix A Multiplying two matrices Checking for A*B=B*A Adding two matrices Subtracting two matrices Dividing matrix A by B(A*inverse of B)(right division) Element by element division(right division) Dividing matrix B by A(inverse of A * B) (left division) Element by element division (left division) Element by element multiplication Taking power of a matrix Element by element taking powers Taking inverse of a matrix A Taking eigen values of matrix A Gives determinant of matrix A Gives rank of matrix A Writing characteristic equation of matrix A Finding the roots of ch.eqn ‘J’ Extracting 2nd row of matrix A Extracting 6th element of matrix A Extracting 3rd row,2nd column element Finding exponential of 3 Extracting 2nd column of matrix A Concatenating the matrices A and B Return dimensions of matrix A Verifying Commutative law, Associative law and Distributive law MxN matrix of zeros MxN matrix of ones MxN matrix of uniformly distributed random numbers on (0,1)
Page 5
18ECL57 45
Digital Signal Processing Lab Creating Identity matrix of order 3*3 Plotting sine waveform from 0 to 7 in steps of 0.25
47 48
R = eye (3, 3) or eye(3) t=0:0.25:7;y = sin(t);plot(t,y) ‘plot’ for continuous function ‘stem’ for discrete function subplot(3,3,2) c2d(value)
49 50
residue(function) ss2tf
51
ss2zp
Converts T.F to the P.F Converts CT state space eqns to T.F Converts CT state space eqns to pole zero gain function Creates a vector with some elements linearly spaced between initial and final numbers Absolute value of ‘x’ Angle of ‘x’ Root locus plot Bode plot Nyquist plot It adds text at the top of the current axis. It adds text beside the x-axis on the current axis.
46
53 54 55 56 57
linspace Ex:linspace(initial,final,no,of elements) abs(x) angle(x) rlocus(x) bode(x) nyquist(x)
58
title(‘text’)
59
xlabel(‘text’)
60
ylabel(‘text’)
61
freqz(b,a,N) Syntax is [h,w] = freqz(b,a,N)
52
3rd row,3rd column,2 nd figure Converts continuous to discrete
It adds text beside the y-axis on the current axis. Returns the N-point frequency vector w in radians and the N-point complex frequency response vector h of the filter b/a.
SINE WAVE disp('sine signal'); N=10; n=0:0.1:N; x=sin(n); plot(n,x); xlabel('time'); ylabel('amplitude'); title('sine wave'); grid;
COSINE WAVE disp('cosine signal'); N=10; n=0:0.1:N; x=cos(n); plot(n,x); xlabel('time'); ylabel('amplitude'); title('cosine wave'); grid;
SQUARE WAVE disp('square signal'); N=10; n=0:0.1:N; x=square(n); plot(n,x); xlabel('time'); ylabel('amplitude'); title('square wave'); grid;
UNIT STEP SIGNAL N=10; n=-N:1:N; x=[zeros(1,N) 1 ones(1,N)]; plot(n,x); xlabel('time'); ylabel('amplitude'); title('step signal'); grid;
RAMP RESPONSE N=10; a=2; n=-N:1:N; x=a*n; plot(n,x); xlabel('time'); ylabel('amplitude'); title('ramp signal'); grid;
TRIANGULAR WAVE N=10; t=0:N; y=(-1).^t; plot(t,y); ylabel ('Amplitude'); xlabel ('Time '); title ('Triangular wave'); grid;
UNIT IMPULSE SIGNAL N=10; n=-N:1:N; x=[zeros(1,N) 1 zeros(1,N)]; plot(n,x); xlabel('time'); ylabel('amplitude'); title('impulse signal'); grid;
SAWTOOTH WAVE disp('sawtooth signal'); N=50; n=0:0.1:N; x=sawtooth(n); plot(n,x); xlabel('time'); ylabel('amplitude'); title('sawtooth wave'); grid;
Dept. of ECE, MITK
Page 6
18ECL57
Digital Signal Processing Lab
EXPONENTIAL SIGNAL disp(‘exponential signal’); t=-1:0.1:1; x=exp(2*t); plot(t,x); xlabel(‘time’); ylabel(‘amplitude’); title(‘exp signal); grid;
EXPONENTIAL GROWING SIGNAL N=10; a=0.5; n=0:0.1:N; x=a.^-n; plot(n,x); xlabel('time'); ylabel('amplitude'); title('exp growing signal'); grid;
EXPONENTIAL DECAYING N=10; a=0.5; n=0:0.1:N; x=a.^n; plot(n,x); xlabel('time'); ylabel('amplitude'); title('exp decaying signal'); grid;
SINC WAVE disp('sine signal'); N=10; n=-N:0.1:N; x=sinc(n); plot(n,x); xlabel('time'); ylabel('amplitude'); title('sine wave'); grid;
0 10 time sawtooth wave
1 0 -1 0
50 time exp decaying signal 1 0.5 0 0 5 10 time
amplitude
20 0 -20 -10
Amplitude
amplitude
5 10 time ramp signal
square wave 1 0 -1
1 0 -1
amplitude
0 10 time exp growing signal 2000 1000 0 0 5 10 time
cosine wave 1 0 -1 0
amplitude
0 10 time impulse signal
amplitude
1 0.5 0 -10
5 10 time step signal
amplitude
1 0.5 0 -10
amplitude
amplitude
0
amplitude
sine wave 1 0 -1
amplitude
amplitude
WAVEFORMS:
0
5 10 time Triangular wave
0
10 5 0 -1
1 0 -1 -10
5 10 Time exp signal
0 time sine wave
1
0 time
10
Exercise Write a MATLAB program for common Discrete Time signals
Dept. of ECE, MITK
Page 7
18ECL57
Digital Signal Processing Lab
Exp. No. 1
SAMPLING THEOREM AIM: Write a MATLAB program to generate a 50 Hz sinusoidal signal of duration 0.1s. Sample it at the given sampling frequency, and then reconstruct the original signal from the samples. Choose fs = 75 Hz, fs = 200 Hz, fs = 400 Hz MATLAB CODE: clc; %clear command window. close all; %close all existing figures. clear all; %clear workspace. t=0:0.001:0.1; F=50; %Frequency of Analog Signal. x=sin(2*pi*F*t); %Original signal subplot(3,1,1); plot(t,x); %Plot the Sinusoidal. title('Analog Signal'); Fs=200; %Sampling frequency. n=0:1/Fs:0.1; xn=sin(2*pi*F*n); %Sampled signal subplot(3,1,2); stem(n,xn); %Plot sampled version of Analog Sinusoidal. title('Sampled Signal'); ni=0:0.001:0.1; xni=interp1(n,xn,ni,'spline'); %Interpolates xn to reconstruct x subplot(3,1,3) %using spline interpolation stem(n,xn); %Discrete signal. hold on ; %use same graph to plot the next graph plot(ni,xni,'r'); %Reconstructed signal. legend('Discrete','Reconstructed'); title('Reconstructed Signal');
Dept. of ECE, MITK
Page 8
18ECL57
Digital Signal Processing Lab
Under-sampling at fs = 75 Hz, resulting in aliasing
Over-sampling at fs = 400 Hz
Exercise: 1. Write a MATLAB program to generate 200 Hz sinusoidal signal of 0.05s duration. Reconstruct the original signal by sampling at 1KHz.
Dept. of ECE, MITK
Page 9
18ECL57
Digital Signal Processing Lab
Exp. No. 2
LINEAR AND CIRCULAR CONVOLUTIONS
A) LINEAR CONVOLUTION AIM: To write MATLAB code to perform Linear Convolution of given sequences, and verify its properties. clear all; close all; clc; a=input('Enter the first sequence a= '); b=input('Enter the second sequence b= '); c=input('Enter the third sequence c= '); x=conv(a,b); disp('Convolution output of a & b = ') disp(x); n=0:length(a)-1; subplot(3,1,1); stem(n,a); title('First sequence'); n=0:length(b)-1; subplot(3,1,2); stem(n,b); title('Second sequence'); n=0:length(x)-1; subplot(3,1,3); stem(n,x); title('Convoluted sequence'); %To verify the commutative property y=conv(b,a); if(x==y) disp('Commutative property is verified'); end %To verify associative property x=conv(conv(a,b),c); y=conv(a,conv(b,c)); if(x==y) disp('Associative property is verified'); end %To verify distributive property x=conv(a,(b+c)); y=conv(a,b)+conv(a,c); if(x==y)
Dept. of ECE, MITK
Page 10
18ECL57
Digital Signal Processing Lab
disp('Distributive property is verified'); end
INPUT: Enter the first sequence a= [1 2 3 4] Enter the second sequence b= [4 3 2 1] Enter the third sequence c= [5 6 7 8]
OUTPUT: Convolution output of a & b = 4 11 20 30 20
11
4
Commutative property is verified Associative property is verified Distributive property is verified
Dept. of ECE, MITK
Page 11
18ECL57
Digital Signal Processing Lab
B) CIRCULAR CONVOLUTION AIM: To write MATLAB code to perform Circular Convolution given sequences, and verify its properties. MATLAB CODE: clc; clear all; close all; a=input('Enter the first sequence: a= '); b=input('Enter the second sequence: b= '); c=input('Enter the third sequence: c= '); n1=length(a); n2=length(b); n3=length(c); N1=max(n1,n2); N=max(N1,n3); a=[a,zeros(1,N-n1)]; b=[b,zeros(1,N-n2)]; c=[c,zeros(1,N-n3)]; subplot(3,1,1); stem(0:N-1,a); title('First sequence'); subplot(3,1,2); stem(0:N-1,b); title('Second sequence'); x=cconv(a,b,N); subplot(3,1,3); stem(0:N-1,x); title('Circular convolution of a&b'); disp('Circular convolution of a&b = '); disp(x); %To verify commutative property y=cconv(b,a,N); if(x==y) disp('Commutative property is verified'); end %To verify associative property x=cconv(cconv(a,b,N),c,N); y=cconv(a,cconv(b,c,N),N); if(x==y) disp('Associative property is verified'); end %To verify distributive property x=cconv(a,(b+c),N); y=cconv(a,b,N)+cconv(a,c,N); if(x==y) disp('Distributive property is verified'); end
Dept. of ECE, MITK
Page 12
18ECL57
Digital Signal Processing Lab
INPUT: Enter the first sequence: a= [1 2 3 4] Enter the second sequence: b= [1 2 3 4 5 6] Enter the third sequence: c= [1 2 3 4 5 6 7 8]
OUTPUT: Circular convolution of a&b = 25.0000 4.0000 10.0000 20.0000 38.0000
30.0000
40.0000
43.0000
Commutative property is verified Associative property is verified Distributive property is verified
Exercises: 1. Write program to perform linear convolution without using the CONV command 2. Write program to perform circular convolution without using the CCONV command 3. Perform linear convolution using CCONV command
Dept. of ECE, MITK
Page 13
18ECL57
Digital Signal Processing Lab
Exp. No. 3
AUTO AND CROSS CORRELATIONS A) AUTO CORRELATION AIM: To write the MATLAB code to perform Autocorrelation on a given signal and to verify its properties. MATLAB CODE: clc; clear all; close all; x=input('Enter the sequence: x= '); n=0:length(x)-1; subplot(2,1,1); stem(n,x); title('Input sequence'); [rxx,nxx]=xcorr(x); subplot(2,1,2); stem(nxx,rxx); title('Auto correlation'); disp('Auto correlation of x is: '); disp(rxx); %To verify symmetry/even property if rxx==fliplr(rxx) disp('Symmetry or Even property is verified'); end %To verify energy property %To verify that center value of rxx is equal to energy of the signal E=sum(x.^2); c=ceil(length(rxx)/2); if E==rxx(c) disp('Energy property is verified'); end
INPUT: Enter the sequence: x= [1 3 2 4]
OUTPUT: Auto correlation of x is: 4.0000 14.0000 17.0000
30.0000
17.0000
14.0000
4.0000
Symmetry or Even property is verified Energy property is verified
Dept. of ECE, MITK
Page 14
18ECL57
Digital Signal Processing Lab
B) CROSS CORRELATION AIM: To write the MATLAB code to perform cross-correlation of the given two signal...