Skip to content

Commit 7f94b9e

Browse files
committed
Update for spring 2020
A light update, mostly to take care of minor-to-moderate errata. Renumbered Matlab lab exercises so that their numbering matches the chapter numbers in the textbook. Closes #8
1 parent 302a299 commit 7f94b9e

File tree

19 files changed

+133
-108
lines changed

19 files changed

+133
-108
lines changed

Matlab Labs/Lab Book.pdf

2.31 KB
Binary file not shown.

Matlab Labs/Lab Book.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
\mbox{}\hfill
117117
\parbox{1.5in}{\mbox{}}
118-
\parbox{3in}{Fall 2016}\\[0.25in]
118+
\parbox{3in}{Spring 2020}\\[0.25in]
119119
\mbox{}\hfill
120120
\parbox{3in}{\raggedright
121121
Michael Stiber\\
@@ -148,6 +148,7 @@
148148

149149
\tableofcontents
150150

151+
\setcounter{section}{-1}
151152
\include{lab1/lab1}
152153
\include{lab2/lab2}
153154
\include{lab3/lab3}

Matlab Labs/lab1/lab1.tex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ \subsection{Matlab in a (Very Small) Nutshell}
188188
output.
189189

190190
Add three lines of code to your script, so that it will plot a cosine
191-
on top of the sine in a different color. Use the \texttt{hold}
192-
function to add a plot of
191+
using the same axes as the sine (i.e., ``on top of the sine''). Use
192+
the \texttt{hold} function to add a plot of
193193
\begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\small]
194194
0.75*cos(2*pi*f*t)
195195
\end{lstlisting}
196-
197-
to the plot. Save the plot using the MATLAB \texttt{print} command as
198-
a PNG file named \texttt{step14.png} by typing:
196+
to the plot. So, your final graph will have two functions
197+
plotted. Save the plot using the MATLAB \texttt{print} command as a
198+
PNG file named \texttt{step14.png} by typing:
199199
\begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\small]
200200
print -dpng step14
201201
\end{lstlisting}
@@ -274,7 +274,7 @@ \subsection{Trigonometric Functions and Complex Mathematics in Matlab}
274274

275275

276276
Include your code in your writeup. Additionally, include a plot of
277-
\texttt{x = sumcos(20, [0 pi/4 pi/2 3*pi/2], 200, 0.25);} versus
277+
\texttt{x = sumcos(20, [0 pi/4 pi/2 3*pi/2], [1 2 3 4], 200, 0.25);} versus
278278
time.
279279

280280
Hint: the MATLAB \verb|length| function is useful in determining the

Matlab Labs/lab2/lab2.tex

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ \section{Let's Get Physical}
1212
\subsection{Beating}
1313

1414
In this section, you will use the Matlab \texttt{AnalogSignal} class
15-
to simulate an analog signal generator. The constructor takes the
16-
following arguments:
15+
(described previously in lab~1 and its
16+
figure~\ref{fg:analogsignal-help}) to simulate an analog signal
17+
generator. The constructor takes the following arguments:
1718
\begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\small]
1819
% AnalogSignal(type, amplitude, frequency, dur)
1920
% Where:
@@ -32,7 +33,7 @@ \subsection{Beating}
3233

3334
\paragraph{Step 1.1} Verify that you can get a triangle wave. What is
3435
the code to generate and plot a triangle wave ranging from -1 to 1
35-
Volts with a frequency of 10Hz and a duration of 1sec?
36+
Volts with a frequency of 10Hz and a duration of 1 second?
3637

3738
\paragraph{Step 1.2} Next, verify that you can generate a sine wave of
3839
1 second duration at a frequency of 440Hz, ranging from -1 to +1. What
@@ -43,9 +44,10 @@ \subsection{Beating}
4344
\itshape{Xmax}])} function call to set the X axis limits so that the
4445
waveform is apparent (i.e., you're not just plotting a solid blob).
4546

46-
\paragraph{Step 1.3} Generate sine waves of identical range and
47-
duration, but with frequencies of 442, 444, and 448 Hz. Now, generate
48-
the sums of 440Hz and each of these new signals to generate beating
47+
\paragraph{Step 1.3} Generate three sine waves of identical range and
48+
duration, but with frequencies of 442, 444, and 448 Hz. Next, generate
49+
the three sums of 440Hz and each of these new signals separately (so,
50+
440Hz + 442Hz, 440Hz + 444Hz, and 440Hz + 448Hz) to generate beating
4951
akin to tuning an instrument against the 440Hz standard. Play each sum
5052
signal; can you hear the beating? Plot each sum signal for its full 1s
5153
duration. The beating ``envelope'' should be obvious. What is the beat
@@ -57,8 +59,8 @@ \subsection{Fourier series representation of a physical signal}
5759

5860

5961
\paragraph{Step 2.1} Recall that any periodic signal can be
60-
represented as a sum of harmonic sinusoids. The amplitude of each
61-
harmonic is known as the Fourier Series. It may at first seem like
62+
represented as a sum of harmonic sinusoids. The amplitudes of these
63+
harmonics is collectively known as the Fourier Series. It may at first seem like
6264
sums of sinusoids would be poor approximations of real periodic
6365
signals, but this is not the case. We can illustrate this using a
6466
triangle wave. The formula for synthesis of a triangle wave with
@@ -75,7 +77,7 @@ \subsection{Fourier series representation of a physical signal}
7577
in Hz, and so $\omega_0 = 2\pi f_0$. Notice that the Fourier Series
7678
of the triangle wave only uses odd harmonics (i.e., the only
7779
non-zero frequencies are $(2k+1)\omega_0=\omega_0, 3\omega_0,
78-
5\omega_0 \cdots$). Also notice that resulting wave will have zero
80+
5\omega_0 \cdots$). Also notice that the resulting wave will have zero
7981
mean because there is no ``DC'' term (i.e., $2k+1 \neq 0$ for any
8082
integer k).
8183

Matlab Labs/lab3/lab3.tex

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ \subsection{Sampling}
3232
sampled versions of this signal at 300Hz, 500Hz, 1000Hz, and
3333
2000Hz. Use the Matlab \texttt{subplot} command, and the
3434
\texttt{discreteplot} function provided with this class's Matlab code,
35-
to plot the original and all four sampled signals together. Clearly,
36-
the results are not the same, and none look identical to the original
37-
sine wave. What are the two essential pieces of information about a
38-
sine wave that need to be preserved when sampling it? Does it appear
39-
that all sampled versions are equally useful in achieving this? Why or
40-
why not (in other words, your answer to this question should not be
41-
just ``yes'' or ``no'')?
35+
to plot the original and all four sampled signals together. One of the
36+
things that you will note from these plots is that the X axes of these
37+
plots do not have units of continuous time; their units are \emph{not}
38+
seconds. Instead, the X axis values are sample count, starting with
39+
sample 1. You will want these plots to show their signals over the
40+
same time duration, and so you'll need to choose that duration,
41+
then figure out, for each sampled signal, how many samples correspond
42+
to that duration, and then set the X axis limits for each figure so
43+
that the plots show equal durations.
44+
45+
Clearly, the results are not the same, and none look identical to the
46+
original sine wave. What are the two essential pieces of information
47+
about a sine wave that need to be preserved when sampling it? Does it
48+
appear that all sampled versions are equally useful in achieving this?
49+
Why or why not (in other words, your answer to this question should
50+
not be just ``yes'' or ``no'')?
4251

4352
\paragraph{Step 1.3} Let's look at aliasing in a little more detail
4453
and with a lot more numerical precision. You'll recall from the text
@@ -121,13 +130,13 @@ \subsection{Analog to Digital Conversion}
121130
2, 4, 8, 12, and 16 bits quantization, and plot SNR on the Y-axis
122131
versus number of quantization bits on the X-axis.
123132

124-
\paragraph{Step 2.3} Repeat Step 3.2 using a square waveform with
133+
\paragraph{Step 2.3} Repeat Step 2.2 using a square waveform with
125134
the same parameters.
126135

127-
\paragraph{Step 2.4} Repeat Step 3.2 using a triangle waveform with
136+
\paragraph{Step 2.4} Repeat Step 2.2 using a triangle waveform with
128137
the same parameters.
129138

130139
\paragraph{Step 2.5} As you double the number of bits used in
131140
quantization, how does the SNR change? How does this compare to what
132141
your learned from the textbook? Refer to specific features of your
133-
plots from Steps~3.2--3.4 to justify your answer.
142+
plots from Steps~2.2--2.4 to justify your answer.

Matlab Labs/lab4/lab4.tex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ \subsection{Overview of Filtering and Matlab}
7979

8080
You can visualize the zero locations with the following code:
8181
\begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\small]
82-
plot(r, 'o')
82+
plot(complex(r), 'o')
8383
rectangle('Position', [-1 -1 2 2], 'Curvature', [1 1])
8484
line([-1 1], [0 0], 'Color', [0 0 0])
8585
line([0 0], [-1 1], 'Color', [0 0 0])
8686
axis equal
8787
\end{lstlisting}
88-
Here, we use the unfortunately named \verb|rectangle| function
89-
to draw the unit circle and the \verb|line| function to draw the real
90-
and imaginary axes.
88+
Here, we use the unfortunately named \verb|rectangle| function to draw
89+
the unit circle and the \verb|line| function to draw the real and
90+
imaginary axes. Note also that we have to make sure that the value of
91+
$r$ that we pass to the \verb|plot()| function is complex (since we
92+
want to plot it on the complex plane) using the \verb|complex()|
93+
function, because the roots of a polynomial can be real.
9194

9295
Finally, you can compute and plot the magnitude of the filter's
9396
frequency response pretty directly in Matlab:

Matlab Labs/lab6/lab6.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ \subsection{Feedback Filters as Recurrence Relations}
9494
\paragraph{Step 1.4} Let's do something similar with the recurrence
9595
relation for computing the series $y[n] = 1/3^n$ in the text (as
9696
always, remember that Matlab indices start at 1). Set the
97-
coefficients for a feedback filter to implement equation~(5-42) in the
97+
coefficients for a feedback filter to implement equation~(5-43) in the
9898
text, $y[n] = 1/3 y[n-1] + x[n]$. What are the filter coefficients?
9999

100100

Matlab Labs/lab7/lab7.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ \subsection{Using the DFT}
133133

134134
\paragraph{Step 2.4} Replace the sum of two sinusoids with your
135135
\verb|DTMFCoder| function from lab 6. Input a selection of button
136-
values. Does the FFT block show the separate frequencies for each
136+
values. Do the FFT function and plot show the separate frequencies for each
137137
button?
138138

139139

Matlab Labs/lab8/lab8.tex

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,22 @@ \subsection{Lossy image coding: JPEG}
240240

241241
\paragraph{Step 3.3} Let's quantize the image's spectral
242242
content. First, find the number of zero elements in the FFT, using
243-
something like \verb|origZero=length(find(abs(a)==0));|, where
244-
\verb|a| is the FFT. \emph{Remember to exclude the DC value in the
243+
something like \verb|origZero=length(find(abs(origX)==0));|, where
244+
\verb|origX| is the FFT. \emph{Remember to exclude the DC value in the
245245
\texttt{fft2} output in figuring out this range.} Then, zero out
246246
additional frequency components by zeroing out all with magnitudes
247247
below some threshold. You'll want to set the threshold somewhere
248-
between the min and max magnitudes of \verb|a|, which you can get as
249-
\verb|mn=min(min(abs(a)));| and \verb|mx=max(max(abs(a)));|. Let's
248+
between the min and max magnitudes of \verb|origX|, which you can get as
249+
\verb|mn=min(min(abs(origX)));| and \verb|mx=max(max(abs(origX)));|. Let's
250250
make four tests, with thresholds 5\%, 10\%, 20\%, and 50\% of the way
251251
between the min and max, i.e., \verb|th=0.05*(mx-mn)+mn;|. Zero out
252252
all FFT values below the threshold using something like:
253253
\begin{lstlisting}[style=Matlab-editor,basicstyle=\mlttfamily\small]
254-
b = a;
255-
b(abs(a)<th) = 0; % Uses logical array indexing
254+
compX = origX;
255+
compX(abs(origX)<th) = 0; % Uses logical array indexing
256256
\end{lstlisting}
257257
You can count the number of elements thresholded by finding the number
258-
of zero elements in \verb|b| at this point and subtracting the number
258+
of zero elements in \verb|compX| at this point and subtracting the number
259259
that were originally zero (i.e., \verb|origZero|). This is an estimate
260260
of the amount the image could be compressed with an entropy
261261
coder. Express the number of thresholded elements as a fraction of the
@@ -270,17 +270,20 @@ \subsection{Lossy image coding: JPEG}
270270
you suggest an approach that will take this into account? How does the
271271
JPEG algorithm deal with or avoid this problem?
272272

273+
\begin{sloppypar}
273274
\paragraph{Step 3.4} Now we will see the effect of this thresholding
274275
on image quality. Convert the thresholded FFT back to an image using
275-
something like \verb|c = abs(ifft2(b));|. For each type of image and
276-
each threshold value, plot the original image and the final processed
277-
image. Compute the mean squared error (MSE) between the original and
278-
reconstructed image (mean squared error for matrices can be computed
279-
as \verb|mean(mean((a-c).^2))|). What can you say about the effects
280-
on the image and MSE? Collect your code together as a script to
281-
automate the thresholding and reconstruction, so you can easily
282-
compute MSE for a number of thresholds. Plot MSE vs. threshold
276+
something like \verb|reconstructed = abs(ifft2(compX));|. For each
277+
type of image and each threshold value, plot the original image and
278+
the final processed image. Compute the mean squared error (MSE)
279+
between the original and reconstructed image (mean squared error for
280+
matrices can be computed as
281+
\verb|mean(mean((original-reconstructed).^2))|). What can you say
282+
about the effects on the image and MSE? Collect your code together as
283+
a script to automate the thresholding and reconstruction, so you can
284+
easily compute MSE for a number of thresholds. Plot MSE vs. threshold
283285
percentage (just as you plotted fraction of pixels thresholded
284286
vs. threshold in step 3.3).
287+
\end{sloppypar}
285288

286289
% LocalWords: WebQ MATLAB DSP

Matlab/AnalogSignal.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ function soundsc(sig)
215215

216216
function y = square(f, t)
217217
% SQUARE Generate a square wave with values in range [0, 1]
218+
% with 50% duty cycle
218219
% Y = SQUARE(F, T)
219220
% Where:
220221
% F = number of positive/negative waves per second

0 commit comments

Comments
 (0)