1 Pre-Lab: ECE 2026 Fall 2018 Lab #5: Spectrograms: Harmonic Lines & Aliasing
1 Pre-Lab: ECE 2026 Fall 2018 Lab #5: Spectrograms: Harmonic Lines & Aliasing
1 Pre-Lab: ECE 2026 Fall 2018 Lab #5: Spectrograms: Harmonic Lines & Aliasing
Pre-Lab: You should read the Pre-Lab section of the lab and do all the exercises in the Pre-Lab section
before your assigned lab time. While this section does not need to be turned in, it provides a very helpful
start to the lab so you have a better understanding of how to complete the lab verification portion.
Verification: The exercise section of each lab must be completed during your assigned Lab time and the
steps marked Instructor Verification must also be signed off during the lab time. When you have com-
pleted a step that requires verification, simply raise your hand (or whatever procedure has been established
in your lab section) and demonstrate the step to the TA or instructor. Turn in your signed verification sheet
to your TA before leaving the lab. No extra time can be allotted for completing the lab verification portion
so please come prepared.
Lab Homework Questions: The Lab-Homework Sheet has a few lab related questions that can be answered
at your own pace. The completed Lab-HW sheet is due at the beginning of the next lab.
Forgeries and plagiarism are a violation of the honor code and will be referred to the Dean of Students
for disciplinary action. You are allowed to discuss lab exercises with other students, but you cannot give
or receive any written material or electronic files. In addition, you are not allowed to use or copy material
from old lab reports from previous semesters. Your submitted work must be your own original work.
Due Date: The lab homework will be due during the week of 15–18. Oct. at the start of your lab.
1 Pre-Lab
This section must be completed prior to attending your lab.
1.1 Objective
The objective of this lab is to study further the spectral content of signals analyzed via the spectrogram.
There are several specific steps that will be considered in this lab:
1. Synthesize a linear-FM chirp with a M ATLAB M-file, and display its spectrogram. Choose the chirp
parameters so that aliasing will happen.
2. Synthesize a periodic triangle wave with a M ATLAB M-file, and display its spectrogram. Relate the
harmonic line spectrum to the fundamental period of the triangle wave.
3. Compare spectrograms using two different scales for amplitude: decibels (dB) and linear.
4. Examine details of the harmonic lines in the dB spectrogram of the triangle wave.
5. Spectrogram: make a spectrogram of your voice signal, and relate the harmonic line spectrum to your
previous measurement of pitch period.
1
1.2 Chirp or Linearly Swept Frequency
A linear-FM chirp signal is a sinusoid whose instantaneous frequency changes linearly from a starting value
to an ending one. The formula for such a signal can be defined by creating a complex exponential signal
with a quadratic angle function ψ(t). Mathematically, we define ψ(t) as
The derivative of ψ(t) yields an instantaneous cyclic frequency that changes linearly versus time.
1 d
fi (t) = ψ(t) = 2µt + f0 (Hz) (2)
2π dt
The slope of fi (t) is equal to 2µ and its t = 0 intercept is f0 . The frequency variation in (2) produced by the
time-varying angle function is called frequency modulation, so these signals are called FM signals. Finally,
since the linear variation of the frequency (2) can produce an audible sound similar to a siren or a bird chirp,
linear-FM signals are also called chirps.
where tn is the nth time sample. The following M ATLAB code will synthesize a linear-FM chirp:
fSamp = 8000; %-Number of time samples per second
dt = 1/fSamp;
tStart = 0;
tStop = 1.5;
tt = tStart:dt:tStop;
mu = 1200;
fzero = 400;
phi = 2*pi*rand; %-- random phase
%
%% psi = ????; <================ FILL IN THE CODE HERE
%
cc = real( 7.7*exp(j*psi) );
soundsc( cc, fSamp );
plotspec( cc+1e-12j, fSamp, 256 ), colorbar, grid on %-- with negative freqs
tt=0:(1/fs):tStop;qq=rem(tt,T);xx=Amp*(abs(qq-(0.5*T))-0.25*T);
2
1.4 Decibels
The common log scale used in engineering is decibels (dB), which is defined as 20 log10 (A) where A is a
positive amplitude. Some special cases that are easy to remember: An amplitude of A = 1 maps to 0 dB;
an amplitude of A = 10 maps to 20 dB; an amplitude of A = 0.1 maps to −20 dB. The built-in M ATLAB
spectrogram M-file uses a dB scale for amplitude when displaying its spectrogram image. The decibel has
two notable features:
20 log10 (A2 ) = 20 log10 (A1 /10) = 20 log10 (A1 ) − 20 log10 (10) = 20 log10 (A1 ) − 20 dB.
Since ratios become differences, dB is most often used to compare the relative size of values.
2. As the amplitude A approaches zero, its value in dB approaches −∞. This is because 20 log10 (0) =
−∞. Therefore, if we were to take amplitudes that range from 0 to 1 and try to plot them on a dB
scale, we would need the dB range of the y-axis to be from −∞ dB to 0 dB. This is not practical. In
practice we must restrict the dB range to something practical, for example −80 dB to 0 dB, or −120
dB to 0 dB. The minimum dB level will chop off the bottom of [0, 1] and make it equal to [, 1] where
is very small. For example, a dB range of 80 dB would define the minimum to be −80 dB, which
corresponds to = 10−80/20 = 10−4 = 0.0001.
for a zero-mean triangle wave, i.e., after dropping the DC term a0 , and whose maximum amplitude is 0.5,
• Evaluate the coefficients for k = 1, 3, 5 and 15. Then compute the ratios a3 /a1 , a5 /a1 and a15 /a1 .
Comment: Here’s a general question: are the Fourier Series coefficients independent of time scaling?
(By time scaling we mean y(t) = x(bt); scaling the time variable by a constant b. For example, a plot of
x(3t) will be squeezed along the horizontal axis by a factor of b = 3.)
What are the Fourier coefficients of y(t) = x(bt) in terms of the Fourier coefficients of x(t) ? If x(t)
has a period equal to T , then the period of y(t) is T /b because x(t) is squeezed by b. Thus, the fundamental
frequency of y(t) is (T2π/b) = b( 2π
T ), i.e., it is scaled by b.
Now we write the Fourier Series integral for y(t)
TZ
/(2b) TZ
/(2b)
3
Make a change of variables: λ = bt, and with dλ = b(dt), you get
ZT /2 ZT /2
−j(2πk/T )λ
b(1/T ) x(λ)e (1/b)dλ = (1/T ) x(λ)e−j(2πk/T )λ dλ = ak
−T /2 −T /2
The scaling factor b cancels to give the RHS. So, time scaling doesn’t change the {ak } coefficients. The
Fourier Series coefficients of y(t) are exactly equal to the Fourier Series coefficients of x(t).
2 Lab Exercise
For the lab exercise, you will synthesize some signals, and then study their frequency content by using the
spectrogram. The objective is to learn more about the connection between the time-domain definition of the
signal and its frequency-domain content.
For the instructor verification, you will have to demonstrate that you understand concepts in a given
subsection by answering questions from your lab instructor (or TA).
(a) What happens when we make a signal that “chirps” up to a very high frequency, and the instantaneous
frequency goes past half the sampling rate? Generate a chirp signal that starts at 1200 Hz when
t = 0 s, and chirps up to 12, 000 Hz, at t = 4 s. Use fs = 4000 Hz. Determine the parameters needed
in (1).
(b) Generate the chirp signal in M ATLAB and make a spectrogram with a short section length, LSECT , to
verify that you have the correct starting and ending frequencies.1 For your chosen LSECT , determine
the section duration TSECT in secs.
(c) Explain why the instantaneous frequency seen in the spectrogram goes up and down between zero
and fs /2, i.e., it does not chirp up to 12,000 Hz. There are two effects that should be accounted for in
your explanation.
Note: If possible listen to the signal to verify that the spectrogram is faithfully representing the audio
signal that you hear.
4
2.2.1 Spectrogram of Periodic Triangle Wave
(a) Write a simple M ATLAB script that will generate a periodic triangle wave once the period is given.
The DC level of the triangle wave should be zero, and the peak amplitude should be equal to 1. Here
is a M ATLAB one-liner that can form the basis of this script:
tt=0:(1/fs):tStop;qq=rem(tt,T);xx=Amp*(abs(qq-(0.5*T))-0.25*T);
The values of fs, tStop, T, Amp will be given in the following exercises.
(b) Generate a triangle wave with a period of 8 msec, using a sampling rate of fs = 10000 Hz. The
duration should be 3 secs. Then make a plot of a short section of the signal consisting of 3–5 periods
to verify that you have the correct time waveform.
(c) Make a spectrogram with a long section duration.2 It is important to pick a section duration that is
equal to an integer number of periods of the periodic triangular waveform created in the previous part.
Define TSECT to get exactly 5 periods, and then determine the section length LSECT (an integer) to be
used in plotspec.
(d) You should expect to see a “harmonic line spectrum” in the spectrogram. Since frequency is along the
vertical axis, the harmonic lines will appear as horizontal lines in the spectrogram. Make a list of all
the harmonic frequencies that you can see in the spectrogram.
(f) Measure the amplitudes of the first and third harmonic lines by using M ATLAB’s Data Cursor af-
ter zooming in on those parts of the spectrogram image. Record the values for the amplitudes and
compute the ratio.
for a zero-mean triangle wave that varies between ±0.5, Thus, in the spectrogram we should see harmonic
lines at f0 , 3f0 , 5f0 , etc. Furthermore, there should be an infinite number of harmonic frequency lines.
Where did all the harmonics go?
The answer is that the higher harmonics have amplitudes that are too small to be seen in a spectrogram that
displays values with a linear amplitude. Instead, a logarithmic amplitude scale is needed.
Consult Section 2.2.2 in the Pre-Lab for a discussion of decibels, and then answer the following questions
about decibels:
(a) In the language of dB, a factor of two is “6 dB.” In other words, if B2 is 6 dB bigger than B1 , then it
is twice as big (approximately). Explain why this statement is true.
2
A long section duration in the spectrogram yields what is called a narrowband spectrogram because it will provide excellent
resolution of the frequency components of a signal.
5
(b) The nonzero Fourier coefficients of the triangular wave are ak = π−2
2 k 2 . Determine the dB difference
between a1 and a3 . In other words, a3 is how many dB below a1 . Furthermore, explain why the dB
difference depends only on the k indices.
(c) Determine (in dB) how far a15 is below a1 for the periodic triangular wave.
2.2.3 Spectrogram in dB
A variation of the SP-First function plotspec has been written to incorporate the dB amplitude scale. This
new function is called plotspecDB and can be downloaded from the lab page on canvas. Its calling template
is shown below:
function him = plotspecDB(xx,fsamp,Lsect,DBrange)
%PLOTSPECDB plot a Spectrogram as an image (displaying magnitude in dB)
% usage: him = plotspec(xx,fsamp,Lsect,DBrange)
% him = handle to the image object
% xx = input signal
% fsamp = sampling rate
% Lsect = section length (integer, power of 2 is a good choice)
% amount of data to Fourier analyze at one time
% DBrange = defines the minimum dB value; max is always 0 dB
(a) Create a “dB-Spectrogram” for the 8-msec periodic triangular wave generated in Sect. 2.2.1. Use a
dBrange equal to 60 dB or 80 dB (whichever looks “best” to you for viewing the spectrum lines).
Notice that many more spectrum lines are now visible. List the frequencies of all the harmonic
spectrum lines, or give a general formula.
(b) Generate a second triangle wave by changing the period to 16 msec. Then make the dB-Spectrogram
of this 16-msec triangle wave, being careful to select the section duration as an integer number of
periods. From the spectrogram, determine the fundamental frequency and also the frequency of the
highest harmonic line. Also, determine the harmonic number for the highest frequency, e.g., the 17th
or 31st , etc.
(c) For the 16-msec triangle wave, measure the amplitudes (in dB) of the first and third harmonic lines by
using M ATLAB’s Data Cursor after zooming in on those parts of the spectrogram image. Compare
the dB difference to the ratio obtained in Section 2.2.1, part (f).
Instructor Verification (separate page)
(d) Change the period to 4 msec and make another dB-Spectrogram. Be careful to select the section
duration as an integer number of periods. This period is shorter but the frequency separation of the
harmonic lines is greater. Notice that this inverse relationship was also true when comparing the
16 msec case to the 8 msec case.
6
2.3 Lab-Homework: dB Spectrogram of Your Voice
Obtain a recording of a single vowel sound (You may use the one you made from Lab #1, make a new one,
or borrow a vowel sound from the web). Make a dB spectrogram with a ”long” section length. Since the
vowel region of the recording is a signal that is quasi-periodic, the spectrogram should exhibit a harmonic
line characteristic during that time. Try different section lengths until the harmonic lines are easy to see in
the spectrogram.
1. Turn in a print out of the spectrogram. Annotate the spectrogram to show the vowel region, as well as
parameter values and measurements such as:
The values of TSECT and LSECT used.
The measured frequency separation of the harmonic lines that are seen in the vowel region.
2. From the frequency separation, compute the fundamental frequency in the vowel region. Also deter-
mine the fundamental period for this fundamental frequency.
3. Measure (or recall the value in Lab #1 if you used that signal) the pitch period (in secs). Compare the
fundamental period determined in the part 2.
7
ECE 2026 Lab #5 Fall 2018
INSTRUCTOR VERIFICATION SHEET
Turn this page in to your lab grading TA before the end of your scheduled Lab time.
Verified: Date/Time:
Part 2.2.1 Spectrogram of periodic triangle wave using a long section duration.
(b) TSECT = and LSECT =
(d) List frequencies of visible harmonics =
(e) Fundamental Frequency =
(f) |a1 | = and |a3 | =
Verified: Date/Time:
Verified: Date/Time:
Verified: Date/Time:
8
Lab #5
ECE 2026 Fall 2018
LAB HOMEWORK QUESTION
Turn this page in to your lab grading TA at the very beginning of your next scheduled Lab time.
Part 2.3 Using the vowel sound that you recorded for Lab #1 (or you can make a completely new one
or borrow a vowel sound from the web), make a dB spectrogram with a long section length. Since the vowel
region of the recording is a signal that is quasi-periodic, the spectrogram should exhibit a harmonic line
characteristic during that time. Try different section lengths until the harmonic lines are easy to see in the
spectrogram.
1. Turn in a print out of the spectrogram. Annotate the spectrogram to show the vowel region, as well as
parameter values and measurements such as:
The values of TSECT and LSECT used.
The measured frequency separation of the harmonic lines that are seen in the vowel region.
2. From the frequency separation, compute the fundamental frequency in the vowel region. Also deter-
mine the fundamental period for this fundamental frequency.
3. Measure (or recall the value in Lab #1 if you used that signal) the pitch period (in secs). Compare the
fundamental period determined in the part 2.