DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)

amrelsayedm 4,881 views 42 slides Apr 12, 2017
Slide 1
Slide 1 of 42
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42

About This Presentation

DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)


Slide Content

MATLAB(04)
The Discrete Fourier Transform
(DFT)
Assist. Prof. Amr E. Mohamed

Introduction
Thediscrete-timeFouriertransform(DTFT)providedthefrequency-
domain(ω)representationforabsolutelysummablesequences.
Thez-transformprovidedageneralizedfrequency-domain(z)
representationforarbitrarysequences.
Thesetransformshavetwofeaturesincommon.
First,thetransformsaredefinedforinfinite-lengthsequences.
Second,andthemostimportant,theyarefunctionsofcontinuousvariables
(ωorz).
Inotherwords,thediscrete-timeFouriertransformandthez-transform
arenotnumericallycomputabletransforms.
TheDiscreteFourierTransform(DFT)avoidsthetwoproblems
mentionedandisanumericallycomputabletransformthatissuitable
forcomputerimplementation.
2

Periodic Sequences
Let ??????(??????)isaperiodicsequencewithperiodN-Samples(thefundamental
periodofthesequence).
Notation:asequencewithperiodNissatisfyingthecondition
whererisanyinteger.
3 ),...1(),...,1(),0(),1(),...,1(),0(...,)(
~
 NxxxNxxxnx
x(n) x(n))(
~
)(
~
rNnxnx 

Periodic Sequences
FromFourieranalysisweknowthattheperiodicfunctionscanbesynthesized
asalinearcombinationofcomplexexponentialswhosefrequenciesare
multiples(orharmonics)ofthefundamentalfrequency(whichinourcaseis
2π/N).
ThediscreteversionoftheFourierSeriescanbewrittenas
where{ ??????(??????),??????=0,±1,...,∞}arecalledthediscreteFourierseries
coefficients.
NoteThat,forintegervaluesofm,wehave
(itiscalledTwiddleFactor)
4


k
kn
N
k
N
kn
j
k
kn
N
j
k
WkX
N
ekX
N
eXnx )(
~1
)(
~1
)(
~
2
2

 nmNk
N
N
nmNk
j
N
kn
j
kn
N WeeW
)(
)(
22






Synthesis and Analysis (DFS-Pairs)
5
Notation)/2(Nj
NeW


Synthesis




1
0
)(
~1
)(
~
N
k
kn
NWkX
N
nx
Analysis)(
~
)(
~
kXnx 
DFS
Both have
Period N



1
0
)(
~
)(
~
N
k
kn
NWnxKX

Matlab Implementation
AnefficientimplementationinMATLABwouldbetouseamatrix-vector
multiplication.
Let Xand Xdenotecolumnvectorscorrespondingtotheprimaryperiodsof
sequences ??????(??????)and ??????(??????),respectively.
wherethematrix�
??????isgivenby
6

Matlab Implementation (Cont.)
ThefollowingMATLABfunctiondfsimplementsthisprocedure.
7

Matlab Implementation (Cont.)
Example:TheDFSof ????????????={...,0,1,2,3,0,1,2,3,0,1,2,3,...}canbe
computedusingMATLABas
8

Matlab Implementation (Cont.)
Thefollowingidfsfunctionimplementsthesynthesisequation.
9

EXAMPLE
10

Solution
AplotofthissequenceforL=5andN=20isshownintheFigure
11

Solution (Cont.)
a.ByapplyingtheDFSanalysisequation
Thelastexpressioncanbesimplifiedto
12

Solution (Cont.)
orthemagnitudeof �(??????)isgivenby
b.TheMATLABscriptforL=5andN=20:
13

Solution (Cont.)
TheplotsforthisandallothercasesareshownintheFigure.
Notethatsince �(??????)isperiodic,theplotsareshownfrom−N/2toN/2.
14

Solution (Cont.)
C.Severalinterestingobservationscanbemadefromplotsintheabove
Figure.TheenvelopesoftheDFScoefficientsofsquarewaveslooklike
“sinc”functions.Theamplitudeatk=0isequaltoL,whilethezeros
ofthefunctionsareatmultiplesofN/L,whichisthereciprocalofthe
dutycycle.
15

Discrete Fourier Transform(DFT)
16

The DFT Pair
17N
j
N
N
k
kn
N
N
k
N
kn
j
N
n
kn
N
N
n
N
kn
j
eWwhere
NnWkX
N
x
ekX
N
xSynthesis
NkWnxX
enxXAnalysis



2
1
0
1
0
2
1
0
1
0
2
1,...,1,0)(
1
n)(
)(
1
n)(
1,...,1,0)(k)(
)(k)(



















Matlab Implementation
TheMATLABhas
thedftfunctiontocalculateDiscreteFourierTransform,and
theidftfunctiontocalculatetheinverseDiscreteFourierTransform.
Or,wecanusethefollowingcode
18

Example
19

Solution
a.Thediscrete-timeFouriertransformisgivenby
20

Solution (Cont.)
Theplotsofmagnitudeandphaseare
21

Solution (Cont.)
b.Letusdenotethe4-pointDFTbyX4(k).Then
WecanalsouseMATLABtocomputethisDFT.
Notethatwhenthemagnitudesampleiszero,thecorrespondingangle
isnotzero.ThisisduetoaparticularalgorithmusedbyMATLABto
computetheanglepart.Generallytheseanglesshouldbeignored.
22

Solution (Cont.)
23

Zero-Padding Operation
InpreviousExample,HowcanweobtainothersamplesoftheDTFT
??????(�
????????????
)?
Solution:Thiswecanachievebytreatingx(n)asan8-pointsequenceby
appending4zeros.
MATLABscript:
24

Zero-Padding Operation (Cont.)
Hence
25

Zero-Padding Operation (Cont.)
1.Zero-paddingisanoperationinwhichmorezerosareappendedtothe
originalsequence.TheresultinglongerDFTprovidescloselyspaced
samplesofthediscrete-timeFouriertransformoftheoriginal
sequence.
2.Thezero-paddinggivesusahigh-densityspectrumandprovidesa
betterdisplayedversionforplotting.Butitdoesnotgiveusahigh-
resolutionspectrumbecausenonewinformationisaddedtothesignal;
onlyadditionalzerosareaddedinthedata.
3.Togetahigh-resolutionspectrum,onehastoobtainmoredatafrom.
26

Example
27

Solution
a.Wecanfirstdeterminethe10-pointDFTofx(n)toobtainanestimate
ofitsdiscrete-timeFouriertransform.MATLABScript:
28

Solution (Cont.)
TheplotsinFigureshow
therearen’tenoughsamples
todrawanyconclusions.
Thereforewewillpad90
zerostoobtainadense
spectrum.
29

Solution (Cont.)
MATLABScript:
30

Solution (Cont.)
NowtheplotinFigureshows
thatthesequencehasa
dominant frequency at
ω=0.5π.
Thisfactisnotsupportedby
theoriginalsequence,which
hastwofrequencies.
Thezero-paddingprovideda
smootherversionofthe
spectrum.
31

Solution (Cont.)
b.Togetbetterspectralinformation,wewilltakethefirst100samplesof
x(n)anddetermineitsdiscrete-timeFouriertransform.
MATLABScript:
32

Solution (Cont.)
Nowthediscrete-timeFourier
transformplotinFigure
clearlyshowstwofrequencies,
whichareveryclosetoeach
other.
Thisisthehigh-resolution
spectrumofx(n).
Notethatpaddingmorezeros
tothe100-pointsequencewill
resultinasmootherrendition
ofthespectrum.
33

Circular Convolution
34

Circular Convolution
Aconvolutionoperationthatcontainsacircularshiftiscalledthe
circularconvolutionandisgivenby
NotethatthecircularconvolutionisalsoanN-pointsequence.
Ithasastructuresimilartothatofalinearconvolution.Thedifferences
areinthesummationlimitsandintheN-pointcircularshift.Henceit
dependsonNandisalsocalledanN-pointcircularconvolution.
Thereforetheuseofthenotation??????isappropriate.TheDFTproperty
forthecircularconvolutionis
35

MATLAB
Implementation
Thefollowingcirconvt
functionisaMATLAB
function that
calculatesthecircular
convolution.
36

MATLAB Implementation (Cont.)
Performthecircularconvolutionforthefollowingtwosequences
MATLABscript:
Hence
37

Linear Convolution Using The DFT
Infact,FIRfiltersaregenerallyimplementedinpracticeusingthis
linearconvolution.Ontheotherhand,theDFTisapracticalapproach
forimplementinglinearsystemoperationsinthefrequencydomain.
TheDFTisalsoanefficientoperationintermsofcomputations.
However,thereisoneproblem.TheDFToperationsresultinacircular
convolution(somethingthatwedonotdesire),notinalinear
convolutionthatwewant.
Howtomakeacircularconvolutionidenticaltothelinear
convolution???
Let??????
1(??????)and??????
2(??????)atwosequenceswithlength??????
1????????????�??????
2,thenthe
circularconvolutionisidenticaltothelinearconvolution.Ifwepadboth
sequencetohavealengthequalto??????=(??????
1+??????
2−1)point.
38

Example
Solution:
39

THE FAST FOURIER TRANSFORM
40

MATLAB IMPLEMENTATION
MATLABprovidesafunctioncalledffttocomputetheDFTofavectorx.
ItisinvokedbyX=fft(x,N),whichcomputestheN-pointDFT.
IfthelengthofxislessthanN,thenxispaddedwithzeros.Ifthe
argumentNisomitted,thenthelengthoftheDFTisthelengthofx.
Ifxisamatrix,thenfft(x,N)computestheN-pointDFTofeachcolumn
ofx.
ThisfftfunctioniswritteninmachinelanguageandnotusingMATLAB
commands(i.e.,itisnotavailableasa.mfile).Thereforeitexecutes
veryfast.Itiswrittenasamixed-radixalgorithm.
TheinverseDFTiscomputedusingtheifftfunction,whichhasthesame
characteristicsasfft.
41

42
Tags