You are on page 1of 19

JawaharlalNehruEngineeringCollege

LaboratoryManual

DIGITAL SIGNAL PROCESSING

For

Third Year Students

Author JNEC, Aurangabad

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.

SUBJECT INDEX
Title

1.Dos and Donts in Laboratory


2 .Instruction for Laboratory Teachers:

Page no.

04
04

3. Lab Exercises
1. Introduction to matlab
2. Generation of signal
3. To verify the partial fraction expansion of the ztransform.
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

05
08

1. DOs and DONTs in Laboratory:


1.
2.
3.
4.
.

Do not handle DSP Starter kit without reading the instructions/Instruction manuals.
Refer Matlab Help for debugging the program.
Go through Matlab Demos of Signal Processing tool box.
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.

3.LabExercises:
Exercise No1: ( 2 Hours) 1 Practical
Aim:Generationofdiscretetimesignallike
a)sinusoidal
b) step
c) ramp
d) impulse
e) realvalued
f) complexvalued
g) noise
ThesearethebasicdiscretesignalsusedinDSP. Plotallthesignals.
Step:1.

GenerateSinusoidalsignal
Discretesinusoidalsignalisrepresentedbytheequation
x(n)=ASin(2 Pfn)foralln
fs
A=peakamplitude
f=signalfrequency
fs=samplingfrequency
n=nthsample
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('Sinusoidalsequence')
xlabel('samples')
ylabel('magnitude')

Step:2.

GenerateStepsignal
Discretestepsignalisrepresentedbytheequation
x(n)=1
foralln>0
=0otherwise

function[x,n]=stepseq(n0,n1,n2)
n=5:10
x=[(n4)>=0]
stem(n,x)
title('unitstepsequencedelayedbyfoursamples')
xlabel('samples')
ylabel('stepsequence')

Step:3.

Generaterampsignal
Discreterampsignalisrepresentedbytheequation
x(n)=nforalln>0
=0otherwise
function[x,n]=rampseq(n0,n1)
n=0:10
x=n
stem(n,x)
title('unitrampsequencedelayedbyfoursamples')
xlabel('samples')
ylabel('rampsequence')

Steps:4. Generatecomplexvaluedsignal
Discretecomplexvaluedsignalisrepresentedbytheequation
x(n)=exp(a+jb)nforalln>0
function[x,n]=compexp(n1,n2)
n=10:50
x=[exp((0.2+i*2)*n)]
stem(n,x)
title('Complexvaluedexponentialsequence')
xlabel('samples')
ylabel('complexvaluedexponentialsequence')

Steps:5. Generaterealvalued signal


Discreterealvaluedsignal isrepresentedbytheequation
x(n)=exp(a)nforalln>0
a<1
function[x,n]=realseq(n1,n2)
n=1:10
x(n)=(0.9).^n
stem(n,x)
title('Realvaluedsequence')
xlabel('samples')
ylabel('impulsesequence')

Steps:5. Generateimpulsesignal
Discreteimpulsesignalisrepresentedbytheequation
x(n)=1foralln=0
=0otherwise
x=2*impseq(5,0,20)
y=3*impseq(1,0,20)
a=x+y
stem(a)
title('unitimpulsesequence')
xlabel('samples')
ylabel('impulsesequence')

Steps:6. Generatenoisesignal
n=50
x=rand(n,1)
%generatetheuncorruptedsignal
m=0:1:n1
s=2*m.*(0.9.^m)
subplot(2,1,1)
stem(m,s)
title('Uncorruptedsequence')
xlabel('Timeindex')
ylabel('Amplitude')
subplot(2,1,2)
stem(m,x)
title('Noise')
xlabel('Timeindex')
ylabel('Amplitude')

Exercise No 2 : ( 2 Hours) 1 Practical


Aim:VerificationofConvolutionTheorem
Theinputsequenceisdenotedbyx(n)andimpulseresponseh(n)areconvoluted
andtheresultantsignalisobtained.Thistechniqueillustrateshowafiltercanbe
implementedintimedomain.
Theconvolutionisgivenby

Y(k)= x(k).h(nk)forall k
n=
Implementtheequationon4_point(orvariety)x(n)&h(n)anddisplayy(n).
%Illustrationofconvolution
x=input('typetheinputsequence')
h=input('typetheimpulseresponse')
y=conv(x,h)
m=length(y)1
n=0:1:m
disp('outputsequence')
disp(y)
stem(n,y)
xlabel('Timeindex')
ylabel('Amplitude')
Anothersampleprogramforconvolutionwhereintimereferenceisalsodisplayed.
%Illustrationofconvolution
nx=[1:2]
x=input('typetheinputsequence')
nh=[1:4]
h=input('typetheimpulseresponse')
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('Timeindex')
ylabel('Amplitude')

Exercise No 3 : ( 2 Hours) 1 Practical


Aim:VerificationofAutoCorrelation andCrosscorrelation
Thecrosscorrelationisgivenby

Rxy(k)= x(n).y(nk)
n=
Theautocorrelationisgivenby

Rxy(k)= x(n).y(nk)
n=
%computationofcrosscorrelationsequence
x=input('typeinthereferencesequence=')
y=input('typeinthesecondsequence=')
%computethecorrelationsequence
n1=length(y)1
n2=length(x)1
r=xcorr(x,y)%herethelengthofx=lengthofy
%r=conv(x,fliplr(y))
%k=(n1):n2'
stem(r)
%computationofautocorrelationofasequence
x=input('typeinthereferencesequence=')
%computethecorrelationsequence
%r=xcorr(x)
r=conv(x,fliplr(x))
stem(r)

Exercise No 4 : ( 2 Hours) 1 Practical


Aim:VerificationofDiscreteFourierTransform
Thediscretefouriertransformisgivenby
N1
X(k)= S x(n)exp(j*2*pi*n/N)k=0,1,N1
n=0

foranyarbitrary8_pointsequencex(n)oflengthNplotthefrequency
responseandphaseresponse.
%IllustrationofDFTcomputation
%wedetermineMpointDFTofNpointu[n]=10<=n<=N1else0
%Nbethelengthofthesequenceand
%Mpointdftiscalculated
N=input('typethelengthofthesequence')
M=input('typethelengthoftheDFT=')
u=[ones(1,N)]
U=fft(u,M)
t=0:1:N1
stem(t,u)
title('Originaltimedomainsequence')
xlabel('n')
ylabel('amplitude')
pause
subplot(2,1,1)
k=0:1:M1
stem(k,abs(U))
title('MagnitudeofDFTsamples')
xlabel('frequencyindexk')
ylabel('magnitude')
subplot(2,1,2)
k=0:1:M1
stem(k,angle(U))
title('PhaseofDFTsamples')
xlabel('frequencyindexk')
ylabel('phase')

Exercise No 5 : ( 2 Hours) 1 Practical


Aim:DesignofInfiniteImpulseFilter
AnIIRfilterisrepresentedbytheequation
Y(n)= Sak y(nk)+ Sbk x(nk)
ForN=7,F1=500Hz, d1=3db,F2=1000Hz, d2=40dbDesign
h(n)eitherbyButterworthorbyChebyshevmethodandplot
infrequencydomaintheresponseofthefilter.
%programtodesigntype1Chebyshevlowpassfilter
N=input('typefilterorder')
fp=input('passbandedgefrequencyinhz=')
Rp=input('passbandrippleindb=')
%Determinecoefficientsofthetransferfunction
[num,den]=cheby1(N,Rp,fp,'s')
%Computeandplotthefrequencyresponse
omega=[0:200:12000*pi]
h=freqs(num,den,omega)
plot(omega/(2*pi),20*log10(abs(h)))
xlabel('freq.inHz')
ylabel('Gainindb')

%programtodesignButterworthlowpassfilter
N=input('typefilterorder')
wn=input('3dbcutofffrequency')
[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.inHz')
ylabel('Gainindb')

Exercise No 6 : ( 2 Hours) 1 Practical


Aim:DesignofFiniteImpulseFilter.
AFIRfilterisrepresentedbytheequation
Y(n)= Sbk x(nk)
Designh(n)byimplementingallwindowingmethod.
Alsoapplytheseresponseon asignalandobservethefilteredoutput.
%programtodesignfirbywindowingmethodimplementing
Bartlett,Hamming,Blackmanwindow
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 cutofffrequency
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('idealimpulseresponse')
axis([0M10.10.3])xlabel('n')ylabel('hd(n)')
subplot(2,2,2)stem(n,w_ham)title('HammingWindow')
axis([0M101.1])xlabel('n')ylabel('w(n)')
subplot(2,2,3)stem(n,h)title('ActualImpulseResponse')
axis([0M10.10.3])xlabel('n')ylabel('h(n)')
subplot(2,2,4)plot(w/pi,db)title('Magnituderesponseindb')
axis([0110010])xlabel('frequencyinpiunits')ylabel('Decibels')

Exercise No 7 : ( 2 Hours) 1 Practical


Aim:StudyofDSPStarterKit
Theory:TMS32054XDSPStarterKithasthefollowing
ADVANTAGESandKEYFEATURES:
Enhancedharvardarchitecturebuiltaroundoneprogrambus,threedatabusesandfouraddress
busesforincreasedperformanceandversatility.
AdavncedCPUdesignwithahighdegreeofparallelismandapplicationspecifichardwarelogic
forincreasedperformance.
Ahighly specializedinstructionsetforfasteralgorithmandforoptimizedhighlevellanguage
operation.
Modulararchitecturaldesignforfastdevelopmentof spinoff devices.
AdvancedICprocessingtechnologyforincreasedperformanceandlowpowerconsumption.
Lowpowerconsumptionandincreasedradiationhardnessbecauseofnewstaticdesign
techniques.
CPU:
40bitALUincluding40bitBarrelshifterandtwoindependent40bitaccumulators.
17bitX17bitparallelmultipliercoupledtoa40bitdedicatedadderfornonpipelinedsinglecycle
multiply/accumulateoperation.
Compare,select,store(CSS)unitforadd/compareselectionofViterbioperation.
Exponentencodertocomputetheexponentofa40bitvalueinasinglecycle.
Twoaddressgeneratorsincluding8Auxiliary registersandtwoauxiliary registerarithmeticunits.
DualCPU.
MEMORY:
192Kwordsby16bitsaddressablememoryspace.
INSTRUCTIONSET:
Singleinstructionrepeatandblockrepeatoperations.
Blockmemorymoveinstructionsforbetterprogramanddatamanagement.
Instructionswitha32bitlongoperand.
Instructionswithtwoorthreeoperandsimultaneousreads.
Arithmeticinstructionswithparallelstoreandparallelload.
Conditionalstoreinstruction.
Fastreturnfrominterrupt.
ONCHIPPERIPHERALS:
Softwareprogrammablewaitstategenerator.
Programmablebankswitchingmodule.
OnchipPLLclockgenerator .
Programmabletimer.
8bitenhancedHostportinterface.
Multichannelbufferedserialport.

Exercise No 8 : ( 2 Hours) 1 Practical


Aim:Generationofsinewave
Algorithm:1.Storethevalue2cos(Q)inamemory.
2. Initializethevalueofn.
3. Accordingtothevaluesofnand Q,storetheinitialvaluesofsin[(n1)Q]and
Sin[(n2) Q]inmemorylocationsAandBrespectively .
4. Calculatethevalueofrecursiveexpressionforsineusingvaluesin
MemorylocationsA,Band2cos(Q)anddisplay it.
5. Storethevalueofsin[(n1) Q]inthememorylocationB.
6. StorethenewvalueofsineinmemorylocationA.
7. Incrementnbyone.
8. Repeatthesteps47.
Procedure:
1. SwitchontheDSPboard.
2. OpentheCodeComposerstudio.
3. CreateanewprojectfromthepulldownmenunamedProject.
FromthispulldownmenuselectNewandwritethenameofthe
Fileandclickopen.
4.Afterthenewfileisnamed,pulldowntheProjectmenuagain
addallthefilessin.candcommon.cmdusingtheoptionAddfilestothe
project.
5.Savethefilesusingpropermenu.
6. ConnectthespeakerjacktotheinputoftheCRO.
7. Buildtheprogram.Aftertheprogramisbuildtheprogramisautomatically
Loadedusingthecmdfile
8. RuntheProgram
9. Thewaveformappearsonthescreen.
CodefortheNonrealTimeImplementationofSinewaveGeneration:
#include<stdio.h>
#include<math.h>
#include<volume.h>
#define PI3.1416
#defineSTEP2000
intinp_buffer[BUFSIZE]
intout_buffer[BUFSIZE]
intpredict=0
floatar0,ar1,ar2

floatstep(PI/180)*6
unsignedintprocessingload=BASELOAD
externvoidload(unsignedintloadvalue)
staticintprocessing(int*input,int*output)
staticvoiddataIO(void)
voidmain()
{
int*input=&inp_buffer[0]
int*output=&out_buffer[0]
puts(volumeexamplestarted\n)
/*initializationofTaylorseries*/
ar0=cos(step)
ar1=sin(step)
ar2=sin((2*step))
while(TRUE)
{
dataIO()
processing(input,output)
}
}

Staticintprocessing(int*input,int*output)
{
intsize=BUFSIZE
intdata
interror
intdelta=2500
floatvalue
while(size)
{value=(2*ar0*ar1)ar2
data=value*16000
ar2=ar1
ar1=value
*input++=data

error=datapredict
if(error>0)
predict=delta
else
if(error<0)
prdict=delta
*output++=predict
}
load(processingload)
returnTRUE
}
staticvoiddataIO()
{
return
}

4.Quizonthesubject:
1).Signalsarethesignalsrepeatingafterspecificperiod.
a]Energy
b]Digital
c]Periodic
2)Thesystemissaidtobe ortohavememory.
a]Dynamic
b]Recursive
c]Stable
3)Ify(n)=nx(n)thenthesystemis
a]Causual
b]Recursive
c]dynamic
4)IfthesignalisinfinitedurationandbothsidedthenitsROCis
a]anannularring
b]entirezplaneexceptz=0
c]entirezplaneexceptz=

5)IfthesequenceisrealandeventhentheDFTconsistsof

a]realandevenparts
b]purelyimaginaryparts

5.ConductionofVivaVoceExaminations:
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.Evaluationandmarkingsystem:
As per JNEC format/University marking scheme.

You might also like