2. PREFACE
It is my great pleasure to present interactive Digital Signal Processing (DSP)
Demonstration modules developed using Matlab for Third year Electronics
Engineering students.
DSP deals with the analysis and manipulation of digital signals. The main
difficulty in DSP learning for a novice, is a large no. of mathematical equations that
needs some intuition to appreciate underlying concepts.
Matlab is the best visualization tool, that accentuate the intuitive aspects of
DSP Algorithms. Hence, this manual consists of a ready to use set of
demonstrations, illustrating the DSP concepts, that can be beneficial to the
students .
Students are advised to thoroughly go through this manual rather than only topics
mentioned in the syllabus as practical aspects are the key to understanding and
conceptual visualization of theoretical aspects covered in the books.
Good Luck for your Enjoyable Laboratory Sessions.
Prof. A. P. Phatale.
3. SUBJECT INDEX
Title Page no.
1.Do‛s and Don‛ts in Laboratory
2 .Instruction for Laboratory Teachers:
3. Lab Exercises
1. Introduction to matlab
2. Generation of signal
3. To verify the partial fraction expansion of the z-
transform.
4. To verify impulse response.
5.
6. Design of IIR Filter
7. Illustration of interpolation process.
8. Illustration of decimal process
9. Spectral analysis using DFT.
4. Quiz for the subject
5. Conduction of viva voce examination
6. Evaluation and marking scheme
04
04
05
08
4. 1. DOs and DON‛Ts in Laboratory:
1. Do not handle DSP Starter kit without reading the instructions/Instruction manuals.
2. Refer Matlab Help for debugging the program.
3. Go through Matlab Demos of Signal Processing tool box.
4. Strictly observe the instructions given by the teacher/Lab Instructor.
.
2 Instruction for Laboratory Teachers::
1. Lab work completed during prior session ,should be corrected during the next lab session.
2. Students should be guided and helped whenever they face difficulties.
3. The promptness of submission should be encouraged by way of marking and evaluation patterns that
will benefit the sincere students.
5. 3. Lab Exercises:
Exercise No1: ( 2 Hours) – 1 Practical
Aim: Generation of discrete time signal like
a) sinusoidal
b) step
c) ramp
d) impulse
e) real valued
f) complex valued
g) noise
These are the basic discrete signals used in DSP. Plot all the signals .
Step: 1. Generate Sinusoidal signal
Discrete sinusoidal signal is represented by the equation
x(n) = A Sin ( 2 P f n) for all n
fs
A = peak amplitude
f = signal frequency
fs= sampling frequency
n = n th sample
function[x,n]=sinusoidal(n1,n2)
n=0:100;
x=5*sin(2*0.05*pi*n)+ sin(0.01*pi*n);
stem(n,x);
title ('Sinusoidal sequence');
xlabel ('samples');
ylabel ('magnitude');
Step: 2. Generate Step signal
Discrete step signal is represented by the equation
x(n) = 1 for all n>0
= 0 otherwise
function[x,n]=step seq(n0,n1,n2)
n=5:10;
x=[(n4)>=0];
stem(n,x);
title('unit step sequence delayed by four samples');
xlabel('samples');
ylabel('step sequence');
8. Exercise No 2 : ( 2 Hours) – 1 Practical
Aim: Verification of Convolution Theorem
The input sequence is denoted by x(n) and impulse response h(n) are convoluted
and the resultant signal is obtained .This technique illustrates how a filter can be
implemented in time domain .
The convolution is given by
¥
Y(k) = å x(k) . h(nk) for all k
n=¥
Implement the equation on 4_ point (or variety) x(n) & h(n) and display y(n).
%Illustration of convolution
x=input('type the input sequence');
h=input('type the impulse response');
y=conv(x,h);
m=length(y)1;
n=0:1:m;
disp('output sequence');
disp(y);
stem(n,y)
xlabel('Time index');
ylabel('Amplitude');
Another sample program for convolution where in time reference is also displayed.
%Illustration of convolution
nx=[1:2];
x=input('type the input sequence');
nh=[1:4];
h=input('type the impulse response');
nyb=nx(1)+nh(1);
nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
y=conv(x,h);
disp(y);
stem(ny,y)
xlabel('Time index');
ylabel('Amplitude');
9. Exercise No 3 : ( 2 Hours) – 1 Practical
Aim: Verification of Auto Correlation and Cross correlation
The cross correlation is given by
¥
Rxy(k) = å x(n) . y(nk)
n=¥
The auto correlation is given by
¥
Rxy(k) = å x(n) . y(nk)
n=¥
%computation of cross correlation sequence
x=input('type in the reference sequence=');
y=input('type in the second sequence=');
%compute the correlation sequence
n1= length(y)1;
n2= length(x)1;
r=xcorr(x,y);% here the length of x= length of y
%r=conv(x,fliplr(y));
%k=(n1):n2';
stem(r);
%computation of auto correlation of a sequence
x=input('type in the reference sequence=');
%compute the correlation sequence
%r=xcorr(x);
r=conv(x,fliplr(x));
stem(r);
10. Exercise No 4 : ( 2 Hours) – 1 Practical
Aim: Verification of Discrete Fourier Transform
The discrete fourier transform is given by
N1
X(k) = S x(n) exp (j*2*pi*n/N) k=0,1,…N1
n=0
for any arbitrary 8_point sequence x(n) of length N plot the frequency
response and phase response.
%Illustration of DFT computation
%we determine Mpoint DFT of N point u[n]=1 0<=n<=N1 else 0
%N be the length of the sequence and
%Mpoint dft is calculated
N=input('type the length of the sequence ');
M=input('type the length of the DFT= ');
u=[ones(1,N)];
U=fft(u,M);
t=0:1:N1;
stem(t,u);
title('Original time domain sequence')
xlabel('n')
ylabel('amplitude')
pause
subplot(2,1,1)
k=0:1:M1;
stem(k,abs(U))
title('Magnitude of DFT samples')
xlabel('frequency index k')
ylabel('magnitude')
subplot(2,1,2)
k=0:1:M1;
stem(k,angle(U))
title('Phase of DFT samples')
xlabel('frequency index k')
ylabel('phase')
11. Exercise No 5 : ( 2 Hours) – 1 Practical
Aim: Design of Infinite Impulse Filter
An IIR filter is represented by the equation
Y(n) = Sak y(nk) + Sbk x (nk )
For N=7 , F1= 500Hz , d1=3db ,F2=1000Hz , d2=40 db Design
h(n) either by Butterworth or by Chebyshev method and plot
in frequency domain the response of the filter.
%program to design type 1 Chebyshev lowpass filter
N=input('type filter order');
fp=input('passband edge frequency in hz= ');
Rp=input('passband ripple in db= ');
%Determine coefficients of the transfer function
[num,den]= cheby1(N,Rp,fp,'s');
%Compute and plot the frequency response
omega=[0:200:12000*pi];
h=freqs(num,den,omega);
plot(omega/(2*pi),20*log10(abs(h)));
xlabel('freq. in Hz');
ylabel('Gain in db');
%program to design Butterworth low pass filter
N=input('type filter order');
wn=input('3 db cut off frequency');
[num,den]= butter(N,wn,'s');
omega=[0:200:12000*pi];
h=freqs(num,den,omega);
plot(omega/(2*pi),20*log10(abs(h)));
xlabel('freq. in Hz');
ylabel('Gain in db');
12. Exercise No 6 : ( 2 Hours) – 1 Practical
Aim: Design of Finite Impulse Filter.
A FIR filter is represented by the equation
Y(n) = Sbk x (nk )
Design h(n) by implementing all windowing method.
Also apply these response on a signal and observe the filtered output.
%program to design fir by windowing method implementing
Bartlett ,Hamming , Blackman window
wp=0.2*pi;
ws=0.3*pi;
tr_width=wswp;
M=ceil(6.6*pi/tr_width)+1;
n=0:1:M1;
wc=(wp+ws)/2 % ideal LPF cutoff frequency
hd=ideal_lp(wc,M);
%w_ham=(blackman(M))';
%w_ham=(hamming(M))';
w_ham=(bartlett(M))';
h=hd.*w_ham;
[db,mag,pha,grd,w]=freqz_m(h,[1]);
delta_w=2*pi/1000;
rp=(min(db(1:1:wp/delta_w+1)));
As=round(max(db(ws/delta_w+1:1:501)))
subplot(1,1,1)
subplot(2,1,1);stem(n,hd);title('ideal impulse response');
axis([0 M1 0.1 0.3]);xlabel('n');ylabel('hd(n)')
subplot(2,2,2);stem(n,w_ham);title('Hamming Window');
axis([0 M1 0 1.1]);xlabel('n');ylabel('w(n)')
subplot(2,2,3);stem(n,h);title('Actual Impulse Response');
axis([0 M1 0.1 0.3]);xlabel('n');ylabel('h(n)')
subplot(2,2,4);plot(w/pi,db);title('Magnitude response in db');
axis([0 1 100 10]); xlabel('frequency in pi units'); ylabel('Decibels');
13. Exercise No 7 : ( 2 Hours) – 1 Practical
Aim: Study of DSP Starter Kit
Theory: TMS 32054X DSP Starter Kit has the following
ADVANTAGES and KEY FEATURES:
· Enhanced harvard architecture built around one program bus, three data buses and four address
buses for increased performance and versatility.
· Adavnced CPU design with a high degree of parallelism and application specific hardware logic
for increased performance.
· A highly specialized instruction set for faster algorithm and for optimized high level language
operation.
· Modular architectural design for fast development of spin off devices.
· Advanced IC processing technology for increased performance and low power consumption.
· Low power consumption and increased radiation hardness because of new static design
techniques.
CPU:
· 40 bit ALU including 40 bit Barrel shifter and two independent 40 bit accumulators.
· 17bit X17bit parallel multiplier coupled to a 40 bit dedicated adder for nonpipelined single cycle
multiply/accumulate operation.
· Compare ,select, store (CSS)unit for add/compare selection of Viterbi operation.
· Exponent encoder to compute the exponent of a 40 bit value in a single cycle.
· Two address generators including 8 Auxiliary registers and two auxiliary register arithmetic units.
· Dual CPU.
MEMORY:
· 192 K words by 16 bits addressable memory space.
INSTRUCTION SET:
· Single instruction repeat and block repeat operations.
· Block memory move instructions for better program and data management.
· Instructions with a 32 bit long operand.
· Instructions with two or three operand simultaneous reads.
· Arithmetic instructions with parallel store and parallel load .
· Conditional store instruction .
· Fast return from interrupt.
ON CHIP PERIPHERALS:
· Software programmable wait state generator.
· Programmable bank switching module.
· On chip PLL clock generator .
· Programmable timer.
· 8 bit enhanced Host port interface.
· Multichannel buffered serial port.
14. Exercise No 8 : ( 2 Hours) – 1 Practical
Aim: Generation of sine wave
Algorithm : 1. Store the value 2 cos(Q) in a memory.
2. Initialize the value of n .
3. According to the values of n and Q ,store the initial values of sin[(n1)Q] and
Sin[(n2) Q] in memory locations A and B respectively .
4. Calculate the value of recursive expression for sine using values in
Memory locations A,B and 2 cos(Q) and display it.
5. Store the value of sin[(n1) Q] in the memory location B.
6. Store the new value of sine in memory location A.
7. Increment n by one.
8. Repeat the steps 47.
Procedure :
1. Switch on the DSP board.
2. Open the Code Composer studio.
3. Create a new project from the pull down menu named ‘Project’.
From this pull down menu select ‘New’ and write the name of the
File and click ‘open’.
4. After the new file is named , pull down the ‘Project ‘ menu again
add all the files sin.c and common.cmd using the option ‘Add files to the
project ….’
5. Save the files using proper menu.
6. Connect the speaker jack to the input of the CRO.
7. Build the program . After the program is build the program is automatically
Loaded using the cmd file
8. Run the Program
9. The waveform appears on the screen.
Code for the Non real Time Implementation of Sine wave Generation:
# include <stdio.h>
# include <math.h>
# include <volume.h>
# define PI 3.1416
# define STEP 2000
int inp_buffer [BUFSIZE];
int out_buffer [BUFSIZE ];
int predict = 0 ;
float ar0,ar1,ar2;
18. 5. Conduction of VivaVoce Examinations:
Questions to be prepared for viva voce examinations
1. Define Discrete time Signal .
2. State the advantages of Digital Signal Processing.
3. What do you mean by aliasing? How to overcome?
4. Define LTI system.
5. What is the significance of convolution.
6. State the applications of autocorrelation and cross correlation.
7. Compare IIR with FIR filters.
8.What are linear phase filters ?
9. List different applications of DSP.
10.Explain architectural overview of TMS 3205402 DSK.
6. Evaluation and marking system:
As per JNEC format/University marking scheme.