MAEA Signals & Systems - Homework 9, Winter due by the end of class Friday March,. Question Three audio files have been placed on the class website: Waits.wav, WaitsAliased.wav, WaitsDecimated.wav. These are excerpts of Tom Waits song that we played in class. The first is, samples taken at. khz. The second and third are the same segments downsampled and decimated by a factor of 8. Read these into matlab using the command audioread: e.g. x=audioread( Waits.wav ); I have included a single channel of the stereo recording. (a) Examine the size of each vector and use the sound command to verify that you have the correct sample rates and sizes. (b) Plot each of the three signals and develop the correct time axis in seconds for each plot. (c) Compute the DFT of each signal using the fft command. Verify the sizes of the DFTs also verify the conjugate symmetry. (d) For each signal, plot the absolute value of the DFT and label the axes correctly in Hertz. (e) Using the plot function, rather than just zoom, plot the piece of the DFT of the original signal in Waits.wav which corresponds exactly to the frequencies in the other two signals. (f) Using this partial plot of the original signals DFT and the two other DFT plots, explain what you these frequency domain plots tell you about the signals and their sounds. (g) Try to construct a digital lowpass filter with cutoff frequency.9 using some of the filter design functions. [Omit the s in the argument list to get a digital filter. The.9 says the db point should be at.9 times the Nyquist frequency.] Then use the filter command to lowpass filter the aliased signal. Replot the absolute value of this signal s DFT and compare it to that of the decimated signal. Listen to the new signal and verify that aliasing has not been removed by the lowpass filtering. (h) Try to build a bandpass filter to extract the part of the sound signal between khz and khz. Listen to and describe this to see which is the part of the song which is most heavily aliased. (a) The audio signal and its sample rate can be obtained using audio read. For example [or,fs] = audioread( Waits.wav ); will return the data samples of the original audio signal, or, and its sample rate, Fs, which is.khz. To play the excerpts, use sound with the appropriate sample rate. Next, use size to examine the size of the data signals. The aliased frequency content sounds distorted. This is because this is simply the downsampled version of the original without any anti-aliasing being used. Whereas in the decimated signal,
the signal is created by decimate which applies an appropriate lowpass filter before downsampling the original signal. The frequency content is reduced by eightfold without aliasing. Below is matlab code: %----------Part (a) [or,fs] = audioread( Waits.wav );% the original [ds,fs] = audioread( WaitsAliased.wav );% the downsampled dc = audioread( WaitsDecimated.wav );% the decimated [nor, ] = size(or); %determine the size [nds, ] = size(ds); [ndc, ] = size(dc); sound(or,fs) % play back with appropriate sample rate sound(ds,fs) sound(dc,fs) (b) Time axis can be constructed from the data size and the sample rate. Figure,, are the plots of the signals with the correct time axis.. Plot of the original signal.. Signal (units) -. -. -. -.8..... Time (s) Figure : Plot of the original signal matlab code: %----------Part (b) ts = /Fs:/Fs:nor/Fs; % time axis of the original ts = /Fs:/Fs:nds/Fs; % time axis of the other versions figure() plot(ts,or)
. Plot of the downsampled signal.. Signal (units) -. -. -. -.8..... Time (s) Figure : Plot of the aliased signal title( Plot of the original signal ); xlabel( Time (s) );ylabel( Signal (units) ); figure() plot(ts,ds) title( Plot of the downsampled signal ); xlabel( Time (s) );ylabel( Signal (units) ); figure() plot(ts,dc) title( Plot of the decimated signal ); xlabel( Time (s) );ylabel( Signal (units) ); (c) After using fft on the signals, the conjugate symmetry happens about the midpoint of the output of fft. This can be verify by inspecting some elements of the DFT of the data around the midpoint using the code below: %----------Part (c) f_or = fft(or);f_ds = fft(ds);f_dc = fft(dc); [L_or, ] = size(f_or); %size of, symmetric around sample # x = f_or(9999:); %examine a small segment of f_or around # [L_ds, ] = size(f_ds); %size of, symmetric around sample # y = f_ds(9:); %examine a small segment of f_or around # where x =. -.i
. Plot of the decimated signal.. Signal (units) -. -. -. -.8..... Time (s). -.8i.8 -.8i. +.i. +.i. +.i. +.i. -.i. -.i. -.i.8 +.8i. +.8i. +.i Figure : Plot of the decimated signal which verifies the conjugate symmetry. Note that the midpoint is a real-valued number, which is the complex conjugate of itself. (d) Figures,, are the single-sided spectra of the signals with x-axes in Hertz using below code: %----------Part (d): requires single-sided DFT and x-axis being Hertz. % Use next power of from length of the signal for fft to be efficient N = ˆnextpow(L_or); % next power of from the length of the original N = ˆnextpow(L_ds); % next power of from the length of the others or_fft = fft(or,n)/l_or; %produce N-point DFT of the original f = Fs/*linspace(,,N/+);%frequency axis of the original ds_fft = fft(ds,n)/l_ds; %produce N-point DFT of the downsampled f = Fs/*linspace(,,N/+); dc_fft = fft(dc,n)/l_ds; %produce N-point DFT of the decimated
# - Single-sided magnitude spectrum of the orginal signal... # Figure : Single-sided spectrum of the original signal %since N>L, signals will be padded with zeros to length N before fft figure() stem(f,*abs(or_fft(:n/+))) title( Single-sided magnitude spectrum of the orginal signal ); figure() stem(f,*abs(ds_fft(:n/+))) title( Single-sided magnitude spectrum of the downsampled signal ); figure() stem(f,*abs(dc_fft(:n/+))) title( Single-sided magnitude spectrum of the decimated signal ); (e) The frequency content of the decimated and aliased signals is from Hz to.hz (half of their sampling frequency). The portion of the DFT of the original from Hz to.hz is plotted in Figure using the below code: %-----------Part(e) %Freq content in the other signals is [,Fs/]Hz, ie [,Fs/]Hz %The portion of the original corresponding to the above range %is from [,Fs/]Hz in the single-sided DFT in Fig above %Then the plot should have range from point to end/8 %of the original DFT plot, because in Fig the freq range is [,Fs/]H figure()
# - Single-sided magnitude spectrum of the downsampled signal Figure : Single-sided spectrum of the aliased signal f = f(:end/8);% freq range stem(f,*abs(or_fft(:(n/+)/8))) title( Spectrum of the original: freq range similar to the other signals (f) Look at Figure,, to compare the sounds of the signals. In the DFT plot of the decimated signal, the effect of the lowpass filter before the downsampling stage in decimate is clearly shown by the reduced magnitude in the high frequency content, when compared to the DFT plot of the original signal. In the high frequency range (around Hz onward) of the aliased signal, the DFT magnitude is actually bigger than that of the original signal. This is an indication of aliasing as a result of downsampling the signal without using an anti-aliasing filter in the case of the aliased sound sample. Here the higher frequencies (beyond half of the sample rate) are masquerading as lower frequencies, and their magnitude adds to that of the lower frequencies. As mentioned above, the decimated signal has been lowpass filtered before being downsampled, which eliminates aliasing in the high frequency content. (g) Figure 8 is the DFT of the aliased signal after it has been filtered by a Butterworth lowpass filter. As seen in this figure, the high frequency content of this filtered signal has been suppressed. But by listening to the signal, aliasing is still present in the form of high frequency distortion. Once aliasing has been introduced, it cannot be removed. matlab code is below: %-----------Part(g) [num,den] = butter(,.9);% cutoff (-db) at.9fs/ Hz ds_filtered = filter(num,den,ds); ds_filtered_fft = fft(ds_filtered,n)/l_ds;
# - Single-sided magnitude spectrum of the decimated signal Figure : Single-sided spectrum of the decimated signal figure(8) stem(f,*abs(ds_filtered_fft(:n/+))) title( Single-sided spectrum of the filtered downsampled signal ); (h) The frequency content of the original signal above around.khz is aliased in the aliased signal as expected earlier due to the much slower sample rate. This can be verified sonically by listening to the frequency range of the original from khz to khz using a Butterworth bandpass filter, and compare it to the aliased signal. matlab code below: %-----------Part(h) [num,den] = butter(,[ ]/(Fs/)); %bandpass filter khz & kh or_bp = filter(num,den,or); %plot DFT to see if filter really works or_bp_fft = fft(or_bp,n)/l_or; figure(9) stem(f,*abs(or_bp_fft(:n/+))) title( Single-sided spectrum of the bandpass filtered original );
# - Spectrum of the original: freq range similar to the other signals Figure : Part of spectrum of the original corresponding to the frequency content of the other two signals. # - Single-sided spectrum of the filtered downsampled signal Figure 8: Spectrum of the aliased signal after having been lowpass filtered.