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

- 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.
- x1 = cos(2*pi*f*t) where t = [0:1/44100:0.1-1/44100]

- Display 1024 samples of the cosine with the horizontal axis expressed in seconds.
- 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 π.
- 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*= (*f*_{s }ω)/(2 π) - 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.
- 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 ?

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:

- fftbuffer = zeros(N, 1);
- fftbuffer(1:(xlength+1)/2) = x((xlength+1)/2: xlength);
- fftbuffer(N-(xlength-1)/2:N) = x(1: (xlength-1)/2);

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.

- 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)))).
- 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.
- Describe the phase relation between the negative and the positive frequency bins of the analyzed sinusoid.
- 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.

- 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())

- 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 ?

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.

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.

- 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.