Lab S: Sampling and Aliasing: 0.1 Simple Examples
Lab S: Sampling and Aliasing: 0.1 Simple Examples
Lab S: Sampling and Aliasing: 0.1 Simple Examples
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
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
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, 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.