Page MenuHomec4science

2_approximation.tex
No OneTemporary

File Metadata

Created
Thu, Mar 13, 07:56

2_approximation.tex

\documentclass[aspectratio=169]{beamer}
\def\stylepath{../styles}
\usepackage{\stylepath/com303}
\begin{document}
%\def\N{4 }
%\begin{frame} \frametitle{Mainlobe and sidelobes}
% \centering
% $W(e^{j\omega}) = \sin(\omega M/2)/\sin(\omega/2)$
% \begin{figure}
% \begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom,xout=true]{0,1}{-3.5,12}
% \moocStyle
% \dspCustomTicks[axis=y]{9 $M$}
% \dspCustomTicks{0.222222 $2\pi/M$}
% \dspCustomTicks{0.333333 $3\pi/M$}
% \dspCustomTicks{0.444444 $4\pi/M$}
% \only<2->{
% % first zero crossing is at 2/(2N+1)
% \FPupn\fzc{2 \N * 1 + 2 / 4 trunc}
% \pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
% \dspFunc[xmin=0,xmax=\fzc]{x 0 eq {0} {x \dspSincS{0}{\N}} ifelse}}}
% \only<3->{
% \FPupn\szc{2 \N * 1 + 4 / 4 trunc}
% \pscustom[linestyle=none,fillstyle=solid,fillcolor=red!50]{
% \dspFunc[xmin=\fzc,xmax=\szc]{x \dspSincS{0}{\N}}}}
% \dspFunc[linecolor=darkgray]{x \dspSincS{0}{\N}}
% \dspPlotFrame
% \end{dspPlot}
% \end{figure}
%\end{frame}
%
%
\begin{frame} \frametitle{Overview:}
\begin{itemize}
\item Impulse truncation
\item Window method
\item Frequency sampling
\end{itemize}
\end{frame}
\begin{frame} \frametitle{How can we approximate an ideal lowpass?}
Idea \#1:
\begin{itemize}[<+->]
\item pick $\omega_c$
\item compute ideal impulse response $h[n]$
\item truncate $h[n]$ to a finite-support $\hat{h}[n]$
\item $\hat{h}[n]$ defines an FIR filter
\end{itemize}
\end{frame}
\begin{frame} \frametitle{Approximation by truncation}
\centering
FIR approximation of length $M = 2N+1$:
\[
\hat{h}[n] = \begin{cases}
\displaystyle \frac{\omega_c}{\pi}\sinc\left(\frac{\omega_c}{\pi}n\right) & |n| \le N \\ \\
0 & \mbox{otherwise}
\end{cases}
\]
\end{frame}
\begin{frame} \frametitle{Why it could be a good idea}
\begin{align*}
\mbox{MSE} &= \frac{1}{2\pi}\int_{-\pi}^{\pi}|H(e^{j\omega}) - \hat{H}(e^{j\omega})|^2 d\omega \\ \pause
&= \|H(e^{j\omega}) - \hat{H}(e^{j\omega})\|^2 \\ \pause
&= \|h[n] - \hat{h}[n]\|^2 \\ \pause
&= \sum_{n=-\infty}^{\infty} |h[n] - \hat{h}[n]|^2 \pause
\end{align*}
\end{frame}
\begin{frame} \frametitle{Why it could be a good idea}
let $I = \{n_0, n_1, \ldots, n_M\}$ the set of indices of the coefficients we keep:
\begin{align*}
\mbox{MSE} &= \sum_{n=-\infty}^{\infty} |h[n]|^2 - \sum_{n \in I} |\hat{h}[n]|^2 \\ \pause
&= 2\omega_c - \sum_{n \in I} |\hat{h}[n]|^2
\end{align*}
\centering
\pause
\begin{itemize}
\item MSE is minimized by keeping the largest coefficients
\item $|h[n]| \propto 1/n$
\item MSE is minimized by symmetric impulse truncation around zero
\end{itemize}
\end{frame}
% DTFT of the truncated ideal lowpass
% h[n] = wc/pi sinc(wc/pi n) = (sin(wc n)) / n
% H(e^jw)=wc/pi + 2/pi \sum_1^N (sin(wc n)/n) cos(w n)
\def\wc{0.5 }
\def\gibbs#1{%
180 mul
0 % accumulator a
1 1 #1 % start, inc, end for loop
{dup dup % stack: x a n n n
\wc 180 mul mul sin % x a n n sin(wc n)
exch div exch % x a sin/n n
3 index % x a sin/n n x
mul cos mul
add}
for
exch pop
2 mul 3.14 div
\wc add}
\def\plotApp#1#2{%
\only<#1>{%
\dspFunc{x \gibbs{#2}}
\FPupn\M{#2 2 * 1 + 0 trunc}
\dspText(0.7,0.8){$M=\M$}}}
\begin{frame} \frametitle{Why it's not such a good idea}
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=2,ylabel={$\hat{H}(e^{j\omega})$},xout=true]{0,1}{-0.3,1.2}
\moocStyle
\dspFunc[linecolor=green,linewidth=1pt]{x \dspRect{0}{1}}
\only<2->{
\psline[linewidth=0.5pt,linecolor=blue](0,1.1)(0.55, 1.1)
\psline[linewidth=0.5pt,linecolor=blue](0.45,-0.1)(1, -0.1)}
\plotApp{2}{4}
\plotApp{3}{10}
\plotApp{4}{50}
\plotApp{5}{150}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{The Gibbs phenomenon}
\centering
The maximum error around the cutoff frequency\\ is around 9\% of the height of the jump\\ {\em regardless of $N$}
\end{frame}
\begin{frame} \frametitle{Understanding the Gibbs phenomenon}
\[
\hat{h}[n] = h[n]\, w[n]
\]
\[
w[n] = \begin{cases}
1 & |n| \le N \\
0 & \mbox{otherwise}
\end{cases}
\]
\vspace{1em}
\pause
\[
\hat{H}(e^{j\omega}) = ?
\]
\end{frame}
\begin{frame} \frametitle{The convolution and modulation theorems}
\begin{align*}
\DTFT{(x \ast y)[n]} &= X(e^{j\omega})\,Y(e^{j\omega}) \\ \\ \pause
\DTFT{x[n]\,y[n]} &= (X \ast Y)(e^{j\omega})
\end{align*}
\vspace{2em}
\end{frame}
\begin{frame} \frametitle{Convolution of DTFTs}
\centering
in $\ell_2(\mathbb{Z})$:
\begin{align*}
(x \ast y)[n] &= \langle x^*[k], y[n-k] \rangle \\
&= \sum_{k=-\infty}^{\infty}x[k]y[n-k]
\end{align*}
\vspace{1em}
\pause
in $L_2([-\pi,\pi])$:
\begin{align*}
(X \ast Y)(e^{j\omega}) &= \langle X^*(e^{j\sigma}), Y(e^{j(\omega-\sigma)}) \rangle \\
&= \frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\sigma}) Y(e^{j(\omega-\sigma)}) d\sigma
\end{align*}
\end{frame}
\begin{frame} \frametitle{Modulation theorem: proof}
\begin{align*}
\IDTFT{(X \ast Y)(e^{j\omega})} &= \frac{1}{2\pi}\int_{-\pi}^{\pi} (X \ast Y)(e^{j\omega})e^{j\omega n}d\omega \\ \pause
&= \frac{1}{(2\pi)^2}\int_{-\pi}^{\pi} \int_{-\pi}^{\pi} X(e^{j\sigma}) Y(e^{j(\omega-\sigma)})e^{j\omega n} d\sigma d\omega \\ \pause
&= \frac{1}{(2\pi)^2}\int_{-\pi}^{\pi} \int_{-\pi}^{\pi} X(e^{j\sigma}) Y(e^{j(\omega-\sigma)})e^{j\sigma n}e^{j(\omega - \sigma) n} d\sigma d\omega \\ \pause
&= \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\sigma})e^{j\sigma n}d\sigma \, \frac{1}{2\pi}\int_{-\pi}^{\pi} Y(e^{j(\omega-\sigma)}) e^{j(\omega - \sigma) n} d\omega \\ \pause
&= x[n] \, y[n]
\end{align*}
\end{frame}
\begin{frame} \frametitle{Aside: sinusoidal modulation revisited}
\centering
\only<1>{$X(e^{j\omega})$}
\only<2>{$Y(e^{j\omega}) = \DTFT{x[n]\,\cos(\omega_0 n)}$}
\begin{figure}
\begin{dspPlot}[height=3cm,xtype=freq,xticks=1,yticks=none]{-1,1}{0,1.2}
\moocStyle
\only<1>{\dspFunc{x \dspPeriodize \sshape }}
\only<2>{\dspFunc{x \modSpec }
\dspCustomTicks[axis=x]{{\wc} $\omega_0$ {-\wc} $-\omega_0$}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Aside: sinusoidal modulation revisited}
\begin{align*}
\DTFT{x[n]\,\cos\omega_0 n} &= X(e^{j\omega}) \ast \frac{1}{2}[\tilde{\delta}(\omega-\omega_0) + \tilde{\delta}(\omega+\omega_0)]\\ \pause
% &= \frac{1}{4\pi}\int_{-\pi}^{\pi} X(e^{j\sigma})\tilde{\delta}(\sigma-\omega+\omega_0)d\sigma + \frac{1}{4\pi}\int_{-\pi}^{\pi} X(e^{j\sigma})\tilde{\delta}(\sigma -\omega-\omega_0)d\sigma \\ \pause
&= \frac{1}{4\pi}\int_{-\pi}^{\pi} X(e^{j(\omega-\sigma)})\tilde{\delta}(\sigma-\omega_0)d\sigma + \frac{1}{4\pi}\int_{-\pi}^{\pi} X(e^{j(\omega-\sigma)})\tilde{\delta}(\sigma+\omega_0)d\sigma \\ \pause
&= \frac{1}{2}\left[ X(e^{j(\omega - \omega_0)}) + X(e^{j(\omega + \omega_0)}) \right]
\end{align*}
\end{frame}
\begin{frame}
\frametitle{Back to the Gibbs phenomenon}
\centering
The maximum error around the cutoff frequency\\ is around 9\% of the height of the jump\\ {\em regardless of $N$}
\end{frame}
\begin{frame} \frametitle{Why it's not such a good idea}
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=2,ylabel={$\hat{H}(e^{j\omega})$},xout=true]{0,1}{-0.3,1.2}
\moocStyle
\dspFunc[linecolor=green,linewidth=1pt]{x \dspRect{0}{1}}
\only<2->{
\psline[linewidth=0.5pt,linecolor=blue](0,1.1)(0.55, 1.1)
\psline[linewidth=0.5pt,linecolor=blue](0.45,-0.1)(1, -0.1)}
\plotApp{2}{4}
\plotApp{3}{10}
\plotApp{4}{50}
\plotApp{5}{150}
\end{dspPlot}
\end{figure}
\end{frame}
\def\N{9 }
\begin{frame} \frametitle{Understanding the Gibbs phenomenon}
\centering
$ \hat{h}[n] = h[n]\, w[n] $
\begin{figure}
\begin{dspPlot}[xticks=10,ylabel={$h[n]$},height=2cm]{-20,20}{-.7,1.2}
\moocStyle
\dspSignal[linecolor=green]{x \dspSinc{0}{2}}
\end{dspPlot}
\end{figure}
\begin{figure}
\begin{dspPlot}[xticks=10,ylabel={$w[n]$},height=2cm]{-20,20}{0,1.2}
\moocStyle
\dspSignal[linecolor=blue]{x \dspRect{0}{\N}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Understanding the Gibbs phenomenon}
\centering
$ \hat{H}(e^{j\omega}) = (H \ast W)(e^{j\omega}), \qquad W(e^{j\omega}) = \sin(\omega M/2)/\sin(\omega/2)\quad$
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=none,ylabel={$H(e^{j\omega})$},height=2cm]{-1,1}{0,1.2}
\moocStyle
\dspFunc[linecolor=green]{x \dspRect{0}{1}}
\end{dspPlot}
\end{figure}
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=2,xout=true,yticks=10,ylabel={$W(e^{j\omega})$},height=2cm]{-1,1}{-7,23}
\moocStyle
\dspFunc[linecolor=blue]{x \dspSincS{0}{\N}}
\end{dspPlot}
\end{figure}
\end{frame}
\def\wRes#1#2{%
\only<#1>{%
\dspFunc{x \dspSincS{#2}{\N}}
\psline[linewidth=1pt,linecolor=gray](#2,80)(#2,-70)}}
\def\tRes#1#2{%
\only<#1>{\dspFunc[xmax=#2]{x \gibbs{\N}}}}
\def\animate{%
\doSlide{1}{-.8} \doSlide{2}{-.7} \doSlide{3}{-.6} \doSlide{4}{-.5} \doSlide{5}{-.4}
\doSlide{6}{-.3} \doSlide{7}{-.2} \doSlide{8}{-.1} \doSlide{9}{0} \doSlide{10}{.1}
\doSlide{11}{.2} \doSlide{12}{.3} \doSlide{13}{.4} \doSlide{14}{.5} \doSlide{15}{.6}
\doSlide{16}{.7} \doSlide{17}{.8}}
\begin{frame} \frametitle{Implicit frequency-domain convolution}
\begin{center}
$N=\N, M=2N+1$
\begin{figure}
\begin{dspPlot}[height=1.4cm,xtype=freq,xticks=none,yticks=1,ylabel={$H(e^{j\omega})$}]{-1,1}{0,1.2}
\moocStyle
\psset{linecolor=green}
\dspFunc{x \dspRect{0}{1}}
\end{dspPlot}
\begin{dspPlot}[height=1.4cm,xtype=freq,xticks=none,xout=true,yticks=10,ylabel={$W(e^{j\omega})$}]{-1,1}{-6,23}
\moocStyle
\psset{linecolor=blue}
\def\doSlide{\wRes}\animate
\end{dspPlot}
\begin{dspPlot}[height=1.4cm,xtype=freq,xticks=2,xout=true,yticks=1,ylabel={$\hat{H}(e^{j\omega})$}]{-1,1}{-.2,1.2}
\moocStyle
\def\doSlide{\tRes}\animate
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\def\N{9 }
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 1}
Observation 1: integral of window's transform is independent of $N$:
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom]{-1,1}{-.3,1.2}
\moocStyle
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
\dspFunc{x -1 eq {0} {x 1 eq {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}
\dspFunc[linecolor=blue]{x \dspSincS{0}{\N} \N 2 mul 1 add div}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 1}
Observation 1: integral of window's transform is independent of $N$:
\begin{align*}
\int_{-\pi}^{\pi} W(e^{j\omega}) &= \int_{-\pi}^{\pi} \sum_{n=-N}^{N}e^{-j\omega n}d\omega \\
&= \sum_{n=-N}^{N} \int_{-\pi}^{\pi}e^{-j\omega n}d\omega \\
&= 2\pi
\end{align*}
\end{frame}
\def\doSincS#1#2{%
\only<#1>{\dspFunc[linecolor=blue]{x \dspSincS{0}{#2} #2 2 mul 1 add div}%
\dspText(0.7,1){$N=#2$}}}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 2}
For large $N$, the area is concentrated around the midpoint:
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom]{-1,1}{-.3,1.2}
\moocStyle
\doSincS{1}{9}
\doSincS{2}{51}
\doSincS{3}{101}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Mainlobe and sidelobes}
\centering
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=1,ylabel={$W(e^{j\omega})$}]{-1,1}{-7,23}
\moocStyle
\dspFunc[linecolor=gray]{x \dspSincS{0}{\N}}
\only<2->{
% first zero crossing is at 2/(2N+1)
\FPupn\fzc{2 \N * 1 + 2 / 4 trunc}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
\dspFunc[xmin=-\fzc,xmax=\fzc]{x \dspSincS{0}{\N}}}}
\only<3->{
\FPupn\szc{2 \N * 1 + 4 / 4 trunc}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=red!50]{
\dspFunc[xmin=\fzc,xmax=\szc]{x \dspSincS{0}{\N}}}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=red!50]{
\dspFunc[xmin=-\szc,xmax=-\fzc]{x \dspSincS{0}{\N}}}}
\end{dspPlot}
\end{figure}
\end{frame}
\def\N{9 }
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 3}
\centering
maximum value of the convolution integral: \only<2->{$A$} \only<3->{$+ B$}
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom]{-1,1}{-.3,1.2}
\moocStyle
\only<2->{
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
\dspFunc[xmax=0]{x -1 eq {0} {x 0 eq {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}}
\only<3->{
\FPupn\fzc{2 \N * 1 + 2 / 4 trunc }
\pscustom[linestyle=none,fillstyle=solid,fillcolor=yellow!30]{
\dspFunc[xmin=0,xmax=\fzc]{x 0 eq {0} {x \fzc\space ge {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}}
\dspFunc[linecolor=blue]{x \dspSincS{0}{\N} \N 2 mul 1 add div}
\dspFunc[linecolor=green]{x 1 \N div ge {0} {1} ifelse}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 4}
\centering
For large $N$, A is basically half the total area:
\[
A \approx \frac{1}{2}\int_{-\pi}^{\pi} W(e^{j\omega}) = \pi
\]
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 5}
\centering
$W(e^{j\omega}) = \sin(\omega M/2)/\sin(\omega/2), \qquad M=2N+1$
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom]{0,0.5}{-.3,1.2}
\moocStyle
\FPupn\fzc{2 \N * 1 + 2 / 4 trunc}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=yellow!30]{
\dspFunc[xmin=0,xmax=\fzc]{x 0 eq {0} {x \fzc\space ge {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}
\dspFunc[linecolor=blue]{x \dspSincS{0}{\N} \N 2 mul 1 add div}
\dspPlotFrame
\dspCustomTicks{{\fzc} $2\pi/M$}
\dspCustomTicks[axis=y]{1 $M$}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 5}
\begin{align*}
\int_{0}^{2\pi/M} W(e^{j\omega}) &= \int_{0}^{2\pi/M} \frac{\sin(\omega M/2)}{\sin(\omega/2)}d\omega \\
&= \frac{2}{M}\int_{0}^{\pi} \frac{\sin t}{\sin (t/M)}dt \qquad (t=M\omega/2)\\
&\approx \frac{2}{M}\int_{0}^{\pi}\frac{\sin t}{(t/M)}dt \qquad (\sin t/M \approx t/M \mbox{ for $M$ large})\\
&= 2 \int_{0}^{\pi}\frac{\sin t}{t}dt \\
&\approx 2\pi \times 0.589 \quad \mbox{(independent of $M$ for large $M$)}
\end{align*}
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 6}
\centering
maximum value of the convolution: $(A+B)/2\pi$
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=custom,yticks=custom]{-1,1}{-.3,1.2}
\moocStyle
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
\dspFunc[xmax=0]{x -1 eq {0} {x 0 eq {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}
\FPupn\fzc{2 \N * 1 + 2 / 4 trunc }
\pscustom[linestyle=none,fillstyle=solid,fillcolor=yellow!30]{
\dspFunc[xmin=0,xmax=\fzc]{x 0 eq {0} {x \fzc\space ge {0} {x \dspSincS{0}{\N} \N 2 mul 1 add div} ifelse} ifelse}}
\dspFunc[linecolor=blue]{x \dspSincS{0}{\N} \N 2 mul 1 add div}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Quantifying the Gibbs overshoot -- 6}
\begin{align*}
A &\approx \frac{1}{2}\int_{-\pi}^{\pi} W(e^{j\omega}) = \pi \\
B &\approx 2\pi \times 0.589
\end{align*}
\[
(A+B)/2\pi \approx 1.09
\]
\end{frame}
\begin{frame} \frametitle{Mainlobe and sidelobes}
\centering
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=1,ylabel={$W(e^{j\omega})$}]{-1,1}{-7,23}
\moocStyle
\dspFunc[linecolor=gray]{x \dspSincS{0}{\N}}
\only<2->{
% first zero crossing is at 2/(2N+1)
\FPupn\fzc{2 \N * 1 + 2 / 4 trunc}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue!30]{
\dspFunc[xmin=-\fzc,xmax=\fzc]{x \dspSincS{0}{\N}}}}
\only<3->{
\FPupn\szc{2 \N * 1 + 4 / 4 trunc}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=red!50]{
\dspFunc[xmin=\fzc,xmax=\szc]{x \dspSincS{0}{\N}}}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=red!50]{
\dspFunc[xmin=-\szc,xmax=-\fzc]{x \dspSincS{0}{\N}}}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{What if we change the window?}
We want:
\begin{itemize}[<+->]
\item narrow mainlobe so that transition is sharp
\item small sidelobe so Gibbs error is small
\item short window so FIR is efficient
\end{itemize}
\centering
\vspace{1em}
\only<+->{very conflicting requirements!}
\end{frame}
\begin{frame}
\frametitle{Triangular window}
\centering
\begin{figure}
\begin{dspPlot}[xticks=10,ylabel={$w[n]$}]{-20,20}{0,1.2}
\moocStyle
\dspSignal{x \dspTri{0}{\N}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Rectangular vs Triangular Window}
\begin{figure}
\begin{dspPlot}[xtype=freq,xticks=2,yticks=none]{0,1}{-0.3,1.2}
\moocStyle
\only<1->{\dspFunc[linecolor=gray]{x \dspSincS{0}{9} 19 div}}
\only<2->{%
\dspFunc{x \dspSincS{0}{5} 11 div dup mul}
\dspLegend(0.5,1){gray {19-tap rectangular} darkred {19-tap triangular}}}
\end{dspPlot}
\end{figure}
\end{frame}
\begin{frame} \frametitle{Window method: pros and cons}
Pros:
\begin{itemize}
\item extremely simple
\item minimizes MSE
\end{itemize}
Cons:
\begin{itemize}
\item can't control max error (Gibbs)
\item must know the impulse response (not easy for arbitrary frequency responses)
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Frequency sampling}
Idea \#2:
\begin{itemize}[<+->]
\item draw desired frequency response $H(e^{j\omega})$
\item take $M$ samples $S[k] = H(e^{j\omega_k})$, $\omega_k = (2\pi/M)k$
\item compute inverse DFT of the $S[k]$ values
\item use $s[n]$ to build impulse response $\hat{h}[n]$
\end{itemize}
\end{frame}
\begin{frame} \frametitle{Frequency sampling: desired response}
\begin{center}
\begin{figure}
\begin{dspPlot}[xtype=freq]{-1,1}{0, 1.5}
\moocStyle \SpecialCoor
\dspFunc[linecolor=green,linewidth=1pt]{x \dspRect{0}{1}}
\only<2->{
\multido{\n=-5+1}{11}{
\FPupn\f{2 11 \n{} / * 3 trunc}
\psdot[dotstyle=o](! \f0 \f0 \dspRect{0}{1})}
\dspText(0.7,0.7){$M=11$}}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\begin{frame} \frametitle{Frequency sampling: from DTFT to DFT}
\begin{center}
\begin{figure}
\begin{dspPlot}[xtype=freq]{-2,2}{0, 1.5}
\moocStyle \SpecialCoor
\dspFunc[linecolor=green,linewidth=1pt]{x \dspPeriodize \dspRect{0}{1}}
\only<2->{
\multido{\n=0+1}{11}{
\FPupn\f{2 11 \n{} / * 3 trunc}
\psdot[dotstyle=o](! \f0 \f0 \dspPeriodize \dspRect{0}{1})}
}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\begin{frame} \frametitle{Frequency sampling: DFT samples}
\begin{center}
$S[k]$
\begin{figure}
\begin{dspPlot}{0,11}{0, 1.5}
\moocStyle \SpecialCoor
\dspSignal{x \dspRect{0}{5} x \dspRect{12}{5} add}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
% Inverse DFT of sampled rect (just two cosines, since we're taking 11 points total)
\def\invSR{%
abs
dup
5 gt
{pop 0}
{32.7273 mul dup % 2pi/11
cos
exch 2 mul cos
add 2 mul
1 add
11 div}
ifelse}
\begin{frame} \frametitle{Frequency sampling: impulse response from IDFT}
\note<1>{Compare the finite-support impulse response with the ideal impulse response (green line)}
\begin{center}
\only<1>{$s[n]$}
\only<2->{$\hat{h}[n]$}
\begin{figure}
\begin{dspPlot}[xticks=none,xout=true]{-20,20}{-.2, 0.6}
\moocStyle \SpecialCoor
\dspSignal[xmin=-5,xmax=5]{x \invSR}
\only<2->{
\dspSignal[xmax=-6]{0}
\dspSignal[xmin=6]{0}}
\only<3->{\dspFunc[linecolor=green,linewidth=0.5pt]{x \dspSincN{0}{2}}}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Frequency sampling: what happens in the time domain}
\begin{align*}
\hat{h}[n] &= \begin{cases}
s[n] & \mbox{if $0 \leq n < M$} \\
0 & \mbox{otherwise}
\end{cases} \\ \\ \pause
s[n] &= \IDFT{S[k]} \\ \\ \pause
S[k] &= H(e^{j\frac{2\pi}{M}k})
\end{align*}
\end{frame}
\begin{frame}
\frametitle{Frequency sampling: what happens in the time domain}
\begin{align*}
s[n] &= \frac{1}{M}\sum_{k=0}^{M-1} S[k] \, e^{j\frac{2\pi}{M}nk} \\
&= \frac{1}{M}\sum_{k=0}^{M-1} H(e^{j\frac{2\pi}{M}k}) \, e^{j\frac{2\pi}{M}nk}\\ \pause
&= \frac{1}{M} \sum_{k=0}^{M-1} \left( \sum_{m=-\infty}^{\infty} h[m]e^{-j\frac{2\pi}{M}k} \right) \, e^{j\frac{2\pi}{M}nk} \\ \pause
&= \sum_{m=-\infty}^{\infty} h[m] \,\, \frac{1}{M} \sum_{k=0}^{M-1} e^{-j\frac{2\pi}{M}(m-n)k} \\
\end{align*}
\end{frame}
\begin{frame}
\frametitle{a familiar result}
\[
\sum_{k=0}^{M-1} e^{-j\frac{2\pi}{M}(m-n)k} = \begin{cases}
M & \mbox{if $m-n$ multiple of M} \\
0 & \mbox{otherwise}
\end{cases}
\]
\end{frame}
\begin{frame}
\frametitle{Frequency sampling: what happens in the time domain}
\begin{align*}
s[n] &= \sum_{m=-\infty}^{\infty} h[m] \,\, \delta[(m-n) \mod M] \\ \pause
&= \sum_{m=-\infty}^{\infty} h[n + mM]
\end{align*}
\centering
\vspace{2em}
sampling in the frequency domain results in periodization in the time domain \\
\end{frame}
\begin{frame}
\frametitle{Frequency sampling: impulse response from IDFT}
\begin{center}
\only<1-2>{$h[n]$}
\only<3-4>{$\sum_{m=-\infty}^{\infty} h[n + mM]$}
\only<5>{$s[n]$ }
\vphantom{$\sum_{m=-\infty}^{\infty}$}
\begin{figure}
\begin{dspPlot}[xticks=11,xout=true]{-35,35}{-.2, 0.6}
\moocStyle
\only<1-3>{\dspSignal{x \dspSincN{0}{2}}}
\only<2-3>{\dspSignal[linecolor=red!50]{x \dspSincN{11}{2}}}
\only<3>{
\dspSignal[linecolor=red!50]{x \dspSincN{22}{2}}
\dspSignal[linecolor=red!50]{x \dspSincN{33}{2}}
\dspSignal[linecolor=red!50]{x \dspSincN{-11}{2}}
\dspSignal[linecolor=red!50]{x \dspSincN{-22}{2}}
\dspSignal[linecolor=red!50]{x \dspSincN{-33}{2}}}
\only<4>{\dspSignal{x \dspPeriod{5} \invSR}}
\only<5>{
\dspSignal[linecolor=lightgray]{x \dspSincN{0}{2}}
\dspSignal{x 5 gt {0} {x -5 lt {0} {x \invSR} ifelse} ifelse}}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Frequency sampling: what happens in the frequency domain}
\begin{center}
what is the frequency response $\hat{H}(e^{j\omega})$?
\end{center}
\begin{itemize}[<+->]
\item $s[n]$: length-$M$ signal
\item $\hat{h}[n]$: finite-support infinite sequence from $s[n]$
\item DFT coefficients $S[k]$ are known
\item use the DFT to DTFT result for finite-support sequences: Lagrangian interpolation
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{DTFT of finite-support signals}
\centering
\[
\hat{H}(e^{j\omega}) = \sum_{k=0}^{M-1} S[k] \Lambda(\omega - \frac{2\pi}{M}k)
\]
with $\Lambda(\omega) = \frac{1}{M} \frac{\sin \left( \frac{\omega}{2}M \right)}{\sin \left( \frac{\omega}{2} \right) }e^{-j\frac{\omega}{2}(M-1)}$: smooth interpolation of DFT values.
\end{frame}
\def\interp#1{\dspSincS{#1 11 div 2 mul}{5} 11 div #1 11 div 2 mul \dspRect{0}{1} mul}
\def\tComp#1#2{\only<#1->{\dspFunc[linewidth=0.5pt,linecolor=blue!50]{x \interp{#2}}}}
\begin{frame}
\frametitle{Frequency sampling: frequency response}
\begin{center}
\only<5>{$\hat{H}(e^{j\omega})$}\vphantom{$\hat{H}(e^{j\omega})$}
\begin{figure}
\begin{dspPlot}[xtype=freq,yticks=none,xout=true]{-1,1}{-.5, 1.5}
\moocStyle
\dspFunc[linecolor=green,linewidth=0.1pt]{x \dspRect{0}{1}}
\multido{\n=-5+1}{11}{
\FPupn\f{2 11 \n{} / mul 3 trunc}
\dspTaps[linecolor=gray]{{\f} {\f0 \dspRect{0}{1}}}}
\tComp{2}{0}
\tComp{3}{1}
\tComp{4}{2}
\only<5->{
\dspFunc[linewidth=0.5pt,linecolor=blue!50]{x \interp{-1}}
\dspFunc[linewidth=0.5pt,linecolor=blue!50]{x \interp{-2}}
\dspFunc{x \interp{-2} x \interp{-1} x \interp{0} x \interp{1} x \interp{2} add add add add}}
\end{dspPlot}
\end{figure}
\end{center}
\end{frame}
\begin{frame} \frametitle{Frequency sampling: pros and cons}
Pros:
\begin{itemize}
\item simple
\item works with arbitrary frequency responses
\end{itemize}
Cons:
\begin{itemize}
\item can't control max error
\end{itemize}
\end{frame}
\end{document}

Event Timeline