DSP Lab Manual GEC Dahod 1
DSP Lab Manual GEC Dahod 1
of
Electronics & Communication Engineering
Laboratory Manual
Digital Signal Processing
B. E. SEMESTER: VII
(Subject Code: 171003)
Certificate
This is to certify that Mr./Ms........
of Electronics and Communication department, semester. Enrollment
No. has satisfactorily completed his/her laboratory work in the
course .......................... course code ... for the term
ending in ..2013.
Date of Submission
INDEX
Sr.
No.
1
7
8
9
Date
Page
Sign
Marks
10
Experiment No: 1
9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t.
10. stem (t,x) :This instruction will display a figure window as shown
11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent number
of the figure
(2,2,1)
(2,2,3)
(2,2,2)
(2,2,4)
12. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.
13. Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable. Note that disp does not display
empty arrays.
14. xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
15. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
16. Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the centre of the current axes.
17. grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
18. FFT
FFT(X) is the discrete Fast Fourier transform (FFT) of vector X. For matrices, the FFT
operation is applied to each column. For N-D arrays, the FFT operation operates on the first
non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N
points and truncated if it has more.
19. ABS
Absolute value.
ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex
modulus (magnitude) of the elements of X.
20. ANGLE
Phase angle.
ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements.
Dept. of Electronics and Comm. GEC, Dahod |
21. INTERP
Resample data at a higher rate using low-pass interpolation.
Y = INTERP(X,L) re-samples the sequence in vector X at L times the original sample rate. The
resulting re-sampled vector Y is L times longer, LENGTH(Y) = L*LENGTH(X).
22. DECIMATE
Resample data at a lower rate after low-pass filtering.
Y = DECIMATE(X,M) re-samples the sequence in vector X at 1/M times the original
sample rate. The resulting re-sampled vector Y is M times shorter,
i.e., LENGTH(Y) = CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th
order Chebyshev Type I low-pass filter with cut-off frequency .8*(Fs/2)/R, before re-sampling.
Some important commands in MATLAB
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
Experiment No: 2
GENERATION OF ELEMENTARY CONTINUES TIME SIGNALS
Aim : Write a MATLAB program to develop some elementary continues time (CT) signals
a.
b.
c.
d.
e.
f.
g.
Sinusoidal
Square
Complex waveform
Unit Step
Unit Ramp
Exponential
Noise
MATLAB Code :
a. Sinusoidal Waveform
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y =a*sin(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('sine wave')
grid on;
Output:
Enter the value of frequency 2
Enter the value of amplitude 1
10
b. Square Waveform
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y =a*square(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Square wave')
grid on;
Output :
Enter the value of frequency 1
Enter the value of amplitude 1
c.
Complex Waveform
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y = [exp((-0.2+2*i)*t)];
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Complex wave')
grid on;
Dept. of Electronics and Comm. GEC, Dahod |
11
Output :
Enter the value of frequency 2
Enter the value of amplitude 1
12
e.
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
m = input ('Enter the value of slope');
subplot (2,1,1);
y = m*t;
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Ramp wave')
grid on;
Output:
Enter the value of slope 1
f.
Exponential Waveform
clc;
clear all;
close all;
a=0.5;
t=0:0.1:10;
disp('EXPONENTIAL DECAYING SIGNAL');
x=a.^t;
subplot(2,1,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Decaying Signal Response');
grid on;
13
g.
Noise Signal
clc;
clear all;
close all;
t=0:0.001:50;
% generate the uncorrupted signal
s=2*t.*(0.9.^t);
subplot(2,1,1);
plot(t,s);
title('Uncorrupted sequence');
xlabel('Time index');
ylabel('Amplitude');
14
Conclusion:
15
Experiment No: 3
CONCEPT OF HARMONICS
Aim: Write a MATLAB program to find the sum of sinusoidal signals and understand the
concept of harmonics.
MATLAB Code :
clc;
clear all;
close all;
t=0:.01:2*pi;
%generation of sine signals%
y1=sin(t);
y2=sin(3*t)/3;
y3=sin(5*t)/5;
y4=sin(7*t)/7;
y5=sin(9*t)/9;
%y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9; %
y = y1+y2+y3+y4+y5;
plot (t,y,t,y1,t,y2,t,y3,t,y4,t,y5);
legend ('y','y1','y2','y3','y4','y5');
title ('generation of sum of sinusoidal signals');
grid on;
ylabel ('---> Amplitude');
xlabel ('---> t');
Output:
16
Exercise:
1. Plot the synthesized waveform using the summation of even component of the series.
2. Plot the synthesized triangular waveform.
Conclusion:
17
Experiment No: 4
GENERATION OF ELEMENTARY DISCRETE TIME SIGNALS
Aim : Write a MATLAB program to develop some elementary discrete time (DT) signals
a.
b.
c.
d.
e.
f.
g.
Sinusoidal
Square
Complex waveform
Unit Impulse
Unit Step
Unit Ramp
Exponential
MATLAB Code :
a. Sinusoidal DT signal
clc;
clear all;
close all;
N = input('Enter Number of Samples : ');
n = 0:0.1:N;
x = sin(n);
stem (n,x);
xlabel ('Time');
ylabel ('Amplitude');
title ('Discrete Time Sine Signal');
grid on;
Output:
Enter Number of Samples : 15
18
b. Square DT signal
clc;
clear all;
close all;
N = input('Enter the number of Samples:);
n = 0:0.1:N;
s = square(2*n);
stem (n,s);
xlabel ('time');
ylabel ('amplitude');
title ('square wave')
grid on;
Output:
Enter the number of Samples : 10
c. Complex DT signal
clc;
clear all;
close all;
n = 0 : 0.1 : 15;
subplot (2,1,1);
y = [exp((-0.2+2*i)*n)];
stem (n,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Discrete Time Complex wave')
grid on;
19
20
Enter Amplitude : 1
g. Exponential DT signal
clc;
clear all;
close all;
N = input('Enter Number of Samples : ');
% EXPONENTIAL DECAYING SIGNAL
a = 0.5;
n = 0:.1:N;
x = a.^n;
subplot (2,1,1);
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Exponential Decaying Signal Response');
grid on;
%EXPONENTIAL GROWING SIGNAL
subplot (2,1,2);
x = a.^-n;
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Exponential Growing Signal Response');
grid on;
Dept. of Electronics and Comm. GEC, Dahod |
21
22
Experiment No: 5
SAMPLING THEOREM
tf = 0.05;
t = 0 : 0.00005 : tf;
f = input ('Enter the analog frequency,f = : ');
xt = cos (2*pi*f*t);
% Under Sampling Sampling Frequency less than Nyquist rate => fs < 2f
fs1 = 1.3*f;
n1 = 0:1/fs1:tf;
xn = cos(2*pi*f*n1);
subplot (3,1,1);
plot (t,xt,'b',n1,xn,'r*-');
title ('Undersampling plot');
xlabel ('time');
ylabel ('Amplitude');
% Nyquist Sampling Sampling Frequency fs = 2f
fs2 = 2*f;
n2 = 0 : 1/fs2 : tf;
xn = cos(2*pi*f*n2);
subplot (3,1,2);
plot (t,xt,'b',n2,xn,'r*-');
title ('Nyquist plot');
xlabel ('time');
ylabel ('Amplitude');
% Over Sampling Sampling Frequency greater than Nyquist rate => fs > 2f
fs3 = 6*f;
n3 = 0 : 1/fs3 : tf;
xn = cos(2*pi*f*n3);
subplot (3,1,3);
plot (t,xt,'b',n3,xn,'r*-');
title ('Oversampling plot');
xlabel ('time');
ylabel ('Amplitude');
23
Conclusion:
24
Experiment No: 6
IMPULSE RESPONSE OF THE LTI SYSTEM
Aim: Write a MATLAB program to find the impulse response of a LTI system defined by a
difference equation:
y(n) + 0.7y(n-1) 0.45y(n-2) 0.6y(n-3) = 0.8x(n) 0.44x(n-1) + 0.36x(n-2) + 0.2x(n-3)
MATLAB Code:
clc;
clear all;
close all;
N = input ('Enter the required length of impulse response N = ');
n = 0 : N-1;
b = input ('Enter the co-efficients of x(n), b = ');
a = input ('Enter the co=efficients of y(n), a = ');
% Impulse response of the LTI system given by the difference equation
x = [1, zeros(1,N-1)];
y = impz (b,a,N);
subplot (2,1,1);
stem (n,y,r);
xlabel ('time');
ylabel ('amplitude');
title ('IMPULSE RESPONSE');
grid on;
% Pole Zero distribution of the LTI system given by the difference equation
subplot (2,1,2);
zplane (b,a);
xlabel ('Real part');
ylabel ('Imaginary part');
title ('Poles and Zeros of H[z] in Z-plane');
grid on;
25
Output :
Exercise:
Find out the impulse response of the following difference equation and plot the pole-zero
response of the same.
1. 0.25y(n-3) + 0.7y(n-2)+y(n) = 3x(n) 0.9x(n-1) + 1.3x(n-2)
2. y(n) y(n-1) = x(n) x(n-1)
26
Conclusion:
27
Experiment No: 7
FREQUENCY RESPONSE OF THE LTI SYSTEM
Aim: Write a MATLAB program to plot the Frequency response of a given LTI sequence:
y(n) 5 y(n1) = x(n) + 4 x(n1)
MATLAB Code:
b = [1, 4]; %Numerator coefficients
a = [1, -5]; %Denominator coefficients
w = -2*pi: pi/256: 2*pi;
% Frequency Response of the LTI system
[h] = freqz(b, a, w);
subplot(2, 1, 1),
plot(w, abs(h));
xlabel ('Frequency \omega'),
ylabel ('Magnitude');
grid on;
% Phase Response of the LTI system
subplot(2, 1, 2),
plot(w, angle(h));
xlabel('Frequency \omega'),
ylabel('Phase - Radians');
grid on;
Output:
28
Exercise:
Find out the frequency response of the following difference equations.
1. 0.25y(n-3) + 0.7y(n-2)+y(n) = 3x(n) 0.9x(n-1) + 1.3x(n-2)
2. y(n) y(n-1) = x(n) x(n-1)
Conclusion:
29
Experiment No: 8
LINEAR CONVOLUTION
Aim: Write a MATLAB program to compute linear convolution of two given sequences.
MATLAB Code:
a. Linear convolution computation (Program 1)
clear all;
close all;
clc;
x1 = input ('enter the first sequence ');
subplot (2,2,1);
stem (x1,'r');
ylabel ('amplitude');
title ('plot of the first sequence');
grid on;
x2 = input ('enter 2nd sequence ');
subplot (2,2,2);
stem (x2, 'r');
ylabel ('amplitude');
title ('plot of 2nd sequence');
grid on;
f = conv (x1,x2);
disp ('output of linear conv is');
disp (f);
subplot (2,2,3);
stem (f,'r');
xlabel ('time index n');
ylabel ('amplitude f');
title('linear conv of sequence');
grid on;
Output:
enter the first sequence [1 2 3 4]
enter 2nd sequence [2 -1 2 3]
output of linear conv is
2
6 12
8 17 12
30
31
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=a+b:length(y)+a+b-1;
stem(n,y,'r');
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('Convolution x(n)* h(n)');
Output:
Enter the starting point of x[n]=-2
Enter the starting point of h[n]=1
Enter the co-efficients of x[n]=[1 2 3 4 5]
Enter the co-efficients of h[n]=[-1 -2 1 1 2]
-1 -4 -6 -7 -6
1 15 13 10
Exercise: Find out the Convolution of other two series and find the starting point of the result.
32
Conclusion:
33
Experiment No: 9
DISCRETE TIME FOURIER TRANSFORM - DTFT
Aim: Write a MATLAB program to find the Discrete Time Fourier Transform (DTFT) of the
given sequence.
MATLAB Program:
34
Output:
( )
( )
35
Conclusion:
36
Experiment No: 10
FIR FILTER DESIGN
Aim: Write a MATLAB program to plot magnitude response and phase response of digital FIR
Filter using Rectangular window
a. Low pass Filter
b. High pass Filter
c. Bandpass Filter
d. Bandstop Filter
MATLAB Program:
37
38
39
Hanning Window:
1.
2.
3.
4.
h=fir1(N,wc/pi,hanning(N+1));
h=fir1(N,wc/pi, high,hanning(N+1));
h=fir1(N,wc/pi,hanning(N+1));
h=fir1(N,wc/pi, stop, hanning(N+1));
Hamming Window:
1.
2.
3.
4.
h=fir1(N,wc/pi,hamming(N+1));
h=fir1(N,wc/pi, high,hamming(N+1));
h=fir1(N,wc/pi,hamming(N+1));
h=fir1(N,wc/pi, stop, hamming(N+1));
40