A Tutorial on Fourier Analysis
A Tutorial on Fourier Analysis
Douglas Eck
University of Montreal
NYU March 2006
A Tutorial on Fourier Analysis
0 20 40 60 80 100 120 140 160 180 200−1
−0.5
0
0.5
1A fundamental and three odd harmonics (3,5,7)
fund (freq 100)3rd harm5th harm7th harmm
0 20 40 60 80 100 120 140 160 180 200−1
−0.5
0
0.5
1Sum of odd harmonics approximate square wave
fund (freq 100)fund+3rd harmfund+3rd+5thfund+3rd+5th+7th
A Tutorial on Fourier Analysis
0 20 40 60 80 100 120 140 160 180 200−1
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1Sum of odd harmonics from 1 to 127
A Tutorial on Fourier Analysis
Linear Combination
In the interval [u1, u2] a function Θ(u) can be written as a linearcombination:
Θ(u) =∞∑i=0
αiψi (u)
where functions ψi (u) make up a set of simple elementaryfunctions. If functions are orthogonal (roughly, perpindicular; innerproduct is zero)then coefficients αi are independant from oneanother.
A Tutorial on Fourier Analysis
Continuous Fourier Transform
The most commonly used set of orthogonal functions is the Fourierseries. Here is the analog version of the Fourier and Inverse Fourier:
X (w) =
∫ +∞
−∞x(t)e(−2πjwt)dt
x(t) =
∫ +∞
−∞X (w)e(2πjwt)dw
A Tutorial on Fourier Analysis
Discrete Fourier and Inverse Fourier Transform
X (n) =N−1∑k=0
x(k)e−2πjnk/N
x(k) =1
N
N−1∑n=0
X (n)e2πjnk/N
A Tutorial on Fourier Analysis
Taylor Series Expansion
f (x) = f (x0)+f ′(x0)
1(x−x0)+
f ′′(x0)
1 ∗ 2(x−x0)
2+f ′′′(x0)
1 ∗ 2 ∗ 3(x−x0)
3+...
or more compactly as
f (x) =∞∑
n=0
f (n)(x0)
n!(x − x0)
n
A Tutorial on Fourier Analysis
Taylor series expansion of e jΘ
Since ex is its own derivative, the Taylor series expansion forf (x) = ex is very simple:
ex =∞∑
n=0
xn
n!= 1 + x +
x2
2+
x3
3!+ ...
We can define:
e jΘ ==∞∑
n=0
(jΘ)n
n!= 1 + jΘ− Θ2
2− j
Θ3
3!+ ...
A Tutorial on Fourier Analysis
Splitting out real and imaginary parts
All even order terms are real; all odd-order terms are imaginary:
ree jΘ = 1−Θ2/2 + Θ4/4!− ...
ime jΘ = Θ−Θ3/3! + Θ5/5!− ...
A Tutorial on Fourier Analysis
Fourier Transform as sum of sines and cosines
Observe that:
cos(Θ) =∞∑
n>=0;n is even
(−1)n/2
n!Θn
sin(Θ) =∞∑
n>=0;n is odd
(−1)(n−1)/2
n!Θn
Thus yielding Euler’s formula:
e jθ = cos(Θ) + j sin(Θ)
A Tutorial on Fourier Analysis
A Tutorial on Fourier Analysis
Fourier transform as kernel matrix
A Tutorial on Fourier Analysis
Example
Sum of cosines with frequencies 12 and 9, sampling rate = 120
0 20 40 60 80 100 120−0.02
−0.01
0
0.01
0.02
signal
0 20 40 60 80 100 120−0.5
0
0.5
1
real part
0 20 40 60 80 100 120−0.2
−0.1
0
0.1
0.2
imag part
two cosines (freqs=9, 12)
A Tutorial on Fourier Analysis
Example
FFT coefficients mapped onto unit circle
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1−1
−0.8
−0.6
−0.4
−0.2
0
0.2
0.4
0.6
0.8
1FFT projected onto unit circle
A Tutorial on Fourier Analysis
Impulse response
0 10 20 30 40 50 60 70 80 90 1000
0.5
1
signal
0 10 20 30 40 50 60 70 80 90 1000.01
0.01
0.01
magnitude
impulse response
0 10 20 30 40 50 60 70 80 90 100−1
−0.5
0
0.5
1
phase
A Tutorial on Fourier Analysis
Impulse response
0 10 20 30 40 50 60 70 80 90 1000
0.5
1
signal
0 10 20 30 40 50 60 70 80 90 1000.01
0.01
0.01
magnitude
delayed impulse response
0 10 20 30 40 50 60 70 80 90 100−4
−2
0
2
4
phase
A Tutorial on Fourier Analysis
A look at phase shifting
Sinusoid frequency=5 phase shifted multiple times.
0 10 20 30 40 50 60 70 80 90 10049.5361
49.5361
49.5361
49.5361
mag
nitu
de
number of points shifted
sinusoid freq=5 phase shifted repeatedly
0 10 20 30 40 50 60 70 80 90 100−3
−2
−1
0
1
2
3
angl
e fr
eq=
6
number of points shifted
A Tutorial on Fourier Analysis
Sin period 10 + period 30
−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.50
100
200
freq (mag)
−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.5−5
0
5
phase
0 100 200 300 400 500 600−1
0
1
component sinusoids
0 100 200 300 400 500 600−5
0
5
reconstructed signal using component sinusoids vs original
0 100 200 300 400 500 600−2
0
2
reconstructed signal using ifft vs original
A Tutorial on Fourier Analysis
Aliasing
The useful range is the “Nyquist frequency” (fs/2)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(21)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(21) sampled at 24 Hz
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(45)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(45) sampled at 24 Hz
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(−3)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1
0
1cos(−3) sampled at 24 Hz
A Tutorial on Fourier Analysis
Leakage
Even below Nyquist, when frequencies in the signal do not alignwell with sampling rate of signal, there can be “leakage”. Firstconsider a well-aligned exampl (freq = .25 sampling rate)
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid at 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
40
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−300
−200
−100
0
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
A Tutorial on Fourier Analysis
Leakage
Now consider a poorly-aligned example (freq = (.25 + .5/N) *sampling rate)
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)
b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−10
0
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
A Tutorial on Fourier Analysis
Leakage
Comparison:
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid at 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
40
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
−300
−200
−100
0
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)
b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−10
0
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
A Tutorial on Fourier Analysis
Windowing can help
Can minimize effects by multiplying time series by a window thatdiminishes magnitude of points near signal edge:
0 10 20 30 40 50 60 700
0.5
1Blackman Window
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−100
−50
0
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
b)
−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.5−100
−50
0
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
A Tutorial on Fourier Analysis
Leakage Reduced
Comparison:
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)
b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−10
0
10
20
30
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
0 10 20 30 40 50 60 70−1
−0.5
0
0.5
1Sinusoid at 1/4 the Sampling Rate
Time (samples)
Am
plitu
de
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
5
10
15
Normalized Frequency (cycles per sample))
Mag
nitu
de (
Line
ar)
b)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−80
−60
−40
−20
0
20
Normalized Frequency (cycles per sample))
Mag
nitu
de (
dB)
c)
A Tutorial on Fourier Analysis
Convolution theorem
This can be understood in terms of the Convolution Theorem.Convolution in the time domain is multiplication in the frequencydomain via the Fourier transform (F).
F(f ∗ g) = F(f )×F(g)
A Tutorial on Fourier Analysis
Computing impulse response
The impulse response h[n] is the response of a system to the unitimpulse function.
A Tutorial on Fourier Analysis
Using the impulse response
Once computed, the impulse response can be used to filter anysignal x [n] yielding y [n].
A Tutorial on Fourier Analysis
Examples
A Tutorial on Fourier Analysis
Filtering using DFT
Goal is to choose good impulse response h[n]
Transform signal into frequency domain
Modify frequency properties of signal via multiplication
Transform back into time domain
A Tutorial on Fourier Analysis
Filtering using DFT
Goal is to choose good impulse response h[n]
Transform signal into frequency domain
Modify frequency properties of signal via multiplication
Transform back into time domain
A Tutorial on Fourier Analysis
Filtering using DFT
Goal is to choose good impulse response h[n]
Transform signal into frequency domain
Modify frequency properties of signal via multiplication
Transform back into time domain
A Tutorial on Fourier Analysis
Filtering using DFT
Goal is to choose good impulse response h[n]
Transform signal into frequency domain
Modify frequency properties of signal via multiplication
Transform back into time domain
A Tutorial on Fourier Analysis
Difficulties (Why not a perfect filter?)
You can have a perfect filter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Difficulties (Why not a perfect filter?)
You can have a perfect filter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Difficulties (Why not a perfect filter?)
You can have a perfect filter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Difficulties (Why not a perfect filter?)
You can have a perfect filter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Gibbs Phenomenon
−500 −400 −300 −200 −100 0 100 200 300 400 5000
0.5
1
ideal lopass filter in frequency domain
−500 −400 −300 −200 −100 0 100 200 300 400 500−0.1
0
0.1
ideal filter coeffs in time domain
0 100 200 300 400 500 600 700 800 900 1000−0.1
0
0.1
truncated causal filter
−500 −400 −300 −200 −100 0 100 200 300 400 5000
0.5
1
1.5
Gibbs phenomenon
A Tutorial on Fourier Analysis
Spectral Analysis
Often we want to see spectral energy as a signal evolves overtime
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge effects
A Tutorial on Fourier Analysis
Spectral Analysis
Often we want to see spectral energy as a signal evolves overtime
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge effects
A Tutorial on Fourier Analysis
Spectral Analysis
Often we want to see spectral energy as a signal evolves overtime
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge effects
A Tutorial on Fourier Analysis
Short-Timescale Fourier Transform (STFT)
X (m, n) =N−1∑k=0
x(k)w(k −m)e−2πjnk/N
Where w is some windowing function such as Hanning or gaussiancentered around zero.The spectrogram is simply the squared magnitude of these STFTvalues
A Tutorial on Fourier Analysis
Trumpet (G4)
Time
Fre
quen
cy
0 1 2 3 4 5 60
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Violin (G4)
Time
Fre
quen
cy
0 0.5 1 1.5 2 2.5 30
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Flute (G4)
Time
Fre
quen
cy
0 0.5 1 1.5 2 2.50
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Piano (G4)
Time
Fre
quen
cy
0 0.1 0.2 0.3 0.4 0.5 0.6 0.70
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Voice
Time
Fre
quen
cy
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20
1000
2000
3000
4000
5000
6000
7000
8000
[Listen]
A Tutorial on Fourier Analysis
C Major Scale (Piano)
Time
Fre
quen
cy
0 1 2 3 4 5 6 7 80
2000
4000
6000
8000
10000
12000
14000
16000
[Listen]
A Tutorial on Fourier Analysis
C Major Scale (Piano)
Log Spectrogram (Constant-Q Transform) reveals low-frequencystructure
Time
Fre
quen
cy
0 1 2 3 4 5 6 7 8
135
240
427
761
1356
2416
4305
7671
13669
A Tutorial on Fourier Analysis
Time-Space Tradeoff
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
−0.4
−0.2
0
0.2
0.4
0.6
Am
p.
spoken "Steven Usma"
A Tutorial on Fourier Analysis
Time-Space Tradeoff
Time
Fre
quen
cy
Narrowband Spectrogram overlap=152 timepts=1633
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60
1000
2000
3000
4000
Time
Fre
quen
cy
Wideband Spectrogram overlap=30 timepts=6593
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60
1000
2000
3000
4000
A Tutorial on Fourier Analysis
Auto-correlation and meter
Autocorrelation long used to find meter in music (Brown 1993)Lag k auto-correlation a(k) is a special case of cross-correlationwhere a signal x is correlated with itself:
a(k) =1
N
N−1∑n=k
x(n) x(n − k)
Autocorrelation can also be defined in terms of Fourier analysis
a = F−1(|F(x)|)
where F is the Fourier transform, F−1 is the inverse Fouriertransform and || indicates taking magnitude from a complex value.
A Tutorial on Fourier Analysis
Auto-correlation and meter
Autocorrelation long used to find meter in music (Brown 1993)Lag k auto-correlation a(k) is a special case of cross-correlationwhere a signal x is correlated with itself:
a(k) =1
N
N−1∑n=k
x(n) x(n − k)
Autocorrelation can also be defined in terms of Fourier analysis
a = F−1(|F(x)|)
where F is the Fourier transform, F−1 is the inverse Fouriertransform and || indicates taking magnitude from a complex value.
A Tutorial on Fourier Analysis
0 5 10 15 20 25 30time (seconds)
0 5 10 15 20 25 30time (seconds)
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000lags (ms)
Time series (top), envelope (middle) and autocorrelation (bottom) of
excerpt from ISMIR 2004 Tempo Induction contest
(Albums-Cafe Paradiso-08.wav). A vertical line marks the actual tempo
(484 msec, 124bpm). Stars mark the tempo and its integer multiples.
Triangles mark levels in the metrical hierarchy.
A Tutorial on Fourier Analysis
Fast Fourier Transform
Fourier Transform O(N2)
Fast version possible O(NlogN)
Size must be a power of two
Strategy is decimation in time or frequency
Divide and conquer
Rearrange the inputs in bit reversed orderOutput transformation (Decimation in Time)