Page MenuHomec4science

fourier.tex
No OneTemporary

File Metadata

Created
Thu, Mar 13, 16:32

fourier.tex

\documentclass[xcolor=dvipsnames,aspectratio=169]{beamer}
\def\stylepath{../styles}
\usepackage{\stylepath/com418}
\begin{document}
\begin{frame} \frametitle{Fourier analysis in a nutshell}
\begin{itemize}
\item signals are elements of a vector space
\item vectors can be expressed as linear combinations of basis elements for any basis
\item basis elements are the ``atomic particles'' of a signal
\item the canonical basis is composed of instantaneous \textit{time} elements
\item the Fourier basis is composed of \textit{oscillatory} elements
\end{itemize}
\end{frame}
\def\timeplot#1#2{
\begin{dspPlot}[width=2.5cm,height=1cm,xticks=1,yticks=1]{0,7}{0,1.2}
\moocStyle
\dspSignal{x #1 eq {1} {0} ifelse}
\dspText(3,1.4){$#2 \times$}
\end{dspPlot}\hspace{-2em}}
\begin{frame} \frametitle{The time domain}
\begin{center}
\begin{dspPlot}[width=5cm,height=1.5cm,xticks=1,yticks=5]{0,7}{0,6}
\moocStyle
\dspTapsAt{0}{1 2 3 4 5 4 3 2}
\end{dspPlot}
\end{center}
\begin{tabular}{cccc}
\timeplot{0}{1}
&
\timeplot{1}{2}
&
\timeplot{2}{3}
&
\timeplot{3}{4}
\\
\timeplot{4}{5}
&
\timeplot{5}{4}
&
\timeplot{6}{3}
&
\timeplot{7}{2}
\end{tabular}
\end{frame}
\def\freqplot#1#2{
\begin{dspPlot}[width=2.5cm,height=1cm,xticks=none,yticks=1]{0,7}{-1.3,1.3}
\moocStyle
\dspSignal{x 360 8 div #1 mul mul cos}
\dspFunc[linewidth=0.3pt,linecolor=blue]{x 360 8 div #1 mul mul cos}
\dspText(3,1.8){$#2 \times$}
\end{dspPlot}\hspace{-2em}}
\begin{frame} \frametitle{The frequency domain}
\begin{center}
\begin{dspPlot}[width=5cm,height=1.5cm,xticks=,yticks=5]{0,7}{0,6}
\moocStyle
\dspTapsAt{0}{1 2 3 4 5 4 3 2}
\end{dspPlot}
\end{center}
\begin{tabular}{cccc}
\freqplot{0}{3}
&
\freqplot{1}{-0.8536}
&
\freqplot{2}{0}
&
\freqplot{3}{-0.1464}
\\
\freqplot{4}{0}
&
\freqplot{5}{-0.1464}
&
\freqplot{6}{0}
&
\freqplot{7}{-0.8536}
\end{tabular}
\end{frame}
\begin{frame} \frametitle{The Discrete Fourier Transform}
\begin{itemize}
\item Fourier transform for finite-length signals
\item the set of $N$ signals in $\mathbb{C}^N$
\[
w_k[n] = e^{j\frac{2\pi}{N}nk}, \qquad n, k = 0, 1, \ldots, N-1
\]
is an orthogonal basis in $\mathbb{C}^N$.
\end{itemize}
\end{frame}
\begin{frame} \frametitle{DFT in vector notation}
\centering
Analysis formula:
\[
X_k = \langle \mathbf{w}^{(k)}, \mathbf{x} \rangle
\]
\vspace{2em}
Synthesis formula:
\[
\mathbf{x} = \frac{1}{N} \sum_{k = 0}^{N-1} X_k \mathbf{w}^{(k)}
\]
\end{frame}
\begin{frame} \frametitle{DFT explicit formulas}
\centering
Analysis formula:
\[
X[k] = \sum_{n = 0}^{N-1} x[n]\, e^{-j\frac{2\pi}{N}nk}, \qquad k = 0,1,\ldots,N-1
\]
$N$-point signal in the {\em frequency domain}
\vspace{2em}
Synthesis formula:
\[
x[n] = \frac{1}{N} \sum_{k = 0}^{N-1} X[k]\, e^{j\frac{2\pi}{N}nk}, \qquad n = 0,1,\ldots,N-1
\]
$N$-point signal in the {\em ``time'' domain}
\end{frame}
\begin{frame} \frametitle{DFT coefficients}
\begin{itemize}
\item square magnitude: energy of each sinusoidal component (Parseval!)
\item phase: relative alignment of each sinusoidal component (determines the shape in time)
\item frequency resolution equal to time resolution (short segments bring little info)
\item magnitude symmetric for real-valued inputs
\item phase mostly irrelevant for steady-state audio
\end{itemize}
\end{frame}
\def\Gen#1{%
\raisebox{-1.2em}{%
\psset{xunit=1em,yunit=1em,linewidth=1.5pt}%
\pspicture(-1,0)(7.1,-3)%
\rput[r]{0}(0,-1.5){$A_{#1}$}\rput[r]{0}(0,-2.5){$\phi_{#1}$}
\rput[l](1.9,-1.5){\psframebox[framesep=.2]{\parbox{4em}{~~\pscirclebox{\Large$\mathbf{\sim}$}$_{~~#1}$}}}
\psline[linewidth=0.8pt]{->}(0.1,-1.5)(1.8,-1.5)
\psline[linewidth=0.8pt]{->}(0.1,-2.5)(1.8,-2.5)
\endpspicture}}
\begin{frame} \frametitle{The inverse DFT as a synthesizer}
\centering
\begin{dspBlocks}{1}{5}
\Gen{k} & ~~$A_k e^{j(\frac{2\pi}{N}kn + \phi_k)}$
\BDConnHNext{1}{1}
\end{dspBlocks}
\end{frame}
\begin{frame} \frametitle{DFT synthesis formula}
\centering
\begin{dspBlocks}{1.2}{0.2}
\rnode{A}{\Gen{\,0}} & & \\
\Gen{\,1} & & \\
\Gen{\,2} & & \BDadd & $x[n]$ \\
\hspace{1em}$\ldots$ & & \\
\Gen{N-2} & & \\
\rnode{B}{\Gen{N-1}} & &
\ncline{1,1}{1,2}\ncline{->}{1,2}{3,3}
\ncline{2,1}{2,2}\ncline{->}{2,2}{3,3}
\ncline{3,1}{3,2}\ncline{->}{3,2}{3,3}
\ncline{5,1}{5,2}\ncline{->}{5,2}{3,3}
\ncline{6,1}{6,2}\ncline{->}{6,2}{3,3}
\ncline{->}{3,3}{3,4}
\end{dspBlocks}
\end{frame}
\begin{frame}
\frametitle{Interpreting a DFT plot}
\begin{center}
\begin{figure}
\begin{dspPlot}[yticks=custom,xticks=custom,xout=true,width=8cm,height=2.5cm,ylabel={$|X[k]|$}]{0, 63}{0, 1}
\moocStyle
\def\y{-0.3}
\pnode(0,\y){A} \pnode(31,\y){B} \pnode(63,\y){C}
\pnode(8,\y){A1}
\pnode(23,\y){B1}\pnode(40,\y){B2}
\pnode(55,\y){C1}
\def\yu{1.1}
\pnode(0,\yu){Au} \pnode(31,\yu){Bu} \pnode(63,\yu){Cu}
\dspTaps{0 .5}
\dspSignal[xmin=1]{x 180 mul 16 div sin x 180 mul 64 div sin div abs 8 div}
\dspCustomTicks[axis=x]{0 0 32 $N/2$ 63 $N-1$}
\end{dspPlot}
\psset{braceWidthInner=3pt,braceWidthOuter=3pt,braceWidth=1pt}
{\psbrace[linecolor=blue,ref=C,nodesepA=-8ex,nodesepB=-2ex,rot=-90](Bu)(Au){frequencies $< \pi$ (counterclockwise)}}
{\psbrace[linecolor=blue,ref=C,nodesepA=5ex,nodesepB=-2ex,rot=-90](Cu)(Bu){frequencies $> \pi$ (clockwise)}}
{\psbrace[linecolor=green,ref=C,nodesep=2ex,rot=90](A)(A1){low frequencies (slow)}
\psbrace[linecolor=green,ref=C,nodesep=2ex,rot=90](C1)(C){low frequencies (slow)}}
{\psbrace[linecolor=red,ref=C,nodesep=2ex,rot=90,braceWidthOuter=23pt](B1)(B2){high frequencies (fast)}}
\end{figure}
\end{center}
\end{frame}
\begin{frame} \frametitle{Labeling the frequency axis}
If we know the ``clock'' of the system $T_s$ (or its frequency $F_s$)
\begin{itemize}
\item fastest (positive) frequency is $\omega=\pi$
\item sinusoid at $\omega=\pi$ needs two samples to do a full revolution
\item time between samples: $T_s = 1/F_s$ seconds
\item real-world period for fastest sinusoid: $2T_s$ seconds
\item real-world frequency for fastest sinusoid: $F_s/2$ Hz
\end{itemize}
\end{frame}
\begin{frame} \frametitle{Example: train whistle}
\begin{center}
\includegraphics[height=60mm]{train.eps}
\movie[inlinesound]{\fbox{\small{Play}}}{train.wav}
\end{center}
\end{frame}
\def\dftpeak#1#2{%
\pscircle[linecolor=green,linewidth=0.5pt](#1){5pt}
\uput{1em}[0](#1){#2}}
\begin{frame} \frametitle{Example: train whistle}
\centering
32768 samples (the ``clock'' of the system $F_s = 8000$Hz)
\begin{figure}
\begin{dspPlot}[xticks=custom,yticks=none,sidegap=0]{0, 1638}{0, 1.2}
\moocStyle
\dspFuncFile{trainDFT.txt}
\dspCustomTicks[axis=x]{0 0 1638 16384}
\only<2>{%
\dftpeak{198,0.79}{$k=2073$}
\dftpeak{229,1}{$k=2400$}
\dftpeak{292,0.56}{$k=3061$}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Example: train whistle}
\centering
the ``clock'' of the system $F_s = 8000$Hz
\begin{figure}
\begin{dspPlot}[xticks=custom,yticks=none,sidegap=0]{0, 1638}{0, 1.2}
\moocStyle
\dspFuncFile{trainDFT.txt}
\dspCustomTicks[axis=x]{0 0 1638 4KHz}
\dftpeak{198,0.79}{506Hz}
\dftpeak{229,1}{585Hz}
\dftpeak{292,0.56}{747Hz}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Example: train whistle}
if we look up the frequencies:
\begin{center}
\includegraphics[height=30mm]{bminor.eps}
B minor chord
\end{center}
\end{frame}
\begin{frame} \frametitle{The fundamental tradeoff}
\begin{itemize}
\item time representation obfuscates frequency
\item frequency representation obfuscates time
\end{itemize}
\vspace{2em}
\begin{figure}
\begin{dspPlot}[height=2.4cm,xticks=none,yticks=none,sidegap=0]{0, 1638}{0, 1.2}
\moocStyle
\dspFuncFile{trainDFT.txt}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Short-Time Fourier Transform}
Idea:
\begin{itemize}
\item take small signal pieces of length $L$
\item look at the DFT of each piece:
\[
X[m; k] = \sum_{n = 0}^{L-1}x[m+n]\, e^{-j\frac{2\pi}{L}nk}
\]
\end{itemize}
\end{frame}
\begin{frame} \frametitle{Wideband vs Narrowband}
Long window: narrowband spectrogram
\begin{itemize}
\item long window $\Rightarrow$ more DFT points $\Rightarrow$ more frequency resolution
\item long window $\Rightarrow$ more ``things can happen'' $\Rightarrow$ less precision in time
\end{itemize}
\vspace{2em}
Short window: wideband spectrogram
\begin{itemize}
\item short window $\Rightarrow$ many time slices $\Rightarrow$ precise location of transitions
\item short window $\Rightarrow$ fewer DFT points $\Rightarrow$ poor frequency resolution
\end{itemize}
\end{frame}
\def\speech#1#2{\only<#1>{\dspImageFile{speechgram#2.eps}}}
\begin{frame} \frametitle{Speech analysis}
\begin{center}
\only<1>{8ms analysis window (125Hz frequency bins)}
\only<2>{32ms analysis window (31Hz frequency bins)}, 4ms shifts
\begin{dspPlot}[height=1cm,xticks=none,xout=true,yticks=none,sidegap=0]{0, 2024}{-.6, .6}
\moocStyle
\dspFuncFile{speech.txt}
\end{dspPlot}
\begin{dspCP}[width=\dspWidth,xticks=custom,yticks=custom]{0,2}{0,5}%
\speech{1}{64}
\speech{2}{256}
\dspCustomTicks[axis=x]{0 0 2 2.5s}
\dspCustomTicks[axis=y]{0 0 5 4KHz}
\end{dspCP}
\end{center}
\end{frame}
\def\tf{180 mul dup 1.1 mul cos 1 add 2 div exch 5 mul sin 0.1 mul add 0.1 add }
\def\td{cvi 16 mod 16 div \tf }
\def\tr{cvi 16 mod 15 exch sub 16 div \tf }
\def\twin{.5 sub abs .5 div 1 exch sub 0.06 add }
\def\tw{cvi 16 mod 16 div \twin }
\def\tdw{cvi 16 mod 16 div dup \tf exch \twin mul }
\begin{frame} \frametitle{Windowing}
\centering
the DFT is inherently $N$-periodic and assumes the signal is $N$-periodic
\vspace{1em}
\begin{columns}
\begin{column}{0.3\textwidth}
\centering
the signal to transform
\begin{dspPlot}[yticks=1,xticks=5,width=0.7\textwidth,height=3cm]{0,16}{0,1.5}
\dspSignal[xmin=0,xmax=15,linecolor=darkred]{x \td}
\end{dspPlot}
\end{column}
\begin{column}{0.7\textwidth}
\centering
what the DFT sees
\begin{dspPlot}[yticks=1,xticks=16,width=0.7\textwidth,height=3cm]{-20,40}{0,1.5}
\dspSignal[xmin=0,xmax=15,linecolor=darkred]{x \td}
\dspSignal[xmin=16,linecolor=darkred!40]{x \td}
\dspSignal[xmax=-1,linecolor=darkred!40]{x 31 add \td}
\end{dspPlot}
\end{column}
\end{columns}
notice the discontinuity jumps!
\end{frame}
\begin{frame} \frametitle{Windowing}
\centering
to avoid spurious high-frequency content use a tapering window \\
(triangular, Hamming, Hanning, ...)
\vspace{1em}
\begin{columns}
\begin{column}{0.3\textwidth}
\centering
\begin{dspPlot}[yticks=1,width=0.7\textwidth,height=3cm]{0,16}{0,1.5}
\dspSignal[xmin=0,xmax=15,linecolor=lightgray]{x \td}
\dspSignal[xmin=0,xmax=15,linecolor=green!40]{x \tw}
\dspSignal[xmin=0,xmax=15,linecolor=darkred]{x \tdw}
\end{dspPlot}
\end{column}
\begin{column}{0.7\textwidth}
\centering
\begin{dspPlot}[yticks=1,xticks=16,width=0.7\textwidth,height=3cm]{-20,40}{0,1.5}
\dspSignal[xmin=0,xmax=15,linecolor=darkred]{x \tdw}
\dspSignal[xmin=16,linecolor=darkred!40]{x \tdw}
\dspSignal[xmax=-1,linecolor=darkred!40]{x 31 add \tdw}
\end{dspPlot}
\end{column}
\end{columns}
\vspace{1em}
equivalent to lowpass-filtering the spectrum
\end{frame}
\intertitle{A panoply of Fourier transforms}
\begin{frame} \frametitle{The Discrete Fourier Transform}
\begin{itemize}
\item Fourier transform for finite-length signals in $\mathbb{C}^N$
\item $N$ basis vectors: $w_k[n] = e^{j\frac{2\pi}{N}nk}, k = 0, 1, \ldots, N-1$
\item spectrum is a set of $N$ Fourier coefficients (DFT is an isomorphism)
\end{itemize}
\vspace{1em}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{align*}
X[k] &= \sum_{n=0}^{N-1} x[n]\, e^{-j\frac{2\pi}{N} nk} \\ \\
x[n] &= \frac{1}{N} \sum_{k=0}^{N-1} X[k]\, e^{j\frac{2\pi}{N} nk}
\end{align*}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\def\a{0.9 }
$x[n] = \cos(\omega_0 n), \quad \omega_0 = (2\pi/16) $
\begin{dspPlot}[height=1cm,width=5cm, xout=true, xticks=4]{0, 16}{-1.2, 1.2}
\moocStyle
\dspSignal{x 22.5 mul cos}
\end{dspPlot}
\begin{dspPlot}[height=1cm,width=5cm,yticks=4]{0, 16}{0, 10}
\moocStyle
\dspTapsAt{0}{0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 8 }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{The DTFT (Discrete-Time Fourier Transform)}
\begin{itemize}
\item frequency representation for signals in $\ell_2(\mathbb{Z})$
\item formal basis vectors $e^{j\omega n}, \omega \in \mathbb{R}$
\item spectrum is a $2\pi$-periodic function in $L_2([-\pi, \pi])$
\end{itemize}
\vspace{1em}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{align*}
X(e^{j\omega}) &= \sum_{n=-\infty}^{\infty} x[n]\, e^{-j\omega n} \\ \\
x[n] &= \frac{1}{2\pi} \int_{-\pi}^{\pi} X(e^{j\omega})\,e^{j\omega n}\,d\omega
\end{align*}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\def\a{0.9 }
$x[n] = \alpha^n\, u[n], \quad |\alpha| < 1$
\begin{dspPlot}[height=1cm,width=5cm]{-3,25}{0, 1.2}
\moocStyle
\dspSignal{x 0 ge {\a x exp} {0} ifelse}
\end{dspPlot}
\begin{dspPlot}[xtype=freq,yticks=5,height=1cm,width=5cm]{-1,1}{0, 11}
\moocStyle
\def\a{0.9 }
\dspFunc{x 180 mul cos \a -2 mul mul \a \a mul 1 add add sqrt 1 exch div }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{The Fourier Transform (original flavor)}
\begin{itemize}
\item frequency representation for continuous-time signals in $L_2(\mathbb{R})$
\item formal basis vetcors $e^{j2\pi f t}, f \in \mathbb{R}$
\item spectrum is a function in $L_2(\mathbb{R})$ (isomorphism)
\item important concept: bandlimited signals
\end{itemize}
\vspace{1em}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{align*}
X(f) &= \int_{-\infty}^{\infty} x(t) e^{-j2\pi f t} dt \\ \\
x(t) &= \int_{-\infty}^{\infty} X(f) e^{j2\pi f t} df
\end{align*}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\def\a{0.9 }
the rect-sinc pair
\begin{dspPlot}[height=1cm,width=5cm,xticks=custom,sidegap=0,xout=true]{-8,8}{-0.3,1.2}
\moocStyle
\dspFunc{x \dspSinc{0}{1}}
\dspCustomTicks[axis=x]{0 0 1 $T_s$ -1 $-T_s$ 2 $2T_s$ 3 $3T_s$ 4 $4T_s$}
\end{dspPlot}
\begin{dspPlot}[height=1cm,width=5cm,xtype=freq,xticks=custom,yticks=custom]{-1.5,1.5}{0,1.4}
\moocStyle
\dspFunc{x \dspRect{0}{1}}
\dspCustomTicks[axis=x]{0 0 -0.5 $-F_s/2$ 0.5 $F_s/2$}
\dspCustomTicks[axis=y]{1 $1/F_s$}
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{The Fourier Series}
\begin{itemize}
\item frequency representation for continuous-time $P$-periodic signals in $L_2([0, P])$
\item formal basis vetcors $e^{j\frac{2\pi}{P}kt}$
\item countable set of coefficients; highlights the harmonic structure of the signal
\end{itemize}
\vspace{1em}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{align*}
X[k] &= \frac{1}{P}\int_{0}^{P} x(t) e^{-j\frac{2\pi}{P}kt} dt \\ \\
x(t) &= \sum_{k=-\infty}^{\infty} X[k]\, e^{j\frac{2\pi}{P}kt}
\end{align*}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\def\a{0.9 }
sawtooth signal
\begin{dspPlot}[height=1cm,width=5cm,xticks=custom,sidegap=0,xout=true]{-8,8}{-1.2,1.2}
\moocStyle
\dspFunc{x 100 add 3 div abs dup cvi sub 0.5 sub 2 mul}% 4 mod 4 div}
\dspCustomTicks[axis=x]{-1 0 2 $P$}
\end{dspPlot}
\begin{dspPlot}[height=1cm,width=5cm,yticks=none]{-10,10}{0, 0.4}
\moocStyle
\dspSignal{x 0 eq {0} {1 3.14 x abs mul div} ifelse}
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{The PSD (Power Spectral Density)}
\begin{itemize}
\item frequency representation for WSS random processes
\item DTFT of the autocorrelation; flat for white noise
\item shows the \textit{power} distribution in frequency
\end{itemize}
\vspace{1em}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{align*}
r_x[n] &= \expt{x[m]x[m+n]} \\ \\
P_x(e^{j\omega}) &= \sum_{n=-\infty}^{\infty} r_x[n]\, e^{-j\omega n}
\end{align*}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\def\a{0.9 }
iid process with zero mean and unit variance
\begin{dspPlot}[height=1cm,width=5cm,xout=true]{-20,20}{-1.2, 1.2}
\moocStyle
\dspSignal{rand 2147483647 div 0.5 sub 2 mul}
\end{dspPlot}
\begin{dspPlot}[xtype=freq,height=1cm,width=5cm]{-1,1}{0, 1.5}
\moocStyle
\def\a{0.9 }
\dspFunc{1 }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\end{document}

Event Timeline