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

A fundamental and three odd harmonics (3,5,7)


1
fund (freq 100)
3rd harm
5th harm
7th harmm

0.5

0.5

20

40

60

80

100

120

140

160

180

200

Sum of odd harmonics approximate square wave


1
fund (freq 100)
fund+3rd harm
fund+3rd+5th
fund+3rd+5th+7th

0.5

0.5

20

40

60

80

100

120

140

160

180

200

A Tutorial on Fourier Analysis

Sum of odd harmonics from 1 to 127


1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

20

40

60

80

100

120

140

160

180

200

A Tutorial on Fourier Analysis

Linear Combination

In the interval [u1 , u2 ] a function (u) can be written as a linear


combination:
(u) =

i i (u)

i=0

where functions i (u) make up a set of simple elementary


functions. If functions are orthogonal (roughly, perpindicular; inner
product is zero)then coefficients 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:
Z +
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
X

x(k)e 2jnk/N

k=0

x(k) =

N1
1 X
X (n)e 2jnk/N
N
n=0

A Tutorial on Fourier Analysis

Taylor Series Expansion

f (x) = f (x0 )+

f 0 (x0 )
f 00 (x0 )
f 000 (x0 )
(xx0 )+
(xx0 )2 +
(xx0 )3 +...
1
12
123

or more compactly as
f (x) =

X
f (n) (x0 )
n=0

n!

(x x0 )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:
ex =

X
xn
n=0

n!

=1+x +

x2 x3
+
+ ...
2
3!

We can define:
e j ==

X
(j)n
n=0

n!

= 1 + j

2
3
j
+ ...
2
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

sin() =

X
n>=0;n is odd

(1)n/2 n

n!

(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.02
0.01
0
0.01
0.02

20

40

60
signal

80

100

120

20

40

60
real part
two cosines (freqs=9, 12)

80

100

120

20

40

60
imag part

80

100

120

1
0.5
0
0.5

0.2
0.1
0
0.1
0.2

A Tutorial on Fourier Analysis

Example
FFT coefficients mapped onto unit circle
FFT projected onto unit circle
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

A Tutorial on Fourier Analysis

Impulse response
impulse response
1

0.5

10

20

30

40

50
signal

60

70

80

90

100

10

20

30

40

50
magnitude

60

70

80

90

100

10

20

30

40

50
phase

60

70

80

90

100

0.01

0.01

0.01

1
0.5
0
0.5
1

A Tutorial on Fourier Analysis

Impulse response
delayed impulse response
1

0.5

10

20

30

40

50
signal

60

70

80

90

100

10

20

30

40

50
magnitude

60

70

80

90

100

10

20

30

40

50
phase

60

70

80

90

100

0.01

0.01

0.01

4
2
0
2
4

A Tutorial on Fourier Analysis

A look at phase shifting


Sinusoid frequency=5 phase shifted multiple times.
sinusoid freq=5 phase shifted repeatedly

49.5361

49.5361

49.5361

10

20

30

40
50
60
number of points shifted

70

80

90

100

10

20

30

40
50
60
number of points shifted

70

80

90

100

3
2
angle freq=6

magnitude

49.5361

1
0
1
2
3

A Tutorial on Fourier Analysis

Sin period 10 + period 30


200
100
0
0.5

0.4

0.3

0.2

0.1

0
freq (mag)

0.1

0.2

0.3

0.4

0.5

0.4

0.3

0.2

0.1

0
phase

0.1

0.2

0.3

0.4

0.5

5
0
5
0.5
1
0
1

100

100

100

200

300
component sinusoids

400

500

600

200
300
400
500
reconstructed signal using component sinusoids vs original

600

5
0
5
2
0
2

200
300
400
reconstructed signal using ifft vs original

500

600

A Tutorial on Fourier Analysis

Aliasing
The useful range is the Nyquist frequency (fs/2)
cos(21)
1
0
1

0.1

0.2

0.3

0.1

0.2

0.3

0.1

0.2

0.3

0.1

0.2

0.3

0.1

0.2

0.3

0.1

0.2

0.3

0.4
0.5
0.6
cos(21) sampled at 24 Hz

0.7

0.8

0.9

0.7

0.8

0.9

0.7

0.8

0.9

0.7

0.8

0.9

0.7

0.8

0.9

0.7

0.8

0.9

1
0
1

0.4

0.5
cos(45)

0.6

1
0
1

0.4
0.5
0.6
cos(45) sampled at 24 Hz

1
0
1

0.4

0.5
cos(3)

0.6

1
0
1

0.4
0.5
0.6
cos(3) sampled at 24 Hz

1
0
1

0.4

0.5

0.6

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)
Sinusoid at 1/4 the Sampling Rate
a)
Amplitude

1
0.5
0
0.5
1

Magnitude (Linear)

b)

10

20

30
40
Time (samples)

50

60

70

40
30
20
10
0

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

Magnitude (dB)

c)
0
100
200
300

A Tutorial on Fourier Analysis

Leakage
Now consider a poorly-aligned example (freq = (.25 + .5/N) *
sampling rate)
Sinusoid NEAR 1/4 the Sampling Rate
a)
Amplitude

1
0.5
0
0.5
1

10

20

30
40
Time (samples)

50

60

70

30
20
10
0

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

30
Magnitude (dB)

c)

Magnitude (Linear)

b)

20
10
0
10

A Tutorial on Fourier Analysis

Leakage

Comparison:
Sinusoid at 1/4 the Sampling Rate

Sinusoid NEAR 1/4 the Sampling Rate


a)

0
0.5
1

Magnitude (Linear)

b)

10

20

30
40
Time (samples)

50

60

70

30
20
10
c)
0

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.5
0
0.5
1

b)

40

1
Amplitude

Amplitude

1
0.5

Magnitude (Linear)

a)

c)

10

20

30
40
Time (samples)

50

60

70

20
10
0

30

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

Magnitude (dB)

Magnitude (dB)

30
0
100
200
300
0

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

20
10
0
10

A Tutorial on Fourier Analysis

Windowing can help


Can minimize effects by multiplying time series by a window that
diminishes magnitude of points near signal edge:
Blackman Window
a)
Amplitude

0.5

10

20

30
40
Time (samples)

50

60

70

Magnitude (dB)

b)
0

50

100

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.4

0.3

0.2
0.1
0
0.1
0.2
Normalized Frequency (cycles per sample))

0.3

0.4

0.5

Magnitude (dB)

c)
0

50

100
0.5

A Tutorial on Fourier Analysis

Leakage Reduced

Comparison:
b)
Sinusoid NEAR 1/4 the Sampling Rate
a)

Amplitude

0.5
1

Magnitude (Linear)

10

20

30
40
Time (samples)

50

60

10

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

Magnitude (dB)

10
0
0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

10

20

0.8

0.9

30
40
Time (samples)

50

60

70

10
5

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
Normalized Frequency (cycles per sample))

0.8

0.9

c)

20

15

30
Magnitude (dB)

0.5
1

20

10

70

30

1
0.5

Magnitude (Linear)

Amplitude

b)

c)

Sinusoid at 1/4 the Sampling Rate


a)

1
0.5

20
0
20
40
60
80

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 filter 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]

A Tutorial on Fourier Analysis

Filtering using DFT

Goal is to choose good impulse response h[n]


Transform signal into frequency 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

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(!)

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

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

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
1
0.5
0
500

400

300

200
100
0
100
200
ideal lopass filter in frequency domain

300

400

500

400

300

200

100
0
100
ideal filter coeffs in time domain

200

300

400

500

100

200

300

400
500
600
truncated causal filter

700

800

900

1000

0
500

400

300

200

100
0
100
Gibbs phenomenon

200

300

400

500

0.1
0
0.1
500
0.1
0
0.1

1.5
1
0.5

A Tutorial on Fourier Analysis

Spectral Analysis

Often we want to see spectral energy as a signal evolves over


time

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

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 effects

A Tutorial on Fourier Analysis

Short-Timescale Fourier Transform (STFT)

X (m, n) =

N1
X

x(k)w (k m)e 2jnk/N

k=0

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)
5000

Frequency

4000

3000

2000

1000

3
Time

[Listen]

A Tutorial on Fourier Analysis

Violin (G4)
5000

Frequency

4000

3000

2000

1000

0.5

1.5

2
Time

2.5

[Listen]

A Tutorial on Fourier Analysis

Flute (G4)
5000

Frequency

4000

3000

2000

1000

0.5

1.5
Time

2.5

[Listen]

A Tutorial on Fourier Analysis

Piano (G4)
5000

Frequency

4000

3000

2000

1000

0.1

0.2

0.3

0.4
Time

0.5

0.6

0.7

[Listen]

A Tutorial on Fourier Analysis

Voice
8000

7000

6000

Frequency

5000

4000

3000

2000

1000

0.2

0.4

0.6

0.8

1
Time

1.2

1.4

1.6

1.8

[Listen]

A Tutorial on Fourier Analysis

C Major Scale (Piano)


16000

14000

12000

Frequency

10000

8000

6000

4000

2000

4
Time

[Listen]

A Tutorial on Fourier Analysis

C Major Scale (Piano)


Log Spectrogram (Constant-Q Transform) reveals low-frequency
structure
13669

7671

4305

Frequency

2416

1356

761

427

240

135

4
Time

A Tutorial on Fourier Analysis

Time-Space Tradeoff
spoken "Steven Usma"

0.6

0.4

Amp.

0.2

0.2

0.4

0.2

0.4

0.6

0.8

1.2

1.4

1.6

A Tutorial on Fourier Analysis

Time-Space Tradeoff
Narrowband Spectrogram overlap=152 timepts=1633
4000

Frequency

3000

2000

1000

0.2

0.4

0.6

0.8
Time

1.2

1.4

1.6

Wideband Spectrogram overlap=30 timepts=6593


4000

Frequency

3000

2000

1000

0.2

0.4

0.6

0.8
Time

1.2

1.4

1.6

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-correlation
where a signal x is correlated with itself:
N1
1 X
a(k) =
x(n) x(n k)
N
n=k

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-correlation
where a signal x is correlated with itself:
N1
1 X
a(k) =
x(n) x(n k)
N
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 Fourier
transform and || indicates taking magnitude from a complex value.

A Tutorial on Fourier Analysis

10

15
time (seconds)

20

25

30

10

15
time (seconds)

20

25

30

500

1000

1500

2000

2500 3000
lags (ms)

3500

4000

4500

5000

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