Fourier transform

Eugeniy E. Mikhailov and Greg Bentsen

Agenda

Final exam

Today

Fourier transform

Next lecture

Fourier series

Any periodic single value function with a finite number of discontinuities, and for which ∫0T|f(t)|dt\int_0^T|f(t)|dt is finite, can be presented as

y(t)=a02+∑1∞(ancos(nω1t)+bnsin(nω1t))\begin{aligned} y(t)=\frac{a_0}{2} + \sum_1^\infty \left(a_n \cos(n \omega_1 t) + b_n \sin( n \omega_1 t) \right) \end{aligned} where (anbn)=2T∫0Tdt(cos(nω1t)sin(nω1t))y(t)\begin{aligned} \begin{pmatrix} a_n\\ b_n \end{pmatrix} = \frac{2}{T} \int_0^T dt \begin{pmatrix} \cos (n \omega_1 t)\\ \sin (n \omega_1 t) \end{pmatrix} y(t) \end{aligned}

TT
is the period, i.e., y(t)=y(t+T)y(t)=y(t+T)
ω1=2π/T\omega_1 =2 \pi/T
is the fundamental frequency

Note that a0/2=<y(t)>Ta_0/2 = <y(t)>_T, i.e. average of the function over the period

Periodic function
Periodic function

Fourier series example: |t|

y(t)=|t|,−π<t<π\begin{aligned} y(t)=|t|, ~ ~ -\pi < t < \pi \end{aligned} Since the function is even all bn=0b_n=0 {a0=π,an=0,nis evenan=−4πn2,nis odd\begin{aligned} \begin{cases} a_0 = \pi, & \\ a_n = 0, & n ~ ~ \text{is even} \\ a_n = -\frac{4}{\pi n^2}, & n ~ ~ \text{is odd} \end{cases} \end{aligned}

Fourier series example: step function

{0,−π<x<0,1,0<x<π\begin{aligned} \begin{cases} 0, & -\pi < x < 0,\\ 1, & 0 < x < \pi \end{cases} \end{aligned} Since the function is odd all an=0a_n=0 except a0=1a_0 = 1 {bn=0,nis evenbn=2πn,nis odd\begin{aligned} \begin{cases} b_n = 0, & n ~ ~ \text{is even} \\ b_n = \frac{2}{\pi n}, & n ~ ~ \text{is odd} \end{cases} \end{aligned}

At a discontinuity, the series approaches the mid point

The Gibbs phenomenon

Notice the overshoots, undershoots, and oscillations near discontinuity

Complex representation

Recall that exp(iωt)=cos(ωt)+isin(ωt)\begin{aligned} \exp( i \omega t) = \cos( \omega t) + i \sin(\omega t) \end{aligned}

It can be shown that

y(t)=∑n=−∞∞cnexp(inω1t)cn=1T∫0Ty(t)exp(−iω1nt)dt\begin{aligned} y(t) &=& \sum_{n=-\infty}^\infty c_n \exp(i n \omega_1 t) \\ c_n &=& \frac{1}{T}\int_0^T y(t) \exp( - i \omega_1 n t) dt \end{aligned}

an=cn+c−nbn=i(cn−c−n)\begin{aligned} a_n &=& c_n + c_{-n} \\ b_n &=& i(c_n - c_{-n}) \end{aligned}

What to do if function is not periodic?

y(t)=12π∫−∞∞cωexp(iωt)dωcω=12π∫−∞∞y(t)exp(−iωt)dt\begin{aligned} y(t) &=& \frac{1}{\sqrt{2 \pi}} \int_{-\infty}^\infty c_\omega \exp(i \omega t) d \omega \\ c_\omega &=& \frac{1}{\sqrt{2 \pi}}\int_{-\infty}^\infty y(t) \exp( - i \omega t) dt \end{aligned} Above requires that ∫−∞∞dty(t)\int_{-\infty}^\infty dt~ y(t) exists and is finite.

Note that cωc_\omega has the extra 2π\sqrt{2 \pi} when compared to cnc_n, and TT is gone.

Discrete Fourier transform (DFT)

In reality, we cannot have

  • infinitely large interval
  • infinite amount of points to calculate true integral

Assuming that y(t)y(t) has a period TT and we took NN equidistant points Δt=TNsamples spacing,fs=1Δtsampling rate,f1=1T=1NΔtsmallest observed frequency,also resolution bandwidth,tk=Δt×ky(tk+N)=y(tk)periodicity condition,yk=y(tk)shortcut notation,y0,y1,y2,y3,⋯,yN−1data set\begin{aligned} \Delta t &=& \frac{T}{N} & ~ ~ \text{samples spacing,}\\ f_s &=& \frac{1}{\Delta t} & ~ ~ \text{sampling rate,}\\ f_1 &=& \frac{1}{T} = \frac{1}{N \Delta t} & ~ ~ \text{smallest observed frequency,} \\ & & & ~ ~ \text{also resolution bandwidth,}\\ t_k&=& \Delta t \times k & \\ y( t_{k+N}) &=& y(t_{k}) & ~ ~ \text{periodicity condition,} \\ y_{k} &=& y(t_k) & ~ ~ \text{shortcut notation,} \\ y_0, y_1, y_2, y_3, \cdots, y_{N-1} & & & ~ ~ \text{data set} \end{aligned} We replace the integral in the Fourier series with the sum

Time representation

DFT

cn=∑k=0N−1ykexp(−i2πknN) Fourier transformyk=1N∑n=0N−1cnexp(i2πknN) inverse Fourier transformn=0,1,2,⋯,N−1\begin{aligned} c_n &=& \sum_{k=0}^{N-1} y_k \exp(-i\frac{ 2 \pi k n}{N}) ~ ~ \text{ Fourier transform} \\ y_k &=& \frac{1}{N} \sum_{n=0}^{N-1} c_n \exp(i\frac{ 2 \pi k n}{N} ) ~ ~ \text{ inverse Fourier transform} \\ n &=& 0, 1, 2, \cdots, N-1 \end{aligned}

Notice that yky_k calculation has 1/N1/N factor and cnc_n is not. This just one of the possible normalization. Some put 1/N1/N up front of cnc_n, and some put 1/N1/\sqrt{N} in front of both.

Confusion keeps increasing: where are the negative coefficients c−nc_{-n} ? In DFT, they moved to the right end of the cnc_n vector : c−n=cN−n\begin{aligned} c_{-n}=c_{N-n} \end{aligned}

Fast Fourier transform (FFT)

Fast numerical realization of DFT is FFT. This is just the smart way to do DFT. Python has one built in either numpy or scipy packages

Both fft and ifft have norm parameter which decides at which points to account for NN. Make sure you understand it. This is usually the reason when calculated coefficients do not make “physical” sense at the first glance.

y = np.fft.ifft(np.fft.fft(y))