Page MenuHomec4science

2_KS.tex
No OneTemporary

File Metadata

Created
Thu, Mar 13, 04:21

2_KS.tex

\intertitle{Let's play with LEGO!}
\begin{frame} \frametitle{Overview:}
\begin{itemize}
\item DSP as Lego: The fundamental building blocks
\item Averages and moving averages
\item Recursion: Revisiting your bank account
\item Building a simple recursive synthesizer
\item Examples of sounds
\end{itemize}
\end{frame}
% Outline slide
% TEXT: [speech]
% Today 's menu is the following
% Menu: Build and Understand a Simple Synthesizer}
% DSP as Lego: The fundamental building blocks
% Averages and moving averages
% Recursion: Revisiting your bank account
% Building a simple recursive synthesizer
% Examples of sounds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{DSP as Lego}
\begin{columns}
\begin{column}{0.4\paperwidth}
\centering
\includegraphics[width=0.28\paperwidth]{Figure2KSlegos.eps}
\end{column}
\begin{column}{0.6\paperwidth}
\begin{figure}
\scalebox{0.7}{%
\begin{dspBlocks}{0.7}{0.6}
$x[n]$ & \BDsplit & \BDadd & & \BDsplit & & \BDadd & $y[n]$\\
& & & \BDdelay & & & & \\
& & \BDadd & & \BDsplit & \BDdelayN{3} & \\
& & & \BDdelay & & & & \\
\ncline{->}{1,1}{1,3} \ncline{1,3}{1,5}\taput{$a$}
\ncline{->}{1,5}{1,7}\taput{$b$}
\ncline{->}{1,7}{1,8}
\ncline{1,2}{3,2} \ncline{->}{2,3}{1,3}
\ncline{1,5}{2,5}
\ncline{->}{4,3}{3,3} \ncline{4,5}{3,5} \ncline{->}{3,7}{1,7}\trput{$-1$}
\ncline{->}{3,2}{3,3} \ncline{3,3}{3,5}\taput{$c$}
\ncline{3,5}{3,6}\ncline{3,6}{3,7}
\ncline{2,3}{2,4}\ncline{2,4}{2,5}
\ncline{4,3}{4,4}\ncline{4,4}{4,5}
\end{dspBlocks}}
\end{figure}
\end{column}
\end{columns}
\end{frame}
% TEXT: Obvious
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\sigA{dup 0 ge {10 div 1 exch sub} {pop 0} ifelse }
\def\sigB{dup 0 ge {10 div} {pop 0} ifelse }
\begin{frame} \frametitle{Building Blocks: Adder}
\setbeamercovered{invisible}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{0}
$x[n]~~$ & & \\
& \BDadd & $~~x[n] + y[n]$ \\
$y[n]~~$ & & \\
\ncline{->}{1,1}{2,2}
\ncline{->}{3,1}{2,2}
\ncline{->}{2,2}{2,3}
\end{dspBlocks}
\end{figure}
\end{center}
\pause
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
{\footnotesize $x[n] = (1 - n/10)\,u[n]$}
\vspace{-0.5em}
\begin{dspPlot}[width=5cm,height=1cm,xticks=2]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA }
\end{dspPlot}
{\footnotesize $x[n] = (n/10)\, u[n]$}
\vspace{-0.5em}
\begin{dspPlot}[width=5cm,height=1cm,xticks=2]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigB }
\end{dspPlot}
\end{column}
\pause
\begin{column}{.5\paperwidth}
\centering
{\footnotesize $x[n] + y[n] = u[n]$}
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA x \sigB add }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Building Blocks: Multiplier}
\setbeamercovered{invisible}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{0}
$x[n]~~$ & & $~~\alpha x[n]$ \\
\ncline{->}{1,1}{1,3}\taput{$\alpha$}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{2em}
\pause
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={\hphantom{$\alpha = 0.5$}}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA }
\end{dspPlot}
\end{column}
\pause
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={$\alpha = 0.5$}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA 0.5 mul}
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Building Blocks: Unit Delay}
\setbeamercovered{invisible}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{0}
$x[n]~~$ & \BDdelay & $~~x[n-1]$ \\
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,3}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{2em}
\pause
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={\hphantom{$N=4$}}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA }
\end{dspPlot}
\end{column}
\pause
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={\hphantom{$N=4$}}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x 1 sub \sigA }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{Building Blocks: Arbitrary Delay}
\setbeamercovered{invisible}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{0}
$x[n]~~$ & \BDdelayN{N} & $~~x[n-N]$ \\
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,3}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{2em}
\pause
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={\hphantom{\hphantom{$N=4$}}}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x \sigA }
\end{dspPlot}
\end{column}
\pause
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5cm,height=2.7cm,xticks=2,xlabel={$N=4$}]{-2,8}{0,1.1}
\moocStyle
\dspSignal{x 4 sub \sigA }
\end{dspPlot}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{The 2-point Moving Average}
\begin{itemize}[<+->]
\item simple average:
\[
m = \frac{a+b}{2}
\]
\item moving average: take a ``local'' average
\[
y[n] = \frac{x[n]+x[n-1]}{2}
\]
\end{itemize}
\note<1>{Averages are very common operations. For example, in Switzerland, the average number of children per woman is 1.42!
You probably had to worry about the famous/infamous GPA.
Here, we are concerned about ``moving averages'', that is we compute a local average of a sequence as we go along.
The simplest case is the 2-point moving average}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{The 2-point Moving Average Using Lego}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{1}
% 1 2 3 4 5
$x[n]~~$ & \BDsplit & & \BDadd & $~~y[n]$ \\
& & \BDdelay & &
\ncline{->}{1,1}{1,4}\ncline{->}{1,4}{1,5}\taput{$1/2$}
\ncline{1,2}{2,2}\ncline{2,2}{2,3}\ncline{2,3}{2,4}
\ncline{->}{2,4}{1,4}
\end{dspBlocks}
\end{figure}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% macro to plot a signal and its two-point average. Define \avgSig prior to use
\def\avgPlot{%
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5.5cm,height=3.5cm,xticks=2]{-2,10}{-1.1,1.1}
\moocStyle
\dspSignal{x \avgSig }
\end{dspPlot}
\end{column}
\pause
\begin{column}{.5\paperwidth}
\centering
\begin{dspPlot}[width=5.5cm,height=3.5cm,xticks=2]{-2,10}{-1.1,1.1}
\moocStyle
\dspSignal{x \avgSig x 1 sub \avgSig add 0.5 mul }
\end{dspPlot}
\end{column}
\end{columns}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Let's average...}
\setbeamercovered{invisible}
$x[n] = \delta[n]$
\vspace{2em}
\def\avgSig{ 0 eq {1} {0} ifelse }
\avgPlot
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Let's average...}
\setbeamercovered{invisible}
$x[n] = u[n]$
\vspace{2em}
\def\avgSig{ 0 ge {1} {0} ifelse }
\avgPlot
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Let's average...}
\setbeamercovered{invisible}
$x[n] = \cos(\omega n), \quad \omega=\pi/10$
\vspace{2em}
\def\avgSig{ 18 mul cos }
\avgPlot
\end{frame}
\begin{frame} \frametitle{Let's average...}
\[
\cos(A) + \cos(B) = 2\cos(\frac{A+B}{2})\cos(\frac{A-B}{2})
\]
\vspace{1em}
\begin{align*}
\frac{\cos(\omega n) + \cos(\omega(n-1))}{2} &= \cos\frac{\omega n + \omega n - \omega}{2}\cos\frac{\omega n - \omega n + \omega}{2} \\
&= \cos(\omega/2)\cos(\omega n - \omega/2)
\end{align*}
\end{frame}
\begin{frame} \frametitle{Don't remember the trigonometry? No problem}
\begin{align*}
\frac{\cos(\omega n) + \cos(\omega(n-1))}{2} &= \frac{1}{2}\Real\{e^{j\omega n} + e^{j\omega(n-1)}\} \\
&= \frac{1}{2}\Real\{e^{j\omega(n - \frac{1}{2})}(e^{j\omega/2} + e^{-j\omega/2})\} \\
&= \cos(\omega/2)\Real\{e^{j\omega(n - \frac{1}{2})}\} \\
&= \cos(\omega/2)\cos(\omega n - \omega/2)
\end{align*}
\end{frame}
\begin{frame} \frametitle{Useful thing to remember}
\centering
any linear combination of trigonometric functions at frequency $\omega_0$ produces a sinusoid at the same frequency; linear combinations only alter the magnitude and phase
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Let's average...}
\setbeamercovered{invisible}
$x[n] = (-1)^n$ %\cos(\omega n), \quad \omega=\pi$
\vspace{2em}
\def\avgSig{ 180 mul cos }
\avgPlot
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Let's average...}
\setbeamercovered{invisible}
$x[n] = \cos(\omega n), \quad \omega=\pi$
\vspace{2em}
\def\avgSig{ 180 mul cos }
\avgPlot
\end{frame}
%% 1 slides on M-point MA, just with examples, M=7 for example
%\begin{frame}
% \frametitle{The M-point moving average }
% Obvious generalization: $y_n = \frac{1}{M} (x_n + x_{n-1} + ... + x_{n-M+1})$
% \begin{itemize}
% \item Dirac
% \item Constant
% \item Step
% \item Sinusoid (low frequency)
% \item Sinusoid (max frequency)
% \item Random signal
% \end{itemize}
%\end{frame}
%% TEXT: Obvious
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{What if we reverse the loop?}
\note<1>{Introducing first order recursion by reversing the MA loop}
\begin{center}
\only<1>{
\begin{figure}
\begin{dspBlocks}{2}{1}
% 1 2 3 4 5
$x[n]~~$ & \BDsplit & & \BDadd & $~~y[n]$ \\
& & \BDdelay & &
\ncline{->}{1,1}{1,4}\ncline{->}{1,4}{1,5}
\ncline{1,2}{2,2}\ncline{2,2}{2,3}\ncline{2,3}{2,4}
\ncline{->}{2,4}{1,4}
\end{dspBlocks}
\end{figure}}
\only<2->{
\begin{figure}
\begin{dspBlocks}{2}{1}
% 1 2 3 4 5
$x[n]~~$ & \BDadd & & \BDsplit & $~~y[n]$ \\
& & \BDdelay & &
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,5}
\ncline{->}{2,2}{1,2}\ncline{2,2}{2,3}\taput{$\alpha$}\ncline{2,3}{2,4}
\ncline{2,4}{1,4}
\end{dspBlocks}
\end{figure}}
\vspace{2em}
\only<3->{$ y[n] = x[n] + \alpha y[n-1]$}
\end{center}
\end{frame}
\begin{frame} \frametitle{A powerful concept: recursion}
\centering
\includegraphics[height=6cm]{hands.eps}
\end{frame}
\begin{frame} \frametitle{How we solve the chicken-and-egg problem}
\begin{center}
\textbf{Zero Initial Conditions}
\end{center}
\vspace{2em}
\begin{itemize}
\item set a start time (usually $n_0=0$)
\item assume input and output are zero for \textit{all time} before $n_0$
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{A simple model for banking}
\note<1>{Let's revisit your bank account: Assume a constant interest and borrowing rate of 5\% per year. Assume you put or take money only once a year, on Jan. 1. Interests (for positive balance) or charges (for negative balance) are calculated on Dec 31. They are added Jan 1 of the following year. Call $x_n$ the input (adding or subtracting from the account) on Jan. 1 of year $n$. Call $y_n$ the content of your account ) on Dec. 31 of year $n$. Then: $y_n = 1.05 y_{n-1} + x_n$}
A simple equation to describe compound interest:
\begin{itemize}[<+->]
\item constant interest/borrowing rate of 5\% per year
\item interest accrues on Dec 31
\item deposits/withdrawals during year $n$: $x[n]$
\item balance at year $n$:
\[
y[n] = 1.05\,y[n-1] + x[n]
\]
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Accumulation of interest: first-order recursion}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{1}
% 1 2 3 4 5
$x[n]~~$ & \BDadd & & \BDsplit & $~~y[n]$ \\
& & \BDdelay & &
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,5}
\ncline{->}{2,2}{1,2}\ncline{2,2}{2,3}\taput{$1.05$}\ncline{2,3}{2,4}
\ncline{2,4}{1,4}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{1em}
\[
y[n] = 1.05\,y[n-1] + x[n]
\]
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Example: the one-time investment}
\onslide<1->{$x[n] = 100\,\delta[n]$}
\begin{itemize}
\item<2-> $y[0] = 100$
\item<3-> $y[1] = 105$
\item<4-> $y[2] = 110.25$, $y[3] = 115.7625$ etc.
\item<5-> In general: $y[n] = (1.05)^n 100\,u[n]$
\end{itemize}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=100]{-2,10}{0,201}
\moocStyle
\dspSignal{x 0 eq {100} {0} ifelse }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\only<5->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=100]{-2,10}{0,201}
\moocStyle
\dspSignal{x 0 lt {0} {100 1.05 x exp mul} ifelse }
\end{dspPlot}}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Example: the saver}
\onslide<1->{$x[n] = 100\,u[n]$}
\note<1>{Solution to the difference equation is not obvious but say that we will know how to do that by mid-course}
\begin{itemize}
\item<2-> $y[0] = 100$
\item<3-> $y[1] = 205$
\item<4-> $y[2] = 315.25$, $y[3] = 431.0125$ etc.
\item<5-> In general: $y[n] = 2000\,((1.05)^{n+1} -1)\,u[n]$
\end{itemize}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=100]{-2,10}{0,201}
\moocStyle
\dspSignal{x 0 ge {100} {0} ifelse }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\only<5->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=500]{-2,10}{0,1500}
\moocStyle
\dspSignal{x 0 lt {0} {2000 1.05 x 1 add exp 1 sub mul} ifelse }
\end{dspPlot}}
\end{column}
\end{columns}
\end{frame}
\begin{frame} \frametitle{Aside: is it worth it to save?}
\[
\frac{y_{\mbox{saver}}[n]}{y_{\mbox{one-time}}[n]} = \frac{1 - \alpha^{n+1}}{(1 - \alpha)\alpha^n} \longrightarrow \frac{\alpha}{\alpha - 1}
\]
\end{frame}
\def\sns#1{ #1 exch exp dup #1 mul 1 sub #1 1 sub div exch div }
\begin{frame} \frametitle{Aside: is it worth it to save?}
\begin{center}
\begin{dspPlot}[sidegap=0,xticks=10,yticks=5,ylabel={saver/nonsaver},xlabel={years}]{0,50}{0,35}
\dspFunc[linecolor=blue!50]{x \sns{1.02 }}
\dspFunc[linecolor=green!50]{x \sns{1.05 }}
\dspFunc[linecolor=orange!50]{x \sns{1.1 }}
\dspFunc[linecolor=red!50]{x \sns{1.2 }}
\dspLegend(2,33){blue!50 {2\% APR} green!50 {5\% APR} orange!50 {10\% APR} red!50 {20\% APR}}
\end{dspPlot}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{Example: living off the interest}
\onslide<1->{$x[n] = 100\,\delta[n] - 5\,u[n-1]$}
\note<1>{Withdrawn amount drawn not to scale to emphasize negativity}
\begin{itemize}
\item<2-> $y[0] = 100$
\item<3-> $y[1] = 100$
\item<4-> $y[2] = 100$, $y[3] = 100$ etc.
\item<5-> In general: $y[n] = 100\,u[n]$
\end{itemize}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\only<1->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=100,xout=true]{-2,10}{-50,121}
\moocStyle
\dspSignal{x 0 eq {100} {x 1 ge {-20} {0} ifelse} ifelse }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\only<5->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2,yticks=100]{-2,10}{0,201}
\moocStyle
\dspSignal{x 0 lt {0} {100} ifelse }
\end{dspPlot}}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} \frametitle{An interesting generalization}
\begin{center}
\begin{figure}
\begin{dspBlocks}{2}{1}
% 1 2 3 4 5
$x[n]~~$ & \BDadd & & \BDsplit & $~~y[n]$ \\
& & \BDdelayN{M} & &
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,5}
\ncline{->}{2,2}{1,2}\ncline{2,2}{2,3}\taput{$\alpha$}\ncline{2,3}{2,4}
\ncline{2,4}{1,4}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{1em}
\[
y[n] = \alpha\,y[n-M] + x[n]
\]
\end{frame}
\begin{frame} \frametitle{Creating loops}
\note<1>{Consider the recursion but with delay $M$ (instead of 1) and feedback factor $\alpha$.
As engineers (and not economists) we like to choose $\alpha \leq 1$.}
\begin{center}
\begin{figure}
\begin{dspBlocks}{0.5}{1}
% 1 2 3 4 5 6 6
$\bar{x}[n]~~$ & \BDadd & & & & \BDsplit & $~~y[n]$ \\
& & \BDdelay & \BDdelay & \BDdelay & &
\ncline{->}{1,1}{1,2}\ncline{->}{1,2}{1,7}
\ncline{->}{2,2}{1,2}\tlput{$\alpha$}
\ncline{2,2}{2,3}\ncline{2,3}{2,4}\ncline{2,4}{2,5}\ncline{2,5}{2,6}
\ncline{2,6}{1,6}
\end{dspBlocks}
\end{figure}
\end{center}
\vspace{1em}
\[
y[n] = \alpha y[n-3] + \bar{x}[n]
\]
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Example}
\onslide<1->{$M=3$, $\alpha = 0.7$, $x[n] = \delta[n]$}
\begin{itemize}[<+->]
\item<2-> $y[0] = 1$, $y[1] = 0$, $y[2] = 0$
\item<3-> $y[3] = 0.7$, $y[4] = 0$, $y[5] = 0$
\item<4-> $y[6] = 0.7^2$, $y[7] = 0$, $y[8] = 0$, etc.
\end{itemize}
\setbeamercovered{invisible}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2]{-2,10}{0,1.5}
\moocStyle
\dspSignal{x 0 eq {1} {0} ifelse }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\onslide<4->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2]{-2,10}{0,1.5}
\moocStyle
\dspSignal{x cvi 3 mod 0 eq {0.7 x cvi 3 idiv exp} {0} ifelse }
\end{dspPlot}}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Example}
\setbeamercovered{invisible}
\onslide<1->{$M=3$, $\alpha = 1$, $x[n] = \delta[n] + 2\,\delta[n-1] + 3\,\delta[n-2]$}
\begin{itemize}[<+->]
\item<2-> $y[0] = 1$, $y[1] = 2$, $y[2] = 3$
\item<3-> $y[3] = 1$, $y[4] = 2$, $y[5] = 3$
\item<4-> $y[6] = 1$, $y[7] = 2$, $y[8] = 3$, etc.
\end{itemize}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2]{-2,10}{0,3.5}
\moocStyle
\dspSignal{x 0 lt {0} {x 2 gt {0} {x 1 add} ifelse} ifelse }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\onslide<4->{
\begin{dspPlot}[width=5.5cm,height=1.5cm,xticks=2]{-2,10}{0,3.5}
\moocStyle
\dspSignal{x 0 lt {0} {x cvi 3 mod 1 add} ifelse }
\end{dspPlot}}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{We can make music with that!}
\begin{itemize}[<+->]
\item build a recursion loop with a delay of $M$
\item choose a signal $\bar{x}[n]$ that is nonzero only for $0 \leq n < M$
\item choose a decay factor
\item input $\bar{x}[n]$ to the system
\item play the output
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{How do we ``play'' it, really?}
\note<1>{``periodicity'' in quotes because of decay''
This slide must refer to previous lecture on basic discrete to continuous time transitions. We need to do that lecture first ;) }
\begin{itemize}[<+->]
\item $M$-tap delay $\longrightarrow$ $M$-sample ``periodicity''
\item associate time $T$ to sample interval
\item periodic signal of frequency
\[
f = \frac{1}{MT} \mbox{Hz}
\]
\item example: $T = 22.7\mu s$, $M=100$
\[
f \approx 440 \mbox{Hz}
\]
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\setbeamercovered{invisible}
\frametitle{Playing a sine wave}
\onslide<1->{$M=100$, $\alpha = 1$, $\bar{x}[n] = \sin(2\pi\,n/100)$ for $0 \leq n < 100$ and zero elsewhere}
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,100}{-1.1,1.1}
\moocStyle
\dspSignal{x 3.6 mul sin }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\onslide<2->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,1000}{-1.1,1.1}
\moocStyle
\dspFunc{x 3.6 mul sin }
\end{dspPlot}}
\end{column}
\end{columns}
\begin{center}
\onslide<2->{\movie[inlinesound]{\fbox{\small{Play}}}{sineWave440Hz.wav}}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Introducing some realism}
\note<1>{To imitate a violin, we need to go beyond a single sine wave.\\
A crude approximation is a sawtooth wave, \\
which simulates the ``grip-and-release'' action of the\\
bow against the strings. \\
We can change the pitch by changing $M$. We can simulate a decay by choosing $\alpha < 1$.}
\begin{itemize}[<+->]
\item $M$ controls frequency (pitch)
\item $\alpha$ controls envelope (decay)
\item $\bar{x}[n]$ controls color (timbre)
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\setbeamercovered{invisible}
\frametitle{A proto-violin}
\onslide<1->{$M=100$, $\alpha = 0.95$, $\bar{x}[n]$: zero-mean sawtooth wave between $0$ and $99$, zero elsewhere}
\def\N{50 }
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,100}{-1.1,1.1}
\moocStyle
\dspSignal{x \N sub \N div }
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\onslide<2->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,1000}{-1.1,1.1}
\moocStyle
\dspFunc{x cvi \N 2 mul mod \N sub \N div}
\end{dspPlot}}
\end{column}
\end{columns}
\begin{center}
\onslide<2->{\movie[inlinesound]{\fbox{\small{Play}}}{violin440Hz.wav}}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\setbeamercovered{invisible}
\frametitle{The Karplus-Strong Algorithm}
\note<1>{To imitate a guitar, Karplus and Strong suggested the ''plucked-string algorithm'' that bears their name. Similar to previous violin simulation, except initialized with random numbers!
Change the pitch by changing $M$.
As it is a plucked string, decay is faster, with a smaller $\alpha$.}
\onslide<1->{$M=100$, $\alpha = 0.9$, $\bar{x}[n]$: 100 random values between $0$ and $99$, zero elsewhere}
\def\N{25 }
\begin{columns}
\begin{column}{.5\paperwidth}
\centering
\onslide<1->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,100}{-1.1,1.1}
\moocStyle
\dspSignalOpt{/I [ 100 {\dspRand } repeat ] def}{I x cvi 100 mod get}
\end{dspPlot}}
\end{column}
\begin{column}{.5\paperwidth}
\centering
\onslide<2->{
\begin{dspPlot}[width=5.5cm,height=3.5cm,sidegap=0,xout=true]{0,1000}{-1.1,1.1}
\moocStyle
\dspSignalOpt{/I [ 100 {\dspRand } repeat ] def}%
{I x cvi 100 mod get
x cvi \N 4 mul idiv 0.9 exch exp mul}
\end{dspPlot}}
\end{column}
\end{columns}
\begin{center}
\onslide<2->{\movie[inlinesound]{\fbox{\small{Play}}}{pluckedString440Hz.wav}}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Recap}
\begin{itemize}
\item We have seen basic elements:
\begin{itemize}
\item adders
\item multipliers
\item delays
\end{itemize}
\item We have seen two systems
\begin{itemize}
\item moving averages
\item recursive systems
\end{itemize}
\item We were able to build simple systems with interesting properties
\item to understand all of this in more details we need a mathematical framework!
\end{itemize}
\end{frame}
% TEXT: Obvious

Event Timeline