subathra_scilab4dsp.pdf
TRANSCRIPT
-
for Digital Signal Processing
SSubathraProjectEngineer,NRCFOSSAUKBCResearchCentreMITCampusofAnnaUniversityChennai600044subathra@aukbc.org
AICTESDPonOpenSourceSoftware,PSGTech,June22nd,2007July6th,2007
-
Scilab for Digital Signal Processing 2
Plan for PresentationTutorialSession
SignalProcessingwithScilab45mins(Tutor)
LabSession InstallationDemo 10mins(Tutor) InstallationofScilab 15mins(Participants) ScilabBuildinDemo 50mins(Participants) HandsonPractise 60mins(Participants)
-
Scilab for Digital Signal Processing 3
Tutorial Session
-
Scilab for Digital Signal Processing 4
Outline Scilab SignalProcessing Handlingvectors&matrices Usingplotfunctions Signalgeneration Sampling Convolution Correlation DiscreteFourierTransform DigitalFilterDesign
-
Scilab for Digital Signal Processing 5
Scilab
Freesoftware Numericalprogramming RapidPrototyping Extensivelibrariesandtoolboxes Easyformatrixmanipulation
-
Scilab for Digital Signal Processing 6
Scilab
Freesoftware Numericalprogramming RapidPrototyping Extensivelibrariesandtoolboxes Easyformatrixmanipulation
IdealforSignalProcessing
-
Scilab for Digital Signal Processing 7
Signal Processing Asignalcarriesinformation,andtheobjectiveofsignal
processingistoextractusefulinformationcarriedbythesignal.
Themethodofinformationextractiondependsonthetypeofsignalandthenatureoftheinformationbeingcarriedbythesignal.
SignalProcessingisconcernedwiththemathematicalrepresentationofthesignalandthealgorithmicoperationcarriedoutonittoextracttheinformationpresent.
-
Scilab for Digital Signal Processing 8
Signal Processing A1Dsignalisafunctionofasingleindependentvariable.
Eg:SpeechSignal=>time A2Dsignalisafunctionofatwoindependentvariable.
Eg:Image(likephotograph)=>twospatialvariables AMDsignalisafunctionofmorethanonevariable.
Eg:Eachframeofablackandwhitevideosignalisa2Dimagesignalthatisafunctionoftwodiscretespatialvariables,witheachframeoccurringsequentiallyatdiscreteinstantsoftime.=>twospatialvariables&time
-
Scilab for Digital Signal Processing 9
Signal Processing Therepresentationofthesignalcanbeintermsofbasis
functionsinthedomainoftheoriginalindependentvariable(s),oritcanbeintermsofbasisfunctionsinatransformeddomain.
Asignalcanbegeneratedbyasinglesourceorbymultiplesources. SingleSource=>Scalar MultipleSource=>Vector
-
Scilab for Digital Signal Processing 10
Signal Processing Therepresentationofthesignalcanbeintermsofbasis
functionsinthedomainoftheoriginalindependentvariable(s),oritcanbeintermsofbasisfunctionsinatransformeddomain.
Asignalcanbegeneratedbyasinglesourceorbymultiplesources. SingleSource=>Scalar MultipleSource=>Vector
HowtoprocessvectorswithScilab
-
Scilab for Digital Signal Processing 11
Handling vectors Tocreateazerovectorwith20dimensions>a=zeros(1,20);
Tocreateavectorandstoreitinavariable>b=[12351];
Toextracttheelement1to3oftheabovevector>b(1:3)[123]
-
Scilab for Digital Signal Processing 12
Handling matrices Toinitializematrix>m=zeros(3,3);>k=rand(3,3);>h=[1467;4321;143
8];
Toextracttheelementsofthematrix
>h(2:3,2:4)|178||215|
Togetthesizeofmatrix>size(h)>[34]
Transposeofamatrix>h=[1467;4321;143
8];>h|129||412||671||785|
-
Scilab for Digital Signal Processing 13
Operator Notation Tomultiplytwomatricesaandb>a*b
Formultiplyingtransposeofmatrixawithitself>a*a
Forelementwisemultiplicationandaddition>c=a.*b>c=a.+b
-
Scilab for Digital Signal Processing 14
Using Plot Function Plotfunctionisusedto
producenumberoftwodimensionalplots
Togeneratesarandomvectoroflength10andplotsthepointswithstraightlinejoiningeachpoints
>y=rand(1,10);>plot(y);
1 2 3 4 5 6 7 8 9 100.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Fig.1PlotFunctionSample1
-
Scilab for Digital Signal Processing 15
Using Plot Function color Colorofthelinejoiningthe
pointschangedusingaparameter yyellow ccyan ggreen wwhite mmagenta rred bblue kblack
>y=rand(1,10);>plot(y,r);
1 2 3 4 5 6 7 8 9 100.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Fig.2PlotFunctionSample2
-
Scilab for Digital Signal Processing 16
Using Plot Function
Toproduceadiscontiniousplot .usesdotateachpoint *usesasterisksateachpoint dusesblankdiamondateach
point ^usesupwardtrianglesateach
point ousescircleateachpoint +usescrossateachpoint vusesinvertedtriangleateach
point
>y=rand(1,10);>plot(y,r);
1 2 3 4 5 6 7 8 9 100.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Fig.3PlotFunctionSample3
-
Scilab for Digital Signal Processing 17
Using Plot Function subplot Severalplotscanbeaccommodatedinasinglefigurewindow
usingsubplotcommand.
Thiscommandtakesthreeparametersasinput,firsttwoparametersspecifiesthegridsize,i.e.howmanyrowsandcolumnsandthethirdparameterspecifiesthepositionoftheplotinthegrid.
Fore.g.,subplot(3,2,2)tellsscilabthatthefigurewindowisdividedasthreerows,two
columnsandtheplothastobeplacedinthesecondcolumnofthefirstrow.
-
Scilab for Digital Signal Processing 18
Using Plot Function subplotExample:x1=rand(1,10);subplot(2,2,1);plot(x1);x2=rand(1,20);subplot(2,2,2);plot(x2);x3=rand(1,15);subplot(2,2,3);plot(x3);x4=rand(1,25);subplot(2,2,4);plot(x4);
1 2 3 4 5 6 7 8 9 100.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0 2 4 6 8 10 12 14 16 18 200.00.10.20.30.40.50.60.70.80.91.0
0 2 4 6 8 10 12 14 160.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0 5 10 15 20 250.00.10.20.30.40.50.60.70.80.91.0
Fig.4PlotFunctionSample4
-
Scilab for Digital Signal Processing 19
Using Plot Function - label
Tomarklabel,thefunctiongcareturnsthehandleforthecurrentaxes
t=1:1:50y=rand(1,50);plot(t,y);a=gca();a.x_label.text=time;a.y_label.text=amplitude;
0 5 10 15 20 25 30 35 40 45 500.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
time
amplitud
e
Fig.5PlotFunctionSample5
-
Scilab for Digital Signal Processing 20
Using Plot Function - Mesh plot
Meshplotcanbegeneratedusingplot3dcommand.
m=rand(5,7);i=1:1:5;j=1:1:7;plot3d(i,j,m);
0
1
Z
1
2
3
4
5
X
1
2
3
4
5
6
7
Y
Fig.6PlotFunctionSample6
-
Scilab for Digital Signal Processing 21
Signal generation//sinewavet=0:0.01:3.14;y=sin(2*3.14*t);subplot(2,1,1);a=gca();a.x_label.text="Time";a.y_label.text="Amplitude";plot2d(t,y);xtitle("SineWaveGeneration");
//coswavet=0:0.01:3.14;y=cos(2*3.14*t);subplot(2,1,2);a=gca();a.x_label.text="Time";a.y_label.text="Amplitude";plot2d(t,y);xtitle("CosineWaveGeneration");
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.51.00.80.60.40.20.00.20.40.60.81.0
SineWaveGeneration
Time
Amplitud
e
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.51.00.80.60.40.20.00.20.40.60.81.0
CosineWaveGeneration
Time
Amplitud
e
Fig.7Signalgeneration
-
Scilab for Digital Signal Processing 22
Sampling
Theprocessinwhichtheanalogcontinuoussignalaremeasuredatequalintervaloftimeandfinallyadiscretizedsetofdigitalnumbersarecreated.
ForpropersamplingofanalogsignalNyquistShannonsamplingtheoremshouldbesatisfied,i.e.samplingfrequencyshouldbeagreaterthantwicethemaximumfrequencyoftheinputsignal.
-
Scilab for Digital Signal Processing 23
Sampling - Examplefo=input('Frequencyofsincewaveinhz=');ft=input('Samplingfrequencyinhz=');t=0:0.01:1;T=1.0/ft;x=sin(2*3.14*fo*t);subplot(2,1,1);a=gca();a.x_label.text="Time";a.y_label.text="Amplitude";plot(t,x);xtitle("Continuoussignal");
n=0:ft;y=sin(2*3.14*fo*n*T);subplot(2,1,2);a=gca();a.x_label.text="Time";a.y_label.text="Amplitude";plot2d3(n,y);xtitle("SampledSignal");
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.01.00.80.60.40.20.00.20.40.60.81.0
Continuoussignal
Time
Amplitud
e
0 5 10 15 20 25 30 35 40 45 501.00.80.60.40.20.00.20.40.60.81.0
SampledSignal
Time
Amplitud
e
Fig.8Sampling
-
Scilab for Digital Signal Processing 24
Convolution
ConvolutionistheprocessinwhichtheresponseofaLTIsystemiscomputedforaninputsignal.
TheLTIsystemcanbedefinedusingtheimpulseresponseofthesystem.
Convolutionoftheinputsignalandimpulseresponseofthesystemgivestheoutputsignal.Thisprocessisalsocalleddigitalfiltering.
Mathematically,
-
Scilab for Digital Signal Processing 25
Correlation
Correlationtakestwosignalsasinputandproducesthirdsignalasoutput.
Ifboththeinputsignalsareoneandthesame,thenitiscalledasautocorrelation
Ifboththeinputsignalsaredifferent,thenitiscalledascrosscorrelation
Correlationisusedtomeasurethesimilaritybetweenthetwoinputsignalsatthatparticulartime.
Mathematically,
-
Scilab for Digital Signal Processing 26
Discrete Fourier Transform
Usedforanalysingthefrequencycomponentsofasampledsignal
DFTdecomposestheinputsignalintosetofsinusoids
InDFT,wetakeasequenceofrealnumbers(sampledsignal)asinputanditistransformedintoasequenceofcomplexnumbers.
Mathematically,
-
Scilab for Digital Signal Processing 27
Digital Filter Design Analog & Digital FilterUsedtoremovetheunwantedsignalfromthe
usefulsignal. Foreg,removingnoisefromaudiosignal
TwotypesAnalog&Digitalfilters Analogfiltersusesinductors,capacitorstoproduce
therequiredeffects Digitalfilterusesmodernprocessorsfordoingthe
same
-
Scilab for Digital Signal Processing 28
Digital Filter Design FIR & IIR
Digitalfiltersareclassifiedasnonrecursivefilters(FIR)andrecursivefilters(IIR) FIRFiltertheoutputwillbedependentonthecurrent&previousinputvalues
IIRFilterdependentonpreviousoutputinadditiontotheinputvalues
-
Scilab for Digital Signal Processing 29
FIR LPF//Lowpassfilterfp=input('Enterthecutofffrequencyin
Hzfp=');n=input('Entertheorderofthefilter
n=');F=input('EntersamplingfrequencyinHz
F=');wc=fp/F;[coeffval,famp,ffreq]=wfir('lp',n,[wc0],
'hm',[00]);//frequencyresponseofthefilterplot2d(ffreq,famp);a=gca();a.x_label.text="Frequency";a.y_label.text="Magnitude";xtitle("FIRlowpassfilter");
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.500.0
0.2
0.4
0.6
0.8
1.0
1.2
FIRlowpassfi l ter
Frequency
Magn
itude
Fig.9FIRLPF
-
Scilab for Digital Signal Processing 30
FIR HPF//Highpassfilterfp=input('Enterthecutofffrequencyin
Hzfp=');n=input('Entertheorderofthefilter
n=');F=input('EntersamplingfrequencyinHz
F=');wc=fp/F;[coeffval,famp,ffreq]=wfir('hp',n,[wc0],
'hm',[00]);//frequencyresponseofthefilterplot2d(ffreq,famp);a=gca();a.x_label.text="Frequency";a.y_label.text="Magnitude";xtitle("FIRhighpassfilter");
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.500.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
FIRhighpassfil ter
Frequency
Magn
itude
Fig.10FIRHPF
-
Scilab for Digital Signal Processing 31
IIR LPF//Lowpassfilterfp=input('EnterthecutofffrequencyinHz
fp=');n=input('Entertheorderofthefiltern=');F=input('EntersamplingfrequencyinHz
F=');wc=fp/F;hz=iir(3,'lp','butt',[wc0],[00]);[hzm,fr]=frmag(hz,256);plot2d(fr',hzm');a=gca();a.x_label.text="Frequency";a.y_label.text="Magnitude";xtitle('DiscreteIIRfilterlowpass');q=poly(0,'q');//toexpresstheresultintermsof
the...hzd=horner(hz,1/q)//delayoperatorq=z^1
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.500.0
0.2
0.4
0.6
0.8
1.0
1.2
DiscreteIIRfi l terlowpass
Frequency
Magn
itude
Fig.11IIRLPF
-
Scilab for Digital Signal Processing 32
IIR HPF//Highpassfilterfp=input('EnterthecutofffrequencyinHz
fp=');n=input('Entertheorderofthefiltern=');F=input('EntersamplingfrequencyinHz
F=');wc=fp/Fhz=iir(3,'hp','butt',[wc0],[00]);[hzm,fr]=frmag(hz,256);plot2d(fr',hzm');a=gca();a.x_label.text="Frequency";a.y_label.text="Magnitude";xtitle('DiscreteIIRfilterhighpass');q=poly(0,'q');//toexpresstheresultintermsof
the...hzd=horner(hz,1/q)//delayoperatorq=z^1
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.500.0
0.2
0.4
0.6
0.8
1.0
1.2
DiscreteIIRfi lterhighpass
Frequency
Magn
itude
Fig.12IIRHPF
-
Scilab for Digital Signal Processing 33
Reference
[1]JohnG.ProakisandDimitrisG.Manolakis,DigitalSignalProcessingprinciples,algorithms,andapplicationsThirdedition.
[2]SanjitK.Mitra,DigitalSignalProcessingacomputerbasedapproachSecondedition.
[3]ScilabDocumentation,Availableatwww.scilab.org
-
Scilab for Digital Signal Processing 34
Lab Session
-
Scilab for Digital Signal Processing 35
Scilab Installation How To Gotowww.scilab.org Checkforthelatestdownloadableversionofscilab(i.e.scilab
4.1.1.bin.linuxi686.tar.gz)anddownloadit. Untarthescilab4.1.1.bin.linuxi686.tar.gzusingthecommand
#tarxzvfscilab4.1.1.bin.linuxi686.tar.gzwherexreferstoextract,zreferstogzip,vreferstoverbose,freferstofile
RunScilabbyexecutingscilab(shellscriptinbin)
-
Scilab for Digital Signal Processing 36
Scilab Build-in Demo
Scilabdemonstration
http://www.scilab.org/doc/demos_html/index.html
MatlabandScilabfunctions
http://www.scilab.org/product/dicmatsci/M2SCI_doc.htm
-
Scilab for Digital Signal Processing 37
More about DSP
SignalProcessingInformationBase(SPIB)
http://spib.rice.edu/spib.html
DSPOnlineClasses
http://bores.com/index_dsp.htm
http://bores.com/index_online.htm
-
Scilab for Digital Signal Processing 38