Assignment 2: FFT and Zero-padding SUBMISSION DEADLINE Friday 03 March 2020 at 5pm Electronic submission (only) through Brightspace

**Task1: Spectrum of a truncated cosine wave**

Consider the following analogue sinusoid x(t) = Acos(2πft) where A = 5.0 and f = 2 kHz.

• Starting from t = 0 and assuming the sampling frequency fs = 8 kHz, generate N = 128 samples of the above sine wave. Let x denote the obtained sequence of 128 samples.

• Plotxandcommentontheperiodicityof x. Verifyyourcommentsusingappropriate equations. To plot functions involving digital signals, use the ‘stem’ command in Matlab.

• Compute the FFT of x, and call it X. Note that X is complex.

• Plot the magnitude of X (i.e. the magnitude spectrum) where the zero-frequency component is shifted to the centre of the spectrum. Why do you see the two peaks at the positions they appear?

• Experiment with different number of samples, e.g. N = 127 samples, and comment on the magnitude spectrum plots.

Dr Nam Tran EEEN30050: Signal Processing

Task2:

Zero Padding In all magnitude spectrum plot sin this task, you need to shift the zero-frequency component to the centre of the spectrum.

• Generate N = 67 samples of a sine wave of frequency f = 330.5 Hz and sampled at fs = 1024 Hz. Call it x.

• Compute the FFT of x, and call it X. • Plot the magnitude of X where the x-axis is the discrete-time frequency. Mark important frequencies of Xon the x-axis (e.g. ±π,±f fs2π).

• Pad zero-valued samples to x so that the resulting signal (called x1) contains M = 128 samples.

• Compute the FFT of x1, and call itX1.

• Inthesamefigureforplottingthemagnitudeof X(use the ‘holdon’ command), plot the magnitude of X1(i.e. the FFT of the zero padded sequence).

• In the same figure as the above,compute and plot the magnitude of the DTFT of x. Comment on what you see.

#### Task3: Musical Notes

Detection You are given an audio file (i.e “note.wav” in Brightspace) that contains a note recorded from a piano and your task is to detect that particular note. Notethatwhenaparticularnote is played on a musical instrument not only is the fundamental frequency(tone), denoted by f, generated but also higher harmonics of the fundamental, i.e., pure tones at the frequencies 2f, 3f, 4f,…. Theseharmonicsgivetheinstrumentarichersound. Start with the following code [y,Fs]=audioread( ’note.wav’) ; % Fs is the sampling frequency used to record the note x = y(: ,1) ; % get the first audio channel

• Plot x to see the time domain waveform of the note.

Dr Nam Tran EEEN30050: Signal Processing Health and Safety

You will be listening to the sound contained in the file “note.wav”. If you are using headphones or in-ear devices, you must take precautions so as not to damage your hearing: Alwayscheckthesoundlevelby first holding the headphone or ear pieces away from your ear.