Professional Documents
Culture Documents
Eee472 DSP Lab Manual
Eee472 DSP Lab Manual
Lab-1
Introduction
Digital signal processing is concerned with the processing of a discrete-time signal, called the input
signal, to develop another discrete-time signal, called the output signal, with more desirable
properties. In certain applications, it may be necessary to extract some key properties of the original
signal using specific digital signal processing algorithms. It is also possible to investigate the
properties of a discrete-time system by observing the output signals for specific input signals. It is
thus important to learn first how to generate in the time domain same basic discrete-time signals in
MATLAB and perform elementary operations on them, which are the main objectives of this first
exercise. A secondary objective is to learn the application of some basic MATLAB commands and
how to apply them in simple digital signal processing problems
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n,u);
xlabel(Time index n);ylabel(Amplitude);
title(Unit Sample Sequence);
axis([-10 20 0 1.2]);
Questions:
Q1.1 Run Program P1 1 to generate the unit sample sequence u[n] and display it.
Q1.2 What are the purposes of the commands clf, axis, title, xlabel, and ylabel?
Q1.3 Modify Program P1 1 to generate a delayed unit sample sequence ud[n] with a
delay of 11 samples. Run the modified program and display the sequence generated.
Q1.4 Modify Program P1 1 to generate a unit step sequence s[n]. Run the modified
program and display the sequence generated.
Questions:
Q1.11 Run Program P1 3 and generate the real-valued exponential sequence.
Q1.12 Which parameter controls the rate of growth or decay of this sequence? Which
Parameter controls the amplitude of this sequence?
Q1.13 What is the difference between the arithmetic operators ^ and .^?
LAB-2
Discrete Time Fourier Analysis
Matlabs function fft is used l for computing the Discrete Fourier Transform of a signal.
The following code examples will help you to understand the details of using the fft function.
8 point DFT of the sequence x(n) =(1,1,1,1,0,0,0,0] can be computed as follows
x=[1 1 1 1 0 0 0 0];
fft(x); or fft(x, 8);
Exercise 2.1: The typical syntax for computing the FFT of a signal is fft(x, N) where x is the signal,
x[n], you wish to transform, and N is the number of points in the FFT. N must be at least as large as
the number of samples in x[n]. To demonstrate the effect of changing the value of N,
% P_2.1 DFT to demonstrate the effect of changing the value of N
% synthesizes a cosine wave with 30 samples at 10 samples per period.
n = [0:29];
x = cos(2*pi*n/10);
% define N
N1= 64;
% finds the fft of x
X1=fft(x,N1);
X1abs=abs(X1);
%The frequency scale begins at 0 and extends to N - 1 for an N-point FFT.
F1 = [0 : N1 - 1]/N1;
subplot(3,1,1)
plot(F1,X1,'-x'),title('N = 64'),axis([0 1 0 20])
Questions:
2.1. Run the program and observe the plot
2.2 Modify the program with N= 128 and N=256 , then observe the effect of
changing N
Exercise 2_2: In the above example the length of x[n] was limited to 3 periods in length.
Now, let's choose a large value for N (for a transform with many points), and vary the number of
repetitions of the fundamental period.
n = [0:29];
x1 = cos(2*pi*n/10); % 3 periods
x2 = [x1 x1]; % 6 periods
N = 2048;
X1 = abs(fft(x1,N));
X2 = abs(fft(x2,N));
F = [0:N-1]/N;
subplot(3,1,1)
plot(F,X1),title('3 periods'),axis([0 1 0 50])
subplot(3,1,2)
plot(F,X2),title('6 periods'),axis([0 1 0 50])
Questions:
2.1. Run the program and observe the plot
2.2 Modify the program with 9 periods, then observe plot
LAB -3
Digital Filters
y = filter(num,den,x) generates an output vector y of the same length as the
Specified input vector x with zero initial conditions, that is, y[-1] y[-2] = ... =
y[-N] = 0.
Exercise 3.1
% Program P3_1
% Simulation of an M-point Moving Average Filter
% Generate the input signal
n = 0:100;
s1 = cos(2*pi*0.05*n); % A low frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input(Desired length of the filter = );
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel(Time index n); ylabel(Amplitude);
title(Signal # 1);
subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel(Time index n); ylabel(Amplitude);
title(Signal # 2);
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel(Time index n); ylabel(Amplitude);
title(Input Signal);
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel(Time index n); ylabel(Amplitude);
title(Output Signal);
axis;
Questions:
Q3.1 Run the above program forM = 2to generate the output signal with x[n] = s1[n]
+ s2[n] as the inpu
Q3.1 Run Program P2 1 for other values of filter length M, and various values of the
frequencies of the sinusoidal signals s1[n] and s2[n]. Comment on your results.t.
LAB-4
Circular Convolution
Aim : To write a MATLAB program to obtain the circular convolution of two sequences
Theory: A convolution operation that contain a circular shift is called the circular
convolution . Circular convolution of two sequences x2 (n) and x2 (n) each having a length of
N is givenby
N 1
The circular convolution is also an N- Point sequence. If the length of the sequence are not equal,
sufficient number of zeros must be padded to it
Algorithm
1. Get the length of the input sequence
1. If the length of the sequence is not equal add zeros
2. Calculate the circular convolution
Example
cconv([3 2 1],[1 2 3 2 1],5)
where the number '5' as input indicates N=5 point circular convolution. So the number of outputs will
be 5
Let see how to achieve the result.
For circular convolution flip h=[3 2 1] as h'= 1 2 3 and find the sum of products as shown below
Step 1:
12321
0 0 1 2 3 ( need to add two zeros since N=5 and size of h is only 3.
________
1x0+2x0+3x1+2x2+1x3 = 3 + 4+3 = 10
Step 3:
12321
12300
_________
1+4+9+0+0 = 14
Step4:
12321
23001
________
2+6+0+0+1=9
Step 5:
12321
30012
__________
3+0+0+2+2=7
So the output is
[ 7 9 14 14 10]
Exercise
For the input given below verify the results for progam 1 & program 2. Also verify the
same with your own calculation
Inputs
1.
X1= [ 1 1 2]
X2=[ 1 2 3 4]
N=4
2.
X1=[ 3 2 1]
X2=[1 2 3 2 1]
N=5