SNP201 Mini Project
SNP201 Mini Project
In this mini-project you will analyze a signal in a number of ways. Many of the MATLAB commands
and operations that you will need were introduced in previous labs, but some will be new, and you
may need to search for information online. All the steps of the mini-project should be
accomplished within MATLAB.
The commands, results, and question answers for each step should appear in your mini-project
report. You can use fprintf to print sentences from your .m file.
1. Find or create a .wav file. This can be a recording of any signal: speech, music, bird sounds,
or anything else you like. A signal that has some clear melody or pitch changes may be slightly more
convenient to work with, but you can experiment with any kind of signal. The duration of your signal
should at least 5 seconds, and no more than 5 minutes long.
3. Print the size of your signal. Is it mono or stereo? If it is stereo, select the data for only one of
the channels (left or right) to proceed. Assign the length of your mono signal to a variable. Note the
difference between the size and length commands.
5. Create a labelled plot of your signal that shows signal amplitude versus sample number. If
necessary, use the axis command to make sure there is no white space at the right of your plot.
Add gridlines to your plot.
6. Create a second labelled plot of your signal. This one should show signal amplitude versus
time in seconds. Again make sure there is no white space at the right, and add gridlines to your plot.
7. Use the info = audioinfo(...) command to display information about your signal.
8. You can access audio information using constructs like info.SampleRate. Print, with
labels and units: the sampling rate, the number of samples, and the number of bits per sample.
What is the duration? How is duration calculated from SampleRate and TotalSamples?
9. Click on the time plot for your signal at the maximum and minimum amplitudes. What is the
maximum amplitude of your windowed signal? At what time does it occur? What is the minimum
amplitude of your signal? At what time does it occur? Include a plot that illustrates the required
data.
In SNP201 you have already learned about the frequency response of a system, by which you can
know the gain and phase shift of your system for inputs of any frequency.
You have not yet learned how to calculate what frequencies are present in a signal. The frequency
content of a signal is called its spectrum. Like the frequency response, the spectrum is complex-
valued, so there are two parts: the magnitude spectrum, which displays the magnitude of the
components at each frequency, and the phase spectrum, which displays the relative phase shifts
of the frequency components. Usually the magnitude spectrum is the most useful.
When you push a button on your phone’s keypad, you hear a DTMF tone made of two separate
frequencies, one from the row and one from the column.
For key 4, the two frequencies 770 Hz and 1209 Hz play. The time plot for this DTMF key is shown at
the left, while the magnitude spectrum is shown at the right.
In the following copy of the magnitude spectrum, the frequencies of the peaks are marked. You can
verify that the frequencies correspond to DTMF key 4. You many notice that there is a second set of
peaks towards the right. These peaks are merely mirrors of the first set and do not represent signal
frequency content. The sampling frequency for this example was 8 kHz. The midpoint of the plot is
at half the sampling frequency. This is also the Nyquist limit; no frequency in a sampled system can
be greater than 𝑓𝑆 /2 Hz.
For example, try the following MATLAB code. You should be able to understand what is going on for
each line of code, and use similar ideas for your mini-project work.
Fs = 8000;
t = 0:1/Fs: 0.1;
x = sin(2*pi*1000*t);
N = length(x)
plot((0:N-1)*Fs/N, abs(fft(x)))
grid on
11. The most interesting content in your magnitude spectrum is probably squeezed to the far
left. Make a second magnitude spectrum plot, this time using the axis command to select a range
of frequencies that more clearly displays the important frequency content.
12. Looking at the magnitude spectrum, what appear to be the most important frequencies or
range of frequencies in your signal? Include a spectrum with the data points marked. Note that you
can drag the data labels so they do not overlap.
13. Make a copy of the commands you used in step 5 to create the plot of signal amplitude
versus sample number. Use the axis command to find a part of your signal that looks somewhat
17. Create a labelled plot of your extracted signal showing signal amplitude versus time in
seconds. Make sure there is no white space at the right of your plot, and add gridlines.
18. Produce a magnitude spectrum for your extracted signal. Use the axis command to
display the most important content in your spectrum. Since you extracted a portion of your signal
that looked very sinusoidal, the magnitude spectrum for your extracted signal should show a single
frequency. What is the frequency? Mark a point on your spectrum to show this data.
Aside: Spectrogram
A time plot of a C major scale (ascending only) might look like the graph below. Eight notes are
playing, from middle C to the C one octave above.
To create a spectrogram of a signal y in MATLAB, use the lines of code suggested here. Hamming
refers to the shape of the window used to select overlapping sections of the signal y. The 'yaxis'
argument ensures frequency will be plotted along the vertical axis of the spectrogram. You can
experiment with the numbers given in the spectrogram command to see the effects on your
spectrogram. The first and last numbers should be equal; the middle number should half of the
others. The axis command plots Normalized Frequency from 0 to 0.05. At a sampling frequency of
44100 Hz, this corresponds to 0 to 1102.5 Hz. If the sampling frequency is much lower or higher
than 44100 Hz, choose a maximum Normalized Frequency that corresponds to about 1 kHz.
spectrogram(y,hamming(2048),1024,2048,'yaxis')
axis([0 length(y)-1 0 0.05])
21. Can you identify frequency changes in your signal over time? Describe how the visual
evidence in your spectrogram follows what you hear when you play your signal.
22. Can you identify harmonics in any part of your spectrogram? Explain.
Your report should describe the sound you chose. For each step of the project, you should include
the exact MATLAB commands you used, along with the output produced by your MATLAB
commands, such as plots or other data. Include answers to questions close to the plots they refer
to. Your plots should have titles and also labels on each axis. Use full sentences. Your report should
be easy to read and understand, without requiring reference to these mini-project instructions.
Once you have a MATLAB .m file, you can easily experiment with other signals. If you try several
signals, please include some comments about how the time plots, spectra, or spectrogram
compare.
1. Your mini-project report as a .pdf (include a full listing of your MATLAB .m file at the end of your
report)
2. Your .wav file