Professional Documents
Culture Documents
Fast Fourier Transform and Matlab Implementation: by Wanjun Huang For For Dr. Duncan L. Macfarlane
Fast Fourier Transform and Matlab Implementation: by Wanjun Huang For For Dr. Duncan L. Macfarlane
MATLABImplementation
by
WanjunHuang
for
Dr.DuncanL.MacFarlane
Signals
In the fields of communications, signal processing, and in electrical engineering
more generally, a signal is any timevarying or spatialvarying quantity
This variable(quantity) changes in time
Speech or audio signal: A sound amplitude that varies in time
Temperature readings at different hours of a day
Stock price changes over days
Etc.
Etc
Signalscanbeclassifiedbycontinuestimesignalanddiscretetime signal:
Adiscretesignalordiscretetimesignalisatimeseries,perhapsasignalthat
h b
hasbeensampledfromacontinuoustimesignal
l df
ti
ti
i l
Adigitalsignalisadiscretetimesignalthattakesononlyadiscretesetof
values
Discrete Time Signal
0.5
0.5
f[n]
f(t)
0
-0.5
-1
0
-0.5
10
20
Time (sec)
30
40
-1
10
20
n
30
40
PeriodicSignal
periodicsignalandnonperiodicsignal:
Periodic Signal
Non-Periodic Signal
-1
1
f[n]
f(t)
10
20
Time (sec)
30
40
-1
10
20
n
30
40
PeriodT:Theminimumintervalonwhich
asignalrepeats
Fundamental frequency: f0=1/T
Fundamentalfrequency:f
1/T
Harmonicfrequencies:kf0
Anyperiodicsignalcanbeapproximated
byasumofmanysinusoidsatharmonicfrequenciesofthesignal(kf
y
y
q
g ( f0))with
appropriateamplitudeandphase
Insteadofusingsinusoidsignals,mathematically,wecanusethecomplex
exponentialfunctionswithbothpositiveandnegativeharmonicfrequencies
TimeFrequencyAnalysis
Asignalhasoneormorefrequenciesinit,andcanbeviewedfrom
twodifferentstandpoints:TimedomainandFrequencydomain
Time Domian (Banded Wren Song)
Frequency Domain
2
Power
Amplitude
A
-1
4
6
Sample Number
1
0
x 10
200
1000 1200
Timedomain figure:
g
how a signal
g changes
g over time
Frequencydomain figure: how much of the signal lies within each given
frequency band over a range of frequencies
Fourier Transform
FourierTransform
We can go between the time domain and the frequency domain
byy usingg a tool called Fourier transform
f
AFouriertransformconvertsasignalinthetimedomaintothe
frequencydomain(spectrum)
AninverseFouriertransformconvertsthefrequencydomain
A i
F i
f
h f
d
i
componentsbackintotheoriginaltimedomainsignal
ContinuousTime
Continuous
TimeFourierTransform:
Fourier Transform:
F ( j ) f (t )e
j t
dt
1
f (t )
2
F ( j )e
j t
DiscreteTime
Discrete
TimeFourierTransform(DTFT):
Fourier Transform(DTFT):
X (e
x [ n ]e
j n
x[ n ]
1
2
X (e
)e
j n
Continuestimeperiodicsignal>discretenonperiodic
spectrum
p
Continuestimenonperiodicsignal>continuesnonperiodic
spectrum
Discrete nonperiodic
Discretenon
periodicsignal
signal >>continuesperiodicspectrum
continues periodic spectrum
Discreteperiodicsignal>discreteperiodicspectrum
Thelasttransformationbetweentimedomainandfrequencyismost
q
y
useful
Thereasonthatdiscreteisassociatedwithbothtimedomainandfrequency
p
y
g
domainisbecausecomputerscanonlytakefinitediscretetimesignals
6
Periodic Sequence
PeriodicSequence
A periodic sequence with period N is defined as:
~
x (n) ~
x ( n kN )
, where k is integer
g
For example:
Properties:
W Nkn e
2
kn
N
Periodic
Symmetric
Orthogonal
N 1
n rN
other
ForaperiodicsequencewithperiodN,onlyN
samples
x (n)
areindependent.SothatN sampleinoneperiodisenoughto
represent the whole sequence
representthewholesequence
7
~
X ( k ) DFS ( ~
x ( n ))
~
~
x ( n ) IDFS ( X ( k ))
n0
1 N 1 ~
kn
~
x (n)
X ( k )W N
N n0
~
X (k )
The Fourier series for the discretetime periodic wave shown below:
Sequence x (in time domain)
Fourier Coeffients
0.2
0.5
Amplitude
1
0
-0.2
10
20
time
30
40
-0.4
04
10
20
30
40
x(n)
x(n)
0
0 n N 1
others
~
x ( n ) x ( n rN )
r
x(n)
~
x(n)
RelationshipBetweenFiniteLengthSequence
andPeriodicSequence
d P i di S
A periodic sequence is the periodic extension of a finite length
sequence
~
x (n)
x ( n rN ) x (( n ))
Afinitelengthsequenceistheprincipalvalueintervaloftheperiodic
A
finite length sequence is the principal value interval of the periodic
sequence
0 n N 1
1
x ( n) ~
x ( n) R N ( n)
Where R N (n )
0
Sothat:
others
~
x(n) ~
x ( n ) R N ( n ) IDFS [ X ( k )] R N ( n )
~
X ( k ) X ( k ) R N ( k ) DFS [ ~
x ( n )] R N ( n )
10
X [ k ] x [ n ] e 2 jnk
/N
n0
TheInverseDiscreteFourierTransform(IDFT):
1 N 1
2 jnk
x[ n ]
X [ k ]e
N k 0
/N
, n 0 ,2 , , N 1 .
NotethatbecauseMATLABcannotuseazeroornegative
Note
that because MATLAB cannot use a zero or negative
indices,theindexstartsfrom1inMATLAB
11
DFT Example
DFTExample
TheDFTiswidelyusedinthefieldsofspectralanalysis,
acoustics medical imaging and telecommunications
acoustics,medicalimaging,andtelecommunications.
Time domain signal
6
Forexample:
x [ n ] [ 2 4 1 6 ], N 4 , ( n 0 ,1, 2 , 3 )
3
X [ k ] x [ n ]e
n0
nk
Amplitude
e
4
3
2
1
x [ n ] ( j ) nk
n0
-1
0.5
X [ 0 ] 2 4 ( 1 ) 6 11
1.5
Time
2.5
2.5
X [1 ] 2 ( 4 j ) 1 6 j 3 2 j
X [ 2 ] 2 ( 4 ) ( 1) 6 9
X [3] 2 ( 4 j ) 1 6 j 3 2 j
6
4
2
0
0.5
1.5
Frequency
12
13
N 1
X [ k ] x [ n ] e 2 jnk
/N
n0
N 1
X [ k ] x [ n ]W Nnk
as
n0
nk
It is easy to realize that the same values of W N are calculated many times as the
Itiseasytorealizethatthesamevaluesofarecalculatedmanytimesasthe
computationproceeds
Usingthesymmetricpropertyofthetwiddlefactor,wecansavelotsofcomputations
N 1
X [ k ] x [ n ]W
n0
N 2 1
x ( 2 r )W
x 1 ( r )W
r0
N 2 1
r0
2 kr
N
nk
N
N 1
x ( n )W
n0
even n
N 2 1
kn
N
N 1
x ( n )W Nkn
n0
odd n
x ( 2 r 1 )W Nk ( 2 r 1 )
r0
N 2 1
kr
k
W
N 2
N
r0
x 2 ( r )W Nkr 2
X 1 ( k ) W Nk X 2 ( k )
ThustheNpointDFTcanbeobtainedfromtwoN/2pointtransforms,oneoneven
inputdata,andoneonoddinputdata.
14
Subtraction 6.2 5
* Multiplication 2 * 3
/
Division
5/2
^
Power
3^2
15
Cosine
Sine
Exponential
Square root
abs(x)
angle(x)
conj(x)
log(x)
Absolute value
Phase angle
Complex conjugate
Natural logarithm
>> x = 0:pi/100:2*pi;
p /
p ;
>> y = sin(x);
>> plot(x,y)
0.8
0.6
0.4
Sine of x
0.2
0
-0.2
-0.4
>> xlabel('x=0:2\pi');
\ i
>> ylabel('Sine of x');
>> tile('Sine function')
-0.6
-0.8
-1
x=0:2
x
0:2
18
Amplitude
0.5
0
-0.5
-1
0.2
0.4
0.6
0.8
Time (s)
P
Power
60
40
20
0
10
20
30
40
50
Frequency (Hz)
60
70
80
19
Amplitude
0.5
0
-0.5
-1
0.2
0.4
0.6
0.8
Time (s)
P
Power
60
40
20
0
10
20
30
40
50
Frequency (Hz)
60
70
80
20
Amplitude
0.5
0
-0.5
-1
0.2
0.4
0.6
0.8
Time (s)
P
Power
60
40
20
0
10
20
30
40
50
Frequency (Hz)
60
70
80
21
Amplitude
0.5
0
-0.5
-1
0.2
0.4
0.6
Time (s)
0.8
Power
80
60
40
20
0
20
40
Frequency (Hz)
60
80
22
Amplitude
0.8
0.6
0.4
0.2
0
-0.5
0
Time (s)
0.5
Power
20
15
10
5
0
20
40
Frequency (Hz)
60
80
23
Amplitude
0
-0.5
0
Time (s)
0.5
Powerr
40
30
20
10
0
10
15
20
Frequency (Hz)
25
30
24
Amplitude
1.5
0.5
0.2
0.4
0.6
Time (s)
0.8
P
Power
S
Spectrum
t
off Exponential
E
ti l Decay
D
Si
Signall
70
60
Powe
er
50
40
30
20
10
0
20
40
Frequency (Hz)
60
80
Amplitude
0.5
-0.5
-1
0.2
0.4
0.6
Time (s)
0.8
Power Spectrum
p
of Chirp
p Signal
g
25
Pow
wer
20
15
10
5
0
20
40
60
Frequency (Hz)
80
100
26