Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

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
1
A fundamental and three odd harmonics (3,5,7)
fund (freq 100)
3rd harm
5th harm
7th harmm
0 20 40 60 80 100 120 140 160 180 200
1
0.5
0
0.5
1
Sum of odd harmonics approximate square wave
fund (freq 100)
fund+3rd harm
fund+3rd+5th
fund+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
1
Sum of odd harmonics from 1 to 127
A Tutorial on Fourier Analysis
Linear Combination
In the interval [u
1
, u
2
] a function (u) can be written as a linear
combination:
(u) =

i =0

i
(u)
where functions
i
(u) make up a set of simple elementary
functions. If functions are orthogonal (roughly, perpindicular; inner
product is zero)then coecients
i
are independant from one
another.
A Tutorial on Fourier Analysis
Continuous Fourier Transform
The most commonly used set of orthogonal functions is the Fourier
series. Here is the analog version of the Fourier and Inverse Fourier:
X(w) =

x(t)e
(2jwt)
dt
x(t) =

X(w)e
(2jwt)
dw
A Tutorial on Fourier Analysis
Discrete Fourier and Inverse Fourier Transform
X(n) =
N1

k=0
x(k)e
2jnk/N
x(k) =
1
N
N1

n=0
X(n)e
2jnk/N
A Tutorial on Fourier Analysis
Taylor Series Expansion
f (x) = f (x
0
)+
f

(x
0
)
1
(xx
0
)+
f

(x
0
)
1 2
(xx
0
)
2
+
f

(x
0
)
1 2 3
(xx
0
)
3
+...
or more compactly as
f (x) =

n=0
f
(n)
(x
0
)
n!
(x x
0
)
n
A Tutorial on Fourier Analysis
Taylor series expansion of e
j
Since e
x
is its own derivative, the Taylor series expansion for
f (x) = e
x
is very simple:
e
x
=

n=0
x
n
n!
= 1 + x +
x
2
2
+
x
3
3!
+ ...
We can dene:
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)
(n1)/2
n!

n
Thus yielding Eulers 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 coecients 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
1
FFT projected onto unit circle
A Tutorial on Fourier Analysis
Impulse response
0 10 20 30 40 50 60 70 80 90 100
0
0.5
1
signal
0 10 20 30 40 50 60 70 80 90 100
0.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 100
0
0.5
1
signal
0 10 20 30 40 50 60 70 80 90 100
0.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 100
49.5361
49.5361
49.5361
49.5361
m
a
g
n
i
t
u
d
e
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
a
n
g
l
e

f
r
e
q
=
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.5
0
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
1
cos(21)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1
0
1
cos(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
1
cos(45)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1
0
1
cos(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
1
cos(3)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1
0
1
cos(3) sampled at 24 Hz
A Tutorial on Fourier Analysis
Leakage
Even below Nyquist, when frequencies in the signal do not align
well with sampling rate of signal, there can be leakage. First
consider a well-aligned exampl (freq = .25 sampling rate)
0 10 20 30 40 50 60 70
1
0.5
0
0.5
1
Sinusoid at 1/4 the Sampling Rate
Time (samples)
A
m
p
l
i
t
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
40
Normalized Frequency (cycles per sample))
M
a
g
n
i
t
u
d
e

(
L
i
n
e
a
r
)
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))
M
a
g
n
i
t
u
d
e

(
d
B
)
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
1
Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
A
m
p
l
i
t
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
Normalized Frequency (cycles per sample))
M
a
g
n
i
t
u
d
e

(
L
i
n
e
a
r
)
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))
M
a
g
n
i
t
u
d
e

(
d
B
)
c)
A Tutorial on Fourier Analysis
Leakage
Comparison:
0 10 20 30 40 50 60 70
1
0.5
0
0.5
1
Sinusoid at 1/4 the Sampling Rate
Time (samples)
A
m
p
lit
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
40
Normalized Frequency (cycles per sample))
M
a
g
n
it
u
d
e

(
L
in
e
a
r
)
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))
M
a
g
n
it
u
d
e

(
d
B
)
c)
0 10 20 30 40 50 60 70
1
0.5
0
0.5
1
Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
A
m
p
lit
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
Normalized Frequency (cycles per sample))
M
a
g
n
it
u
d
e

(
L
in
e
a
r
)
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))
M
a
g
n
it
u
d
e

(
d
B
)
c)
A Tutorial on Fourier Analysis
Windowing can help
Can minimize eects by multiplying time series by a window that
diminishes magnitude of points near signal edge:
0 10 20 30 40 50 60 70
0
0.5
1
Blackman Window
Time (samples)
A
m
p
l
i
t
u
d
e
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))
M
a
g
n
i
t
u
d
e

(
d
B
)
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))
M
a
g
n
i
t
u
d
e

(
d
B
)
c)
A Tutorial on Fourier Analysis
Leakage Reduced
Comparison:
0 10 20 30 40 50 60 70
1
0.5
0
0.5
1
Sinusoid NEAR 1/4 the Sampling Rate
Time (samples)
A
m
p
lit
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
10
20
30
Normalized Frequency (cycles per sample))
M
a
g
n
it
u
d
e

(
L
in
e
a
r
)
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))
M
a
g
n
it
u
d
e

(
d
B
)
c)
0 10 20 30 40 50 60 70
1
0.5
0
0.5
1
Sinusoid at 1/4 the Sampling Rate
Time (samples)
A
m
p
lit
u
d
e
a)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
5
10
15
Normalized Frequency (cycles per sample))
M
a
g
n
it
u
d
e

(
L
in
e
a
r
)
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))
M
a
g
n
it
u
d
e

(
d
B
)
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 frequency
domain 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 unit
impulse function.
A Tutorial on Fourier Analysis
Using the impulse response
Once computed, the impulse response can be used to lter any
signal 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
Diculties (Why not a perfect lter?)
You can have a perfect lter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Diculties (Why not a perfect lter?)
You can have a perfect lter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Diculties (Why not a perfect lter?)
You can have a perfect lter(!)
Need long impulse response function in both directions
Very non causal
In generating causal version, challenges arise
A Tutorial on Fourier Analysis
Diculties (Why not a perfect lter?)
You can have a perfect lter(!)
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 500
0
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 500
0
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 over
time
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge eects
A Tutorial on Fourier Analysis
Spectral Analysis
Often we want to see spectral energy as a signal evolves over
time
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge eects
A Tutorial on Fourier Analysis
Spectral Analysis
Often we want to see spectral energy as a signal evolves over
time
Compute Fourier Transform over evenly-spaced frames of data
Apply window to minimize edge eects
A Tutorial on Fourier Analysis
Short-Timescale Fourier Transform (STFT)
X(m, n) =
N1

k=0
x(k)w(k m)e
2jnk/N
Where w is some windowing function such as Hanning or gaussian
centered around zero.
The spectrogram is simply the squared magnitude of these STFT
values
A Tutorial on Fourier Analysis
Trumpet (G4)
Time
F
r
e
q
u
e
n
c
y
0 1 2 3 4 5 6
0
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Violin (G4)
Time
F
r
e
q
u
e
n
c
y
0 0.5 1 1.5 2 2.5 3
0
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Flute (G4)
Time
F
r
e
q
u
e
n
c
y
0 0.5 1 1.5 2 2.5
0
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Piano (G4)
Time
F
r
e
q
u
e
n
c
y
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
0
1000
2000
3000
4000
5000
[Listen]
A Tutorial on Fourier Analysis
Voice
Time
F
r
e
q
u
e
n
c
y
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
1000
2000
3000
4000
5000
6000
7000
8000
[Listen]
A Tutorial on Fourier Analysis
C Major Scale (Piano)
Time
F
r
e
q
u
e
n
c
y
0 1 2 3 4 5 6 7 8
0
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-frequency
structure
Time
F
r
e
q
u
e
n
c
y
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 Tradeo
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
A
m
p
.
spoken "Steven Usma"
A Tutorial on Fourier Analysis
Time-Space Tradeo
Time
F
r
e
q
u
e
n
c
y
Narrowband Spectrogram overlap=152 timepts=1633
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
1000
2000
3000
4000
Time
F
r
e
q
u
e
n
c
y
Wideband Spectrogram overlap=30 timepts=6593
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
1000
2000
3000
4000
A Tutorial on Fourier Analysis
Auto-correlation and meter
Autocorrelation long used to nd meter in music (Brown 1993)
Lag k auto-correlation a(k) is a special case of cross-correlation
where a signal x is correlated with itself:
a(k) =
1
N
N1

n=k
x(n) x(n k)
Autocorrelation can also be dened in terms of Fourier analysis
a = F
1
(|F(x)|)
where F is the Fourier transform, F
1
is the inverse Fourier
transform and || indicates taking magnitude from a complex value.
A Tutorial on Fourier Analysis
Auto-correlation and meter
Autocorrelation long used to nd meter in music (Brown 1993)
Lag k auto-correlation a(k) is a special case of cross-correlation
where a signal x is correlated with itself:
a(k) =
1
N
N1

n=k
x(n) x(n k)
Autocorrelation can also be dened in terms of Fourier analysis
a = F
1
(|F(x)|)
where F is the Fourier transform, F
1
is the inverse Fourier
transform and || indicates taking magnitude from a complex value.
A Tutorial on Fourier Analysis
0 5 10 15 20 25 30
time (seconds)
0 5 10 15 20 25 30
time (seconds)
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
lags (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(N
2
)
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 order
Output transformation (Decimation in Time)

You might also like