discrete fourier transform (dft)
DESCRIPTION
Discrete Fourier Transform (DFT). Jyh-Shing Roger Jang ( 張智星 ) MIR Lab ( 多媒體資訊檢索實驗室 ) CSIE, NTU ( 台灣大學 資訊工程系 ) [email protected] , http://mirlab.org/jang. Discrete Fourier Transform. Goal - PowerPoint PPT PresentationTRANSCRIPT
Discrete Fourier Transform (DFT)
Jyh-Shing Roger Jang ( 張智星 )MIR Lab ( 多媒體資訊檢索實驗室 )
CSIE, NTU ( 台灣大學 資訊工程系 )[email protected], http://mirlab.org/jang
-2-
Discrete Fourier Transform
Goal Decompose a given vector of discrete signals into sinusoidal components whose amplitudes can be view as energy distribution over a range of frequencies
Applications Speech recognition Digital filtering Many many more...
-3-
Decomposition
Given xn=x(n/fs), n=0~N-1, we want to decompose x(t) into a linear combination of sinusoidal functions.
Magnitude spectrum Phase spectrum
Remaining problems To determine no. of terms and their frequencies
444333122111 2cos2cos2cos2cos)( tfmtfmtfmtfmtx
4321 ,,, mmmm
4321 ,,,
-4-
Bin Frequencies
Frequencies of these sinusoidal basis functions (aka “bin frequencies”):
/ / 2/ 2 / 3: , , , , ,
/ 22 3: 0, , , , ,
s s s s
ss s s
N NN N NPeriods
f f f f
N ff f fFrequencies
N N N N
fsNfsfsfstime
Nindex
/)1(/2/1/0:
1210:
-5-
Sinusoidal Basis Functions (1/2)
1
2
3
4
5
6
7
sin 2
2 2/ 2sin 2
3 3/ 3sin 2
4 4/ 4sin 2
5 5/ 5sin 2
6 6/ 6sin 2
7 7/ 7sin 2
s s
s
s s
s
s s
s
s s
s
s s
s
s s
s
s s
s
T f Basis
f fNt
f N N
f fNt
f N N
f fNt
f N N
f fNt
f N N
f fNt
f N N
f fNt
f N N
f fNt
f N N
N
8
8 8/ 8sin 2s s
s
f ft
f N N
1,16,8~1,2sin
ss fNktN
kf
0 2 4 6 8 10 12 14 16-1
0
1
k=1
N=16, fs=1
0 2 4 6 8 10 12 14 16-1
0
1
k=2
0 2 4 6 8 10 12 14 16-1
0
1
k=3
0 2 4 6 8 10 12 14 16-1
0
1
k=4
0 2 4 6 8 10 12 14 16-1
0
1
k=5
0 2 4 6 8 10 12 14 16-1
0
1
k=6
0 2 4 6 8 10 12 14 16-1
0
1
k=7
0 2 4 6 8 10 12 14 16-1
0
1
k=8
Time (sec)
-6-
Sinusoidal Basis Functions (2/2)
, 0 1
, cos 2 ,sin 2
2 2 2/ 2, cos 2 ,sin 2
3 3 3/ 3, cos 2 ,sin 2
/, cos 2 ,sin 2
s s s
s
s s s
s
s s s
s
s s s
s
T f
f f fNT f t t
f N N N
f f fNT f t t
f N N N
f f fNT f t t
f N N N
kf kf kfN kT f t t
f N N N
T
/ ( / 2), cos 2 ,sin 2
2 2 2s s s
s
f f fN Nf t t
f
0 2 4 6 8 10 12 14 16-1
0
1
k=
1
N=16, fs=1
0 2 4 6 8 10 12 14 16-1
0
1
k=
2
0 2 4 6 8 10 12 14 16-1
0
1
k=
3
0 2 4 6 8 10 12 14 16-1
0
1
k=
4
0 2 4 6 8 10 12 14 16-1
0
1
k=
5
0 2 4 6 8 10 12 14 16-1
0
1
k=
6
0 2 4 6 8 10 12 14 16-1
0
1
k=
7
0 2 4 6 8 10 12 14 16-1
0
1
k=
8
Time (sec)
1,16,8~1,2cos
ss fNktN
kf
-7-
Decomposition into Basis Functions
0
1 1
2 2
3 3
/2 /2
( )
cos 2 sin 2
2 2cos 2 sin 2
3 3cos 2 sin 2
cos 2 sin 2
cos 2 sin 22 2
s s
s s
s s
s sk k
s sN N
x t a
f fa t b t
N N
f fa t b t
N N
f fa t b t
N N
kf kfa t b t
N N
f fa t b t
0
1 1
2 2
3 3
2
( / )
2 2cos 1 sin 1
2 2cos 2 sin 2
2 2cos 3 sin 3
2 2cos sin
cos
n s
k k
N
x x t n f a
n na b
N N
n na b
N N
n na b
N N
n na k b k
N N
a n
No. of modifiable parameters = N
-8-
Decomposition into Basis Functions
Overall expression:
No. of parameters is 1+2*(N/2-1)+1=N, which is equal to the no. of data points Exact solution is likely to exist.
12
01 2
12
2 20
1 2
2 2cos sin cos , 1 ~ 1
2cos cos
N
n k k Nk
N
k k k Nk
n nx a a k b k a n n N
N N
na a b k a n
N
Amplitude PhaseFreq= /skf N
-9-
Parameter Identification
How to identify coefficients of the basis functions: Fast Fourier transform (FFT)
A fast algorithm with a complexity of O(n log n)
Solving simultaneous linear equations Integration (which take advantage of the
orthogonality of the basis functions)
-11-
Frequencies of Basis Functions
Due to Euler identity, we can express the k-th term shown on the right.
2 2
2 2
2 2
2 2cos sin
2,
2 2
1 1
2 2
1 1
2 2
1 1
2 2
k k
j j j j
k k
j jk k k k
n nj k j kN N
k k k k
n nj k j N kN N
k k k k
n nj k j N kN N
k N k
n nk th term a k b k
N N
e e e e na b with k
j N
a b j e a b j e
a b j e a b j e
a b j e a b j e
c e c e
:
cos sin
cos sin
cos / 2
sin / 2
j
j
j j
j j
Euler Identity
e j
e j
e e
e e j
-12-
Frequencies of Basis Functions
Plug in the simplified k-th term:
Include the first and last terms:
2 21
0 /21 0
0 0
/2 /2
cos
1, 1 ~ / 2 1
2
1, / 2 1 ~ 1
2
n nN Nj k j kN N
n k N kk k
k k k
N N
k k k
x a c e a n c e
where
c a
c a b j k N
c a
c a b j k N N
0
2 21 1
1 1
2 22 2
2 2
2 23 3
3 3
2 2
/2
21
0 /21
cos
cos
n
n nj j NN N
N
n nj j NN N
N
n nj j NN N
N
n nj k j N kN N
k N k
N
nN j kN
k Nk
x a
c e c e
c e c e
c e c e
c e c e
a n
a c e a n
-13-
Representations of DFT: Two-side
Characteristics General representation If x is complex, then c is not conjugate symmetric MATLAB command: c=fft(x)
0 1 2 1 0 1 2 1[ , , , ] [ , , , ]fft
N Nx x x x x c c c c c
-14-
Representations of DFT: One-side
Characteristics When x is real, c is conjugate symmetric and we
only have to look at one-side of FFT result. MATLAB command: magSpec=fftOneside(x)
0 1 2 3 /2 1 /2 /2 1 3 2 1[ , , , , , , , , , , , ]N N N N N Nc c c c c c c c c c
Real Real
Complexconjugate
-15-
Representations of DFT: One-side
Formulas
0 1 2 1
0 1 2 /2 1 /2
0 1 2 /2 1 /2
2 2 2 2 2 20 1 1 2 2 /2 1 /2 1 /2
, , ,
/ 22 3,2 ,2 , 2 , at bin frequencies 0, , , ,...,
Magnitude spectrum , 2 , 2 , 2 ,
, , , ,
Power spectru
N
ss s sN N
N N
N N N
x x x x x
N ff f fc c c c c c
N N N N
c c c c c
a a b a b a b a
10 0 1 2 /2 1 /2
2 2 2 2 2 210 0 10 1 1 10 2 2 10 /2 1 /2 1 10 /2
m 20log , 2 , 2 , 2 ,
20log ,10log ,10log , 10log ,20log
N N
N N N
c c c c c
a a b a b a b a
-16-
Example: Conjugate Symmetric
Conjugate symmetric of DFT for real x fftSym01.m
-17-
Example: Two-side FFT
Two-side FFT of a pure sinusoid at one of the bin freqency fft01.m
-18-
Example: Two-side FFT
Two-side FFT of a pure sinusoid NOT at one of the bin freqency fft02.m
-19-
Example: One-side FFT
One-side FFT of a pure sinusoid NOT at one of the bin freqency fft03.m
-20-
Example: One-side FFT
One-side FFT of a frame of audio signals fft04.m
-21-
Example: FFT for Data Compression
Use partial coefficients to reconstruct the original signals fftApproximate01.m High-frequency
components are not so important
-22-
Example: FFT for Data Compression
Use low-freq components to reconstruct a frame fftApproximate01.m
-23-
Example: FFT for Periodic Signals
FFT on periodic signals fftRepeat01.m Useful for pitch tracking Intepretation of
harmonics from viewpoints ofIntegration for obtaining
the coefficientsApproximation by basis
functions
-24-
Example: Zero-padding for FFT
Zero-padding Purpose
Easier for FFTInterpolation
fftRepeat01.m
-25-
Example: Down-sampling
Down sampling High-frequency
components are missing fftResample01.m
-26-
Harmonics
Why do we have harmonic structures in a power spectrum? Since the original frame is quasi-periodic…
If we want to use the spectrum for pitch tracking, we need to enhance the harmonics. How?
-27-
How to Enhance Harmonics?
Goal Enhance harmonics for pitch tracking
Approach Take an integer number of fundamental periods
Hard! Use windowing Use zero-padding for better resolution
-28-
Example: Harmonics Enhancement (1)
fftHarmonics01.m
0 100 200 300-1
-0.5
0
0.5
1Frame 1 (length=256)
Am
plitu
de
0 100 200 300-1
-0.5
0
0.5
1Frame 2 (length=238)
Am
plitu
de
0 1000 2000 3000 4000-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 1
0 1000 2000 3000 4000-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 2
-29-
Example: Harmonics Enhancement (2)
fftHarmonics02.m
0 100 200 300-1
-0.5
0
0.5
1Frame 1 (length=256)
Am
plitu
de
0 100 200 300-1
-0.5
0
0.5
1Frame 2 (length=256)
Am
plitu
de
0 1000 2000 3000 4000-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 1
0 1000 2000 3000 4000-100
-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 2
-30-
Example: Harmonics Enhancement (3)
fftHarmonics03.m
0 100 200 300-1
-0.5
0
0.5
1Frame 1 (length=256)
Am
plitu
de
0 1000 2000 3000-1
-0.5
0
0.5
1Frame 2 (length=2048)
Am
plitu
de
0 1000 2000 3000 4000-100
-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 1
0 1000 2000 3000 4000-100
-50
0
50
100
Frequency (Hz)
Pow
er (
db)
Power spectrum 2