Lab-3: Properties of the Discrete Fourier Transform

The goal of this lab is to look at different properties of the Discrete Fourier Transform.

3.1: Spectral leakage

  1. Create a cosine of 0.1 second at a sampling rate of 44100 Hz, with a frequency multiple of 44100/1024, for example 10*44100/1024. 
  2. Display 1024 samples of the cosine with the horizontal axis expressed in seconds.
  3. Compute an FFT of size N = 1024 of the signal x1 and display its magnitude spectrum (only the positive part). Use the "*" mode for plot, plot(abs(y),"*"). The horizontal axis should show the frequency ω in radians per second. This means that the frequency range goes from 0 to π.
  4. From the magnitude spectrum, read out the frequency of the cosine and compare it with the original frequency you used when generating it. To calculate the frequency in Hz use the formula f = (fs ω)/(2 π)
  5. Compute two other cosine functions x2 and x3 with frequencies at 10.25 and 10.50 times 44100/1024 and display 1024 samples of the cosines.
  6. Calculate the FFT of the two cosines x2 and x3, display the magnitude spectrum and try to identify their frequencies. What has changed ? Try to explain it ?

3.2: DFT phases

The phases spectrum gives information about the exact position in time of the different spectral components. In order to better visualize the phase, the sound has to be centered at time zero, called zero-phase windowing, otherwise it has a time-offset and that means that there is a complex exponential factor in the phase. So, before computing the FFT of size N of an array x of size x-length (which should be an odd value and smaller than N) you have to shift the array samples to time zero by:

In Octave, the phases are computed using arg() (help arg) and in Matlab using angle() (help angle). In order to remove the effect of the modulus 2π of the phase spectrum use the function unwrap(). Be aware that the only relevant phase values are the ones for which there is some energy at the given spectral components you are looking at.

  1. Compute the fft of size 1024 of an odd number of samples (ex: 801) of sound x1, using  zero-phase windowing and unwrapping. Use plot(unwrap(arg(fft(fftbuffer, 1024))))
  2. Compute the of the signal x1 with a different phase offset (ex: start the FFT at sample 5 of the vector x1 instead of sample 0). Display the phase of this FFT.
  3. Describe the phase relation between the negative and the positive frequency bins of the analyzed sinusoid.
  4. Compute and display the amplitude and the phases of signal x2 using subplot(2,1,1). The first plot should show the amplitude and the second one the phase.

3.3: Time - Frequency duality

An impulse in the time domain corresponds to a constant offset in the frequency domain (and the other way around). 
  1. Create a vector z of 1024 zeros and set the first value to 1. ( z = zeros(1,1024); z(1)=1 ). Display the magnitude, the real values and the complex values of the FFT of the vector (use the functions real() and imag())

A rectangular function in the time domain corresponds to a sinc (sin(x)/x) function in the frequency domain. 
  1. Set all values from index 1 to 30 of vector z to one and display the function and its spectral content (the magnitude of the FFT). What can you say about the resulting function ? Set the values from index 1 to 60 to 1 and display its spectral content. What changed ?
The convolution is defined by

One of the properties of the DFT is that multiplication in the spectral domain corresponds to circular convolution in the time domain and the other way round. The convolution of a function with an impulse function is equal to the function itself.
  1. Multiply the cosine function from exercise 1 with the rectangular function you have just created. Calculate the FFT from the result and display its magnitude. Explain the result.

The inverse discrete Fourier transform (or IFFT) converts a signal from the spectral domain to the time domain.
  1. Generate a signal in the spectral domain by puting a value in the appropiate spectral bin and convert it to the time domain using ifft(). The resulting time-domain signal should be a cosine with frequency of 646 Hz. Choose an fft size that is a power of 2. Sampling rate is 44100 Hz. Display both, the original spectrum and the time domain signal.