Prelab 3  Fourier Transforms
Summary
You will investigate the effects of windowing and zeropadding on the Discrete Fourier Transform of a signal, as well as the effects of dataset quantities and weighting windows used in Power Spectral Density Estimation.
Submission Instruction
Refer to the Submission Instruction page for more information.
Part 1  Zeropadding and Windowing
Since the DFT is a sampled version of the spectrum of a digital signal, it has certain sampling effects. To explore these sampling effects more thoroughly, we consider the effect of multiplying the time signal by different window functions and the effect of using zeropadding to increase the length (and thus the number of sample points) of the DFT.
Assignment 1
Using the following Python script as an example, plot the squaredmagnitude frequency response of the following test cases over the digital frequencies .

Rectangular window with no zeropadding

Hamming window with no zeropadding

Rectangular window with zeropadding by factor of four (i.e., 1024point FFT)

Hamming window window with zeropadding by factor of four
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 
import numpy as np import matplotlib.pyplot as plt from scipy import signal #%matplotlib inline # Uncomment this to show figure in Jupyter Notebook N = 256; # length of test signals num_freqs = 100; # number of frequencies to test # Generate vector of frequencies to test omega = np.pi/8 + np.linspace(0,num_freqs1,num_freqs)/num_freqs*np.pi/4; S = np.zeros([N,num_freqs]); # matrix to hold FFT results for i in range(0,len(omega)): # loop through freq. vector s = np.sin(omega[i]*np.linspace(0,N1,N)); # generate test sine wave win = signal.boxcar(N); # use rectangular window s = s*win; # multiply input by window S[:,i] = np.square(np.abs(np.fft.fft(s))); # generate magnitude of FFT # and store as a column of S plt.plot(S); # plot all spectra on same graph 
Question
Describe the tradeoff between mainlobe width and sidelobe behavior for the various window functions. Does zeropadding increase frequency resolution? Are we getting something for free? What is the relationship between the DFT, , and the DTFT, , of a sequence ?
Part 2  Resolve close Frequencies
In this section, you will resolve the two closely spaced sine waves using a Fourier transform method. Consider the signal:
consisting of two sine waves of frequency 2000 Hz and 2100 Hz with sampling frequency of 8000 Hz. Here, is the discrete time index.
The following Python code can be used to generate a pure tone:
1 2 3 4 5 6 7 8 9 10 11 
import numpy as np from IPython.display import Audio fs = 8000 # Sampling Rate is 8000 duration = 1 # 1 sec t = np.linspace(0,duration,duration*fs) freq = 600 # Tune Frequency is 600Hz tune = np.sin(2*np.pi*freq*t) # To listen to it, you can use: Audio(tune,rate=fs) 
Assignment 2
Generate a block of 256 samples of x(n) and use the Fast Fourier Transform (fft) function to determine the two frequency components. Plot the magnitude of the frequency output.
Question
What is the closest frequency to 2000 Hz that you can resolve using the Fourier transform method? Which of the following method applied to x(n) results in the best resolving capabilities? Why?
 Rectangular window with no zeropadding
 Hamming window with no zeropadding
 Rectangular window with zeropadding by factor of four (i.e., 1024point FFT)
 Hamming window window with zeropadding by factor of four
Part 3  Shorttime Spectral Analysis
Shorttime spectral analysis is an important technique that is used to visualize the time evolution of the frequency content of nonstationary signals, such as speech. The fundamental assumption is that the signal is modeled as being quasistationary over short time periods; in many speech applications, this period is on the order of 2030 milliseconds.
The shorttime Fourier transform (STFT) is defined to be:
where f is frequency, FT represents the Fourier transform , and is a window with finitetime support centered at time (i.e., it is nonzero for only a short amount of time near ).
In the case of digital time and frequency, the rate at which is evaluated, along with the block size used to compute the FFT determines the amount of data overlap that occurs in evaluating the STFT over time.
The spectrogram is just the magnitudesquared of the STFT, and can be computed in Python using scipy.signal.spectrogram.
The question of how much to overlap can be understood by asking how many time/frequency samples are required to fully represent the continuous timefrequency STFT; for the interested reader, see the section titled "Analysis of Short Term Spectra" in Allen77.
The following Python code can be used to generate a frequencysweep signal:
1 2 3 4 5 6 7 8 
import numpy as np from IPython.display import Audio from scipy import signal t = np.linspace(0,0.5,4001) s = signal.chirp(t,1000,0.5,5000); # Frequencysweep that goes from 1000 Hz to 5000 Hz in 0.5 seconds Audio(s,rate=8192) # Default rate is 8192Hz 
Assignment 3
Plot the spectrogram of x(n) you generate in part 2 with no overlap and 50% overlap. Repeat this for the the frequencysweep signal.
Hint
Use plt.specgram() to plot the spectrogram.
Question
How are the spectrograms different between no overlap and 50% overlap? What is going on at 0.4 seconds into the frequencysweep signal?
Grading
Prelab 3 will be graded as follows:

Assignment 1 [1 point]
Plots of the frequency response with different window and zeropadding settings [0.5 point]
Short answer question [0.5 point]

Assignment 2 [0.5 point]
A plot of the frequency response [0.25 point]
Short answer question [0.25 point]

Assignmet 3 [0.5 point]
Plots of the spectrogram of the two signals [0.25 point]
Short answer question [0.25 point]