Prelab 3 - Fourier Transforms

Summary

You will investigate the effects of windowing and zero-padding on the Discrete Fourier Transform of a signal, as well as the effects of data-set quantities and weighting windows used in Power Spectral Density Estimation.

Submission Instruction

Refer to the Submission Instruction page for more information.

Part 1 - Zero-padding 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 zero-padding 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 squared-magnitude frequency response of the following test cases over the digital frequencies .

Rectangular window with no zero-padding

Hamming window with no zero-padding

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

Hamming window window with zero-padding 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

importnumpyasnpimportmatplotlib.pyplotaspltfromscipyimportsignal#%matplotlib inline # Uncomment this to show figure in Jupyter NotebookN=256;# length of test signalsnum_freqs=100;# number of frequencies to test# Generate vector of frequencies to testomega=np.pi/8+np.linspace(0,num_freqs-1,num_freqs)/num_freqs*np.pi/4;S=np.zeros([N,num_freqs]);# matrix to hold FFT resultsforiinrange(0,len(omega)):# loop through freq. vectors=np.sin(omega[i]*np.linspace(0,N-1,N));# generate test sine wavewin=signal.boxcar(N);# use rectangular windows=s*win;# multiply input by windowS[:,i]=np.square(np.abs(np.fft.fft(s)));# generate magnitude of FFT# and store as a column of Splt.plot(S);# plot all spectra on same graph

Question

Describe the tradeoff between mainlobe width and sidelobe behavior for the various window functions. Does zero-padding 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, n 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

importnumpyasnpfromIPython.displayimportAudiofs=8000# Sampling Rate is 8000duration=1# 1 sect=np.linspace(0,duration,duration*fs)freq=600# Tune Frequency is 600Hztune=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 zero-padding

Hamming window with no zero-padding

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

Hamming window window with zero-padding by factor of four

Part 3 - Short-time Spectral Analysis

Short-time spectral analysis is an important technique that is used to visualize the time evolution of the frequency content of non-stationary signals, such as speech. The fundamental assumption is that the signal is modeled as being quasi-stationary over short time periods; in many speech applications, this period is on the order of 20-30 milliseconds.

The short-time Fourier transform (STFT) is defined to be:

where f is frequency, FT represents the Fourier transform , and
is a window with finite-time support centered at time
(i.e., it is non-zero 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 magnitude-squared 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 time-frequency 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 frequency-sweep signal: