Music 421 Spring 2004-2005 Homework #2 Windows and Fourier Theorem Review 60 points Due in one week (4/14/2005)
1. In this problem you will write 2 matlab functions, and at least the second will be very useful to you in the rest of the course. Turn in a copy of your code for each part. (a) (3 pts) Write a matlab function that windows and zero pads an input signal. Your function should take 3 arguments: input to be windowed, window to be used, and final length of the zero padded sequence. The code below will get you started. function [output_sig] = zeropadwin(input_sig, window, padded_length) % function windows a signal and adds zeros to the end % check that input_sig is the same size vector as the window: % multiply window by input_sig: % add zeros to end so that length(output_sig) is padded_length: output_sig = (b) (5 pts) Write a matlab function that zero-phase windows and zero pads an input signal. This is the same as the previous problem, except you must be careful about the order of the output. The output should look similar to Figure 1.21(b) of SASP (p. 34 in the May 2004 draft). 2. In the previous homework, you (hopefully) Blackman windowed a sinusoid (1000 Hz (cosine) of N samples, at a sampling rate of 8192 Hz, with amplitude 0.6 and phase 0.25*2*π radians).
N = 1024; % FFT size = window length w = (.42 - .5*cos(2*pi*(0:N-1)/(N-1)) + .08*cos(4*pi*(0:N-1)/(N-1)))’; % Blackma
Now consider a frequency of 1024 Hz, but other quantities the same. When plotting frequency responses in this problem, always normalize for a peak value of 0 dB, and always use fftshift() so that the frequency 0 is in the center of the plot. (a) (2 pts) Plot the log magnitude spectrum of the windowed signal. Do not zero pad the signal. Find the maximum side-lobe level (two digits accuracy is sufficient). (b) (1 pt) Repeat the above item for a frequency of 1023 Hz. You may expect a seemingly very different answer. 1
(c) (2 pts) Now, zero-pad the windowed signal to a length of 8192. Plot the log magnitude spectrum (with the maximum value normalized to 0 dB). Find the side-lobe level graphically for both the 1023 Hz sinusoid and the 1024 Hz sinusoids. (d) (5 pts) (Important.) Why do you get such different results on the last part compared with the previous parts? 3. In this problem, we consider the important question of what happens to the frequency response of a window when we change its length and/or the sampling rate considered. When plotting frequency responses in this problem, always normalize for a peak value of 0 dB, and always use fftshift() so that frequency 0 is in the center of the plot. (a) (2 pts) Plot using (using stem()) the time domain representation of a 51 sample rectangular window, zero phase zero padded to length 256. Double label the time axis in both samples and seconds, assuming a sampling rate of 8192 Hz. How long is your window in seconds? (b) (2 pts) Plot the log-mag frequency response of the window, and label the frequency axis in Hz. Manually (or using Matlab) label the frequency of the first positive zero crossing in Hz. (c) (2 pts) Change the window length to 81 samples and repeat the previous item. How long is this window in seconds? (d) (2 pts) Using the window length 81 samples, change the sampling rate to 8000 Hz. How long in seconds is the window now? Plot the log-mag frequency response of the window, and label the frequency axis in Hz. Manually label the frequency of the first positive zero crossing in Hz. 4. (8 pts) Repeat the previous problem for a Hann window. Compare and contrast the main lobe width and side lobe level for analogous plots. 5. (4 pts) Consider the 8 point DFT of some arbitrary input, where the sample rate is 3 Hz. Write the frequency in Hz represented by every point of the DFT. 6. (4 pts) For the sequence x(n) = [1 : 8, 8 : −1 : 1] (MATLAB notation), plot STRETCH2 (x) and its magnitude spectrum. 7. (3 pts) Given a mixture of signals with lots of harmonics and a filter with a rectangular impulse response, what length M would you choose for the filter to get rid of all the harmonics (frequency less than half the sampling rate) of frequency f0 in the mixture? What if the filter impulse response is now a triangular function as defined in HW1? Verify the result for the case of a rectangular impulse response as follows: (a) (2 pts) In MATLAB, generate a sum of cosines having frequencies 400,800,1200 Hz and 300,600,900 Hz, i.e., the sum of two harmonic sources of fundamental frequencies 400 and 300 Hz. Use the sampling frequency fs = 8kHz and the signal duration of 1 second.
2
(b) (2 pts) Find the value of M of a rectangular impulse response which will get rid of the harmonics of the source with the fundamental frequency of 400Hz. Construct the rectangular impulse response of the filter. (c) (3 pts) Show in time-domain(by convolution) or frequency-domain(by FFT) that all harmonics of the 400Hz source are more or less gone. Plot the spectrum of the original mixed signal as well as the signal after filtering. Also, verify the result by listening. (Use verb=soundsc(x,fs)= to listen to a signal in Matlab. Is it what you expected from the plots? 8. (5 pts) Derive the expression and sketch the window w(n) corresponding to the window transform 1 1 W (ω) = asincM (ω + ω1 ) + asincM (ω) + asincM (ω − ω1 ) 2 2 where ω1 = 2π/M 9. (3 pts) Suppose we used an exponential window (Poisson window) on a recorded impulse response, with a window decay time-constant of τ = 1 second, and a sampling rate of fs = 1 sample/second. In this application, the window is used in “zero-phase form,” so that the left half of it is applied to zeros when the windowed signal is causal, as is the case for real-world impulse responses. The window length was 15 samples, thus spanning 14 seconds. To the 7-second impulse response remaining after applying the window, we fit a one-pole filter, obtaining H0 (z) =
1 1 − e−1 z −1
We now wish to undo the effect of the exponential window to obtain the final model H(z) = H0 (z/α) for some appropriate value of α. Find α, H(z), and the final model impulse response h(n) for this problem.
3