




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





In the previous lab you learned about sampling. You evaluated your first FFT, and your first STFT. You witnessed the non-uniqueness of sampled signals, i.e., the same samples might belong to a completely different waveform. Now you will explore sample rate alteration and the reconstruction of waveforms. Your lab report should answer all questions in all sections.
There are moments in one’s life when time goes by too fast or too slow. Surprisingly the same thing occurs for digital systems. “System A” may be operating at 5 kHz, and “System B” at 50 kHz. If A were to communicate with B, the data rate would be 10 times too slow. As a result the data at B would not be a good representation of the original data. Instead, to communicate from A to B one would use an “upsampler,” which in effect resamples the data from A to be at 50 kHz. And to communicate from B to A one would use a “downsampler,” which in effect resamples the data from B to be at 5 kHz. In this lab section you will explore this concept that is not only fundamental to multirate signal processing, but essential for communicating between digital systems. 1.1 Sample the following signal at a rate of 10 kHz: € x ( t ) = cos( 2 π ft ), for some frequency f below the Nyquist frequency. Choose an f that best describes you. Now create a new signal by selecting every L sample from your x[n] starting with the first one, where L is a positive integer. (Hint: xd = x[1:L:end].) This is what is meant when someone says “Dude, I just downsampled the signal by a factor of L, where L is a positive integer.” To
keep the frequency of the sampled signal f, the downsampled signal must have a sampling rate of 1/L the original, or in this case 10/L kHz. Include your code and explain why the downsampled signal has a sampling rate of 10/L kHz. 1.2 For f = 1 kHz and Fs = 10 kHz, plot the spectrum of the original signal. (Just evaluate the FFT of the signal over the domain € 0 ≤ t ≤ 1 seconds.) Include all frequencies in your plot, 0-10 kHz. That means € fk = kFs N for € 0 ≤ k ≤ N − 1 , where N is the number of samples in one second. Include your graph and code. 1.3 For the sampled sinusoid created in 1.2, downsample it by factors L=2, 4, and 8. Evaluate the DFT of each sequence and plot the magnitude spectrum of each over [0:Fs’], where Fs’=Fs/L is the new sampling rate. Include your code and graph. Your graphs should resemble those in Figure 1. Figure 1: Spectrum of the signal created in 1.1, with f=1 kHz, and sampled at 10 kHz, each downsampled by a factor L
rate that could not accurately reflect it. Rapid changes in intensity in the image are being aliased to lower frequencies! The stripes meld and do not remain vertical. This is spatial aliasing plain and simple. For the speech soundfile you loaded in Lab 2, part 2.5, you saw in the sonogram that a majority of energy is located below 4 kHz. So a sampling rate of at least twice that would be adequate for representing it. 1.7 For a sampling rate of 44.1 kHz, what integer downsample factor will result in a sampling rate of about 9 kHz? Show your calculation. 1.8 For this speech file, downsample it by a factor of 5. Display the sonogram of this downsampled signal between the times 0 to 1.4 seconds, and 0 to Fs’/ in frequency, where Fs’ = 8820 Hz. Compare this spectrogram with that of the original signal. In other words make two images, one for the original signal and one for the downsampled signal with axes limited to the same range and domain. Include your code and figures. 1.9 Describe the differences between the two spectrograms. For instance, how does the distribution of energy change? Where is energy missing in the downsampled signal? Where is energy present in the downsampled signal where it is not in the original? What is happening around 1 second? 1.10 Now listen to the entirety of the two sounds: the original and the one downsampled by a factor of 5. Use soundsc, but remember to include the sample rate at which the sound should be played. If it sounds like a zombie, then you have got it wrong. Point out some of the major differences between the two sounds? As demonstrated above, like a punch to your ear, is that downsampling can be dangerous when not taking into account the frequency content of the signal. In order to downsample without fear of aliasing one needs to suppress all frequencies above the Nyquist frequency that will result from the downsampling.
For the speech file we downsampled by a factor of five, we calculated above that the new sampling rate will be 8820 Hz. That means everything above 4410 Hz will be aliased to something between 0 and 4410 Hz in the reconstruction. Therefore before we downsample the signal, let us lowpass filter it first so that we can remove the energy above this the Nyquist frequency. Use the code below to lowpass your signal before downsampling it. % Determine the order necessary for the filter to have a % passband edge of 1/5, a stopband edge of 1/4, a passband % ripple of 1 dB, and a stopband attenuation of 40 dB [N, Wn] = buttord(1/5, 1/4, 1, 40); % Obtain the filter coefficients for a lowpass filter with % a cutoff frequency of 1/ [b,a] = butter(N,1/4,'low'); % pass the signal x through the filter defined by the % coefficients in b and a xf = filter(b,a,x); 1.11 As in 1.8, display the spectrogram of this filtered and downsampled signal between the times 0 to 1.4 seconds, and 0 to Fs’/2 in frequency, where Fs’ = 8820 Hz. Compare this spectrogram with that of the original signal. In other words make two images, one for the original signal and one for the downsampled signal with axes limited to the same range and domain. Include your figure. 1.12 Make some observations of the differences between the spectrogram created in 1.8 and 1.12. For instance, at what times are there major differences? 1.13 Listen to the results of downsampling with and without prior lowpass filtering. State some observations. For instance, which is more listenable? 1.14 In what ways have you administered medicine to animals? For my dog Barney (Figure 2), we used to wrap up a pill in bologna and cheese. He would be very excited to get this handmade bologna and cheese ball; but somehow he was able to eat everything but the pill. One time we tried crushing the pill and concealing it in peanut butter. Barney ate the peanut butter, but like Sai Baba and his linghams, would reproduce and spit out a whole rematerialized pill.
Figure 3: Spectrum of the signal created in 1.1, with f=200 Hz, and sampled at 1 kHz, each upsampled by a factor L 2.3 Make a few observations of what you observe. For instance, what is happening? Does the component at f=200 Hz remain in all of them? When a signal is upsampled, aliases appear in the new baseband. Therefore, in order to make the upsampled signal have the same spectrum as the original, we need to lowpass filter after upsampling to remove these aliases and recover the spectrum of the original signal. 2.4 Use the code below to lowpass filter the signal after it has been upsampled by a factor L=3. Plot the resulting upsampled and filtered signal using stem for samples between n=[100:200]. Include your figure. If it doesn’t look something like Figure 4, seek professional help immediately —you only have two minutes left to finish and print this lab! % Lowpass filter % Determine the order necessary for the filter to have a
% passband edge of 0.4, a stopband edge of 0.5, a passband % ripple of 0.1 dB, and a stopband attenuation of 40 dB [N, Wn] = buttord(0.4, 0.5, 0.1, 40); % Obtain the filter coefficients for a lowpass filter with % a cutoff frequency of 0. [b,a] = butter(N,Wn,'low'); % pass the signal x through the filter defined by the % coefficients in b and a xuf = M*filter(b,a,xu); Figure 4: The signal created in 2.1, with f=200 Hz, and sampled at 1 kHz, is upsampled by a factor of three (top). When passed through an appropriate lowpass filter, the zero valued samples are interpolated (below). There is a delay caused by the lowpass filtering, which has been corrected above. What you just observed, if you did it correctly, is that properly lowpassing an upsampled signal interpolates the zero-valued samples! In effect you reconstructed the signal. This is in fact identical to what happens when converting a digital signal to an analog one. It is lowpass filtered to remove all aliases above the Nyquist frequency. You are now fully qualified to upsample, downsample, and administer medicine to anything.