Beruflich Dokumente
Kultur Dokumente
for
Digital Signal Processing
SSubathra
ProjectEngineer,NRCFOSS
AUKBCResearchCentre
MITCampusofAnnaUniversity
Chennai600044
subathra@aukbc.org
SignalProcessingwithScilab45mins(Tutor)
LabSession
InstallationDemo
10mins(Tutor)
InstallationofScilab
15mins(Participants)
ScilabBuildinDemo 50mins(Participants)
HandsonPractise
60mins(Participants)
Tutorial Session
Outline
Scilab
SignalProcessing
Handlingvectors&matrices
Usingplotfunctions
Signalgeneration
Sampling
Convolution
Correlation
DiscreteFourierTransform
DigitalFilterDesign
Scilab for Digital Signal Processing
Scilab
Freesoftware
Numericalprogramming
RapidPrototyping
Extensivelibrariesandtoolboxes
Easyformatrixmanipulation
Scilab
Freesoftware
Numericalprogramming
IdealforSignalProcessing
RapidPrototyping
Extensivelibrariesandtoolboxes
Easyformatrixmanipulation
Signal Processing
Asignalcarriesinformation,andtheobjectiveofsignal
processingistoextractusefulinformationcarriedbythe
signal.
Themethodofinformationextractiondependsonthetype
ofsignalandthenatureoftheinformationbeingcarriedby
thesignal.
SignalProcessingisconcernedwiththemathematical
representationofthesignalandthealgorithmicoperation
carriedoutonittoextracttheinformationpresent.
Signal Processing
A1Dsignalisafunctionofasingleindependentvariable.
A2Dsignalisafunctionofatwoindependentvariable.
Eg:SpeechSignal=>time
Eg:Image(likephotograph)=>twospatialvariables
AMDsignalisafunctionofmorethanonevariable.
Eg:Eachframeofablackandwhitevideosignalisa2
Dimagesignalthatisafunctionoftwodiscretespatial
variables,witheachframeoccurringsequentiallyat
discreteinstantsoftime.=>twospatialvariables&time
Scilab for Digital Signal Processing
Signal Processing
Therepresentationofthesignalcanbeintermsofbasis
functionsinthedomainoftheoriginalindependent
variable(s),oritcanbeintermsofbasisfunctionsina
transformeddomain.
Asignalcanbegeneratedbyasinglesourceorby
multiplesources.
SingleSource=>Scalar
MultipleSource=>Vector
Signal Processing
Therepresentationofthesignalcanbeintermsofbasis
functionsinthedomainoftheoriginalindependent
variable(s),oritcanbeintermsofbasisfunctionsina
transformeddomain.
HowtoprocessvectorswithScilab
Asignalcanbegeneratedbyasinglesourceorby
multiplesources.
SingleSource=>Scalar
MultipleSource=>Vector
10
Handling vectors
Tocreateazerovectorwith20dimensions
>a=zeros(1,20);
Tocreateavectorandstoreitinavariable
>b=[12351];
Toextracttheelement1to3oftheabovevector
>b(1:3)
[123]
Scilab for Digital Signal Processing
11
Handling matrices
Toinitializematrix
>m=zeros(3,3);
>k=rand(3,3);
>h=[1467;4321;143
8];
Toextracttheelementsof
thematrix
>h(2:3,2:4)
|178|
|215|
Togetthesizeofmatrix
>size(h)
>[34]
Transposeofamatrix
>h=[1467;4321;143
8];
>h
|129|
|412|
|671|
|785|
12
Operator Notation
Tomultiplytwomatricesaandb
>a*b
Formultiplyingtransposeofmatrixawithitself
>a*a
Forelementwisemultiplicationandaddition
>c=a.*b
>c=a.+b
Scilab for Digital Signal Processing
13
Plotfunctionisusedto
producenumberoftwo
dimensionalplots
0.9
0.8
0.7
Togeneratesarandom
vectoroflength10andplots
thepointswithstraightline
joiningeachpoints
0.6
0.5
0.4
0.3
0.2
0.1
>y=rand(1,10);
>plot(y);
0.0
10
Fig.1PlotFunctionSample1
Scilab for Digital Signal Processing
14
Colorofthelinejoiningthe
pointschangedusinga
parameter
yyellow
ccyan
ggreen
wwhite
mmagenta
rred
bblue
kblack
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
>y=rand(1,10);
>plot(y,r);
10
Fig.2PlotFunctionSample2
Scilab for Digital Signal Processing
15
Toproduceadiscontiniousplot
.usesdotateachpoint
*usesasterisksateachpoint
dusesblankdiamondateach
point
^usesupwardtrianglesateach
point
ousescircleateachpoint
+usescrossateachpoint
vusesinvertedtriangleateach
point
>y=rand(1,10);
>plot(y,r);
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
10
Fig.3PlotFunctionSample3
Scilab for Digital Signal Processing
16
Severalplotscanbeaccommodatedinasinglefigurewindow
usingsubplotcommand.
Thiscommandtakesthreeparametersasinput,firsttwo
parametersspecifiesthegridsize,i.e.howmanyrowsand
columnsandthethirdparameterspecifiesthepositionoftheplot
inthegrid.
Fore.g.,
subplot(3,2,2)
tellsscilabthatthefigurewindowisdividedasthreerows,two
columnsandtheplothastobeplacedinthesecondcolumnofthe
firstrow.
17
0.9
1.0
0.8
0.9
x1=rand(1,10);
0.7
subplot(2,2,1);
0.8
0.7
0.6
0.6
0.5
0.5
plot(x1);
0.4
0.4
x2=rand(1,20);
0.2
subplot(2,2,2);
plot(x2);
0.3
0.3
0.1
0.2
0.1
1
10
0.0
0.9
1.0
x3=rand(1,15);
0.8
0.9
subplot(2,2,3);
0.6
plot(x3);
0.4
0.4
subplot(2,2,4);
plot(x4);
10 12 14 16 18 20
0.6
0.5
0.1
0.7
0.5
x4=rand(1,25);
0.8
0.7
0.3
0.3
0.2
0.2
0.1
0
10
12
14
16
0.0
10
15
20
25
Fig.4PlotFunctionSample4
Scilab for Digital Signal Processing
18
Tomarklabel,thefunction
gcareturnsthehandlefor
thecurrentaxes
1.0
0.9
0.8
0.7
0.6
amplitude
t=1:1:50
0.5
0.4
y=rand(1,50);
0.3
plot(t,y);
0.2
0.1
a=gca();
0.0
a.x_label.text=time;
a.y_label.text=amplitude;
10
15
20
25
30
35
40
45
50
time
Fig.5PlotFunctionSample5
19
Meshplotcanbe
generatedusingplot3d
command.
Z
1
0
1
m=rand(5,7);
i=1:1:5;
2
3
1
4
3
6
j=1:1:7;
plot3d(i,j,m);
4
7
Fig.6PlotFunctionSample6
Scilab for Digital Signal Processing
20
Signal generation
SineWaveGeneration
1.0
0.8
0.6
0.4
Amplitude
//sinewave
t=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");
0.2
0.0
0.2
0.4
0.6
0.8
1.0
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
2.5
3.0
3.5
Time
CosineWaveGeneration
1.0
0.8
0.6
0.4
Amplitude
//coswave
t=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.2
0.0
0.2
0.4
0.6
0.8
1.0
0.0
0.5
1.0
1.5
2.0
Time
Fig.7Signalgeneration
Scilab for Digital Signal Processing
21
Sampling
Theprocessinwhichtheanalogcontinuoussignal
aremeasuredatequalintervaloftimeandfinallya
discretizedsetofdigitalnumbersarecreated.
ForpropersamplingofanalogsignalNyquist
Shannonsamplingtheoremshouldbesatisfied,i.e.
samplingfrequencyshouldbeagreaterthantwice
themaximumfrequencyoftheinputsignal.
22
Sampling - Example
Continuoussignal
1.0
0.8
0.6
0.4
Amplitude
fo=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");
0.2
0.0
0.2
0.4
0.6
0.8
1.0
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
30
35
40
45
50
Time
SampledSignal
1.0
0.8
0.6
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");
Amplitude
0.4
0.2
0.0
0.2
0.4
0.6
0.8
1.0
10
15
20
25
Time
Fig.8Sampling
Scilab for Digital Signal Processing
23
Convolution
ConvolutionistheprocessinwhichtheresponseofaLTIsystemis
computedforaninputsignal.
TheLTIsystemcanbedefinedusingtheimpulseresponseofthe
system.
Convolutionoftheinputsignalandimpulseresponseofthesystem
givestheoutputsignal.Thisprocessisalsocalleddigitalfiltering.
Mathematically,
24
Correlation
Correlationtakestwosignalsasinputandproducesthirdsignalasoutput.
Ifboththeinputsignalsareoneandthesame,thenitiscalledasauto
correlation
Ifboththeinputsignalsaredifferent,thenitiscalledascrosscorrelation
Correlationisusedtomeasurethesimilaritybetweenthetwoinputsignalsat
thatparticulartime.
Mathematically,
25
Usedforanalysingthefrequencycomponentsofasampled
signal
DFTdecomposestheinputsignalintosetofsinusoids
InDFT,wetakeasequenceofrealnumbers(sampledsignal)
asinputanditistransformedintoasequenceofcomplex
numbers.
Mathematically,
26
FilterUsedtoremovetheunwantedsignalfromthe
usefulsignal.
Foreg,removingnoisefromaudiosignal
TwotypesAnalog&Digitalfilters
Analogfiltersusesinductors,capacitorstoproduce
therequiredeffects
Digitalfilterusesmodernprocessorsfordoingthe
same
Scilab for Digital Signal Processing
27
Digitalfiltersareclassifiedasnonrecursive
filters(FIR)andrecursivefilters(IIR)
FIRFiltertheoutputwillbedependentonthe
current&previousinputvalues
IIRFilterdependentonpreviousoutputin
additiontotheinputvalues
28
FIR LPF
FIRlowpassfilter
1.2
1.0
0.8
Magnitude
//Lowpassfilter
fp=input('Enterthecutofffrequencyin
Hzfp=');
n=input('Entertheorderofthefilter
n=');
F=input('EntersamplingfrequencyinHz
F=');
wc=fp/F;
[coeffval,famp,ffreq]=wfir('lp',n,[wc0],
'hm',[00]);
//frequencyresponseofthefilter
plot2d(ffreq,famp);
a=gca();
a.x_label.text="Frequency";
a.y_label.text="Magnitude";
xtitle("FIRlowpassfilter");
0.6
0.4
0.2
0.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
Frequency
Fig.9FIRLPF
29
FIR HPF
FIRhighpassfilter
1.0
0.9
0.8
0.7
0.6
Magnitude
//Highpassfilter
fp=input('Enterthecutofffrequencyin
Hzfp=');
n=input('Entertheorderofthefilter
n=');
F=input('EntersamplingfrequencyinHz
F=');
wc=fp/F;
[coeffval,famp,ffreq]=wfir('hp',n,[wc0],
'hm',[00]);
//frequencyresponseofthefilter
plot2d(ffreq,famp);
a=gca();
a.x_label.text="Frequency";
a.y_label.text="Magnitude";
xtitle("FIRhighpassfilter");
0.5
0.4
0.3
0.2
0.1
0.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
Frequency
Fig.10FIRHPF
30
IIR LPF
DiscreteIIRfilterlowpass
1.2
1.0
0.8
Magnitude
//Lowpassfilter
fp=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.6
0.4
0.2
0.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
Frequency
Fig.11IIRLPF
31
IIR HPF
DiscreteIIRfilterhighpass
1.2
1.0
0.8
Magnitude
//Highpassfilter
fp=input('EnterthecutofffrequencyinHz
fp=');
n=input('Entertheorderofthefiltern=');
F=input('EntersamplingfrequencyinHz
F=');
wc=fp/F
hz=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.6
0.4
0.2
0.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
Frequency
Fig.12IIRHPF
32
Reference
[1]JohnG.ProakisandDimitrisG.Manolakis,DigitalSignalProcessingprinciples,algorithms,and
applicationsThirdedition.
[2]SanjitK.Mitra,DigitalSignalProcessingacomputerbasedapproachSecondedition.
[3]ScilabDocumentation,Availableatwww.scilab.org
33
Lab Session
34
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.gz
where
xreferstoextract,
zreferstogzip,
vreferstoverbose,
freferstofile
RunScilabbyexecutingscilab(shellscriptinbin)
Scilab for Digital Signal Processing
35
36
37
38