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
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_freqs-1,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,N-1,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 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, 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 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:

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);    # Frequency-sweep 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 frequency-sweep 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 frequency-sweep signal?

Grading

Prelab 3 will be graded as follows:

  • Assignment 1 [1 point]

    Plots of the frequency response with different window and zero-padding 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]