Calculating DTFT in MATLAB
It is not hard to see that you may use the function freq resp you wrote in Lab 5 to calculate the DTFT of any finite-length signal (why?). Hereafter in this lab, rename the function as below:
X = dtft(x,w)
where x is the input signal vector, w is a (normalized radian) frequency vector, and X is the DTFT vector of x calculated at the frequencies specified in w. For an infinite-length signal, we have to truncate it in order to use the function dtft to approximately calculate the DTFT of the signal.
Note that the method used in dtft is a computationally inefficient way to calculate the DTFT of a signal, as you will see in the latter parts of the lab. We will talk about how to do DTFT calculations in a much more computationally efficient way later in the semester.
Table of Discrete-Time Fourier Transform Pairs
Discrete-Time Fourier Transform : X(ejb) = X x[n]ejnb
Inverse Discrete-Time Fourier Transform :
Dirac delta function that repeat every 2 : 2(b) = X (b 2k)
k=
x[n] | X(ejb) | condition |
[n] | 1 | |
[n n0] x[n] = 1 | 2 | |
u[n]ejb0ncos(0n) b | ) is periodic with period 2 |
Table of Discrete-Time Fourier Transform Properties
For each property, assume
) and
Property | Time domain | DTFT domain |
Linearity | Ax[n] + By[n] | AX(ejb) + BY (ejb) |
Time Shifting | x[n n0] | |
Frequency Shifting | X( 0) b b | |
Conjugation | x[n] | X(ejb) |
Time Reversal | x[n] | X(ejb) |
ConvolutionMultiplicationDifferencing in TimeAccumulationFrequency DifferentiationParsevals Relation for Aperiodic Signals | nx[n] |
Lab 6 Exercises
- Unless stated otherwise, you must submit your solutions to all the lab exercises in this section.
- Your laboratory solutions should be submitted on Canvas as a single PDF. The simplest way is to put your codes and answers for all the lab exercises in a single MATLAB Publisher script and use %% to separate the codes and answers for different exercises into different sections as described in the information section of Lab 1.
- Plot all magnitude spectrums in this lab in dB scale.
Exercise 6.1:
This exercise shows you how to carefully interprete the results obtained from your MATLAB function dtft, particularly for the cases of infinite-length signals.
Use the tables in the information section, or otherwise, to analytically determine the expressions of the DTFTs for the signals below. Use your MATLAB function dtft to calculate and plot (magnitude and angle) the DTFTs. For each signal, truncate its length to 10, if needed, when using your function dtft to calculate the DTFT. Compare your plot with the DTFT expression you obtain analytically. Do they match? Repeat the same MATLAB calculation of the DTFT and comparison with the analytic expression by truncating each signal to length 100 instead. Explain the effects of increasing the truncation length.
- x[n] = [n 3]
- x[n] = (8/9)nu[n]
- x[n] = (8/9)nu[n]
- x[n] = u[n] u[n 5]
- x[n] = cos((/4)n)
Exercise 6.2: (Nulling Filter)
This exercise shows you how to employ DTFT to analyze an audio signal corrupted by a sinusoidal interfering signal. Specifically, you will examine the DTFT to determine the frequency of the sinusoidal interference and then use a nulling filter to remove the interference. The corrupted audio signal is provided in the WAV file corrupted wannabe.wav.
- Load corrupted wannabe.wav into MATLAB. Use your function dtft to calculate the DTFT of the audio signal. Plot the magnitude of the DTFT. Hint: You should use a frequency vector that has at least 2000 points to calculate the DTFT so as to properly identify the interference frequency in part (b) below. It may take a minute or so to compute the DTFT.
- Identify the frequency of the sinusoidal interference. Give this frequency in normalized radian frequency as well as continuous-time cyclic frequency. Hint: You may use ToolsData Tips to identify the value of interference frequency from the DTFT magnitude plot. You may also use the MATLAB function find (see Lab 5) to more accurate determine the frequency of interest.
- Consider the following nulling FIR filter:
y[n] = x[n] 2cos(wb0)x[n 1] + x[n 2], (1)
This filter can remove a sinusoid at the normalized radian frequency specified by wb0. Design this filter to remove the interference that you identified in (b), i.e. specify the impulse response of the resulting filter in the vector h. Use your function dtft to calculate and plot the magnitude response and phase response of the filter.
- Apply the nulling filter to the corrupted audio signal. Listen to the filtered audio and save it to the WAV file filtered wannabe.wav. Submit the WAV file. Use your dtft function to calculate and plot the magnitude of the DTFT of the filtered audio signal. Describe the differences between the DTFTs of the original audio and the output of the nulling filter, particularly with respect to the interference signal.
Exercise 6.3 (Extra credits: +20 points):
This exercise is similar to Exercise 6.2. An audio signal (not the same as the one in Exercise 6.2) is corrupted by a very strong artificial noise (not a simple sinusoidal interference). You again need to use your dtft function to study the frequency contents of the corrupted audio signal, identify the frequency range of the noise components, and design a filter to remove the noise. The theory behind how to design a filter that can remove the noise here is a bit too advance for us. Instead of going through the theory, this exercise shows you how to use a MATLAB filter design GUI to work out the required filter.
Load in the noisy audio signal from the WAV file what did he say.wav. Use your dtft function to calculate and plot the magnitude of the signals DTFT. Identify the frequency range of the noise. Express your answer in both normalized radian frequency and continuous-time cyclic frequency. To remove the noise in this case, you will need to employ a filter different than the nulling filter in Exercise 6.2. State what kind of filter (lowpass, highpass, bandpass) is needed to remove the noise. Determine the start and end frequencies of the passband and stopband of the filter.
MATLAB has a GUI filterDesigner that helps you design a filter. Type filterDesigner in the command window to invoke the GUI. You may select the type of the filter that you want to design. Based on your answer above, choose whether you want to design a lowpass, highpass, or bandpass filter. Choose FIR Equiripple. Choose the Filter Order to be Minimum order. Specify the sampling frequency, start and end frequencies of the passband and stopband. You will also need to specify the ripple tolerance in the passband (Apass) and the magnitude attenuation from the passband to stopband (Astop). It suffices to choose Apass = 1 dB. You will need to choose a suitable value for Astop. For example, Astop = 60 dB means that the value of the magnitude response in the stopband is 60 dB below that in the passband. After specifying all the parameters, click the Design Filter button to generate the filter impulse response. You can save the generated impulse response to your workspace by choosing FileExport, and then specifying Export to Workspace, Export as Coefficients, and setting Numerator to your choice of a variable name to hold the impulse response. Click the Export button to export the impulse response to your workspace.
Use the GUI to design a filter that can remove the noise. Report all the parameters that you specify in the GUI. Export the impulse response of the filter to your MATLAB workspace. Apply this filter to the noisy audio signal. Listen to the filtered signal and save the filtered audio to the WAV file filtered what.wav. Submit the WAV file. Write down the sentence dictated in the audio file. Use your dtft function to calculate and plot the magnitude of the DTFT of the filtered audio signal. Describe the differences between the DTFTs of the original audio and the output of the noise removal filter, highlighting what and how much noise components are removed by the filter.
Note that you may need to iterate the above filter design process a few times to generate a relatively clean and audible audio signal.
Reviews
There are no reviews yet.