0% found this document useful (0 votes)
13 views7 pages

SNP201 Mini Project

The SNP201 Mini-Project involves analyzing a signal using MATLAB, requiring students to create or find a .wav file and perform various tasks including reading the file, plotting its amplitude, and producing its magnitude spectrum. Students will also explore concepts like frequency response, spectrograms, and harmonics while documenting their process and results in a report. The final submission includes a .pdf report and the .wav file used for analysis.

Uploaded by

Sherab Wangchuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

SNP201 Mini Project

The SNP201 Mini-Project involves analyzing a signal using MATLAB, requiring students to create or find a .wav file and perform various tasks including reading the file, plotting its amplitude, and producing its magnitude spectrum. Students will also explore concepts like frequency response, spectrograms, and harmonics while documenting their process and results in a report. The final submission includes a .pdf report and the .wav file used for analysis.

Uploaded by

Sherab Wangchuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SNP201

Mini-Project: Signal Analysis


Group size: 2 students

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.

2. Read the .wav file for your signal into MATLAB.

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.

4. Play your signal.

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.

SNP201 Mini-Project: Signal Analysis 1


Aside: Spectrum

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.

SNP201 Mini-Project: Signal Analysis 2


The MATLAB command fft computes the spectrum for a signal. Whatever number of samples of
signal you provide is also the number of points the fft produces. When you plot your FFT you
should plot frequencies in Hz along the horizontal axis, starting with 0 Hz. FFT frequencies come
from:
𝑓𝑆
𝑓=𝑘
𝑁
where 𝑘 is the FFT index value (from 0 to 𝑁 − 1), 𝑓𝑆 is the sampling frequency, and 𝑁 is the number
of points in the FFT. To get the magnitude of a complex number in MATLAB, you use the abs
command.

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

10. Produce a magnitude spectrum for your signal.

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

SNP201 Mini-Project: Signal Analysis 3


like a sine wave. You may have to search for a while. Once you have found a suitable range of
samples, define a new signal that extracts just these samples. For example, if a MATLAB array is
defined as:
y = [0.1 0.2 -0.5 0.3 0.4 0.7 0.9 -0.4 0.8];

you can extract a subset of the samples with the command:


y_extract = y(4:8)

which will return:


y_extract =
0.3000 0.4000 0.7000 0.9000 -0.4000

14. In MATLAB, print the length of your extracted signal.

15. Print the duration of your extracted signal in seconds.

16. Play your windowed signal. It will be very short!

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

Click the play button at https://pulse.berklee.edu/scales/c-major-scale.html to listen to a C major


scale.

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.

SNP201 Mini-Project: Signal Analysis 4


The magnitude spectrum of the scale is shown below. You can see eight big spikes in the spectrum,
one at each note frequency. In this way, you know what frequencies are present in the signal, but
there is no sense of when the frequencies were active.

A spectrogram plots frequency versus time. It is a collection of overlapping magnitude spectrums,


which allows you to see how the frequency content of your signal changes over time. The
spectrogram for the C major scale is shown below. To convert the Normalized Frequency along the
left vertical axis to frequency in Hz, multiply by 𝑓𝑆 /2. In this case, the sampling frequency for the
.wav file used for this example was 44100 Hz, so each Normalized Frequency should be multiplied
by 22050 Hz. The yellow line at the lower left occurs at a Normalized Frequency of about 0.012,
corresponding to 265 Hz; the exact frequency of middle C is 261.63 Hz. The bottom series of yellow
bars shows the frequencies of the notes in the scale as they are played, the main melody of the
scale.

SNP201 Mini-Project: Signal Analysis 5


For each note played, you will notice above the bottom main melody track additional, slightly paler
yellow bars. These are harmonics. Many complex sounds coming from musical instruments or birds
or whales contain harmonics. Harmonics are multiples of a fundamental frequency. For any note in
the melody track at the bottom, you will see harmonics equally spaced at higher frequencies. For
example, for a note whose fundamental frequency is 261 Hz, you would look for harmonics at 522
Hz, 783 Hz, 1044 Hz, and so on. This means the higher the fundamental frequency, the wider the
spacing. This is evident in the spectrogram.

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])

19. Go back to your original signal (not the extracted one).

20. Produce a spectrogram for your signal.

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.

SNP201 Mini-Project: Signal Analysis 6


Your report:

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.

You will submit two files on VLE:

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

SNP201 Mini-Project: Signal Analysis 7

You might also like