You are on page 1of 4

Lab S: Sampling and Aliasing

The domain of Matlab is discrete time signals, and without delving into the world of hardware, it is impossible for us to truly consider the problems of sampling and reconstructing.
We can fake it though, by using over-sampled signals or computed-on-demand functions and
concentrating on the boundary where discrete-time effects get strange.

0.1
0.1.1

Simple Examples
Chirp Folding

Remember that chirps are signals with linearly increasing frequency. That is x(t) = cos((t+
0 )t + ).
1. Using a sampling frequency of 8000 Hz, generate a chirp signal that goes from 200 Hz
to 800 Hz. Listen to it. Make a spectrogram of it.
2. Now make a chirp that goes from 200 Hz to 10200 Hz. Listen and make a spectrogram.

0.1.2

Sinusoid Sampling

1. Generate about 20 periods of a sinusoid of your choice. Choose a sampling frequency


to get at least 20 samples per period.
2. On the same plot or in subplots, generate 4 more sinusoid plots by using different
sampling rates, covering a range of apparent frequencies, including some sinusoids
that appear to have a higher frequency than others for which the sampling frequency
was higher. That is, by choosing different, slower, sampling rates, you should be
able to get very low apparent frequencies. If you continue to decrease your sampling
frequency, you should then higher apparent frequencies (though not as high as your
original signal).

0.1.3

Folding in Music

1. Find a .wav file of a simple song (preferably one with distinct notes and minimal
singing). Read it into Matlab using wavread. Note that Matlab cannot read all kinds
of .wav files and you may have to try more than one to find one for which the wavread
1

command is successful. http://www.chivalry.com/cantaria/ has a collection of files


that might be suitable. Your lab 3 songs are another good choice.
2. If the song is longer than 30 seconds, take a subsection of it. Also, if the song is in stereo
(it has two columns), isolate one of them with xx = song(:, 1) or xx = song(1,
:). Make a spectrogram of that subsection. Look at how high up the energy in the
spectrum goes.
3. Subsample the data (with a command like yy = xx(1:N:length(xx)) and play it
with the new sampling frequency to see when you can notice the distortion. Can you
subsample the signal enough to hear the high notes become low notes?

0.2

Adjusting Pitch

Using these methods, you can adjust the pitch of a sound without adjust its length, or visa
versa. We will concentrate on the former since it is less programmatically intensive. See the
figure for a graphical representation of our method. This method allows us to finely adjust
the pitch within a limited range, so long as we are willing to down-sample the original data
by 2.

1. Generate your low-pass filter using the equation X() =


x[n] =

1, 0 || W
0, W < ||

sin(W n)
n

Where W is 2(.25 fx /fs ) and fx is the desired frequency shift. Use the equation on
the right to get the frequency-domain representation on the left. n should go from 0
to between 50 and 500.
Plot the result. Now plot(abs(fftshift(fft(xx)))) where xx is your x[n] above to
see the spectrum. Comment on any abnormalities.
2. Using your low-pass filter, perform the sequence of functions shown in the figure.
You can use commands like plot(abs(fftshift(fft(xx)))) to confirm that your
method is going according to plan. You can apply the low-pass filter with the command
conv(xx, lowpass) (where xx is the input and lowpass is the filter). conv will return
vectors longer than its inputs, so you may want to generate your t vectors for the cosines
on-the-fly with (0:1/fs:((length(uu) - 1) / fs)). Note that the f s used in the
second cosine-modulation should be 1/2 of the original f s.
3. Listen to and make a wavwrite of the result. Comment on its effectiveness. Try doubly
applying the lowpass filter everywhere that you apply it.
4. Make your code a function which takes sound data, a sampling frequency, and a shift
frequency and returns subsampled data with the appropriate shift.

You might also like