Matlab_HW2.pdf

1
Sharif University of Technology
DSP
Dr. Sameti
Computer Assignment 2
Dear All,
This assignment is intended to make you familiar with MATLAB’s FilterDesign functions. Please E-mail a zip file including your M-files and the word
document to [email protected] . The name of your zip file should be
HW1_xxxxxxxx in which the 8-digit number is your student ID. Notice that all the
curves should be automatically plotted and no one will debug the codes. Choose
proper titles for your plots and use separate M-files for different problems. Try to
make each part of the problem recognizable by commenting (e.g. %a, %b, etc.). The
word document should explain all parts of each problem. If you have any questions
please contact me by email [email protected].
2
1. Analysis of Periodic Signals in the Frequency Domain
a) For the purpose of this assignment you have to load the audio file “Audio1.mp3” and bring it
to the SPtool as your input signal and apply different filters to your signal, especially the
ones you will design in the FDAtool at the following part. At last, you should study the
results and plot them as a function of time.
b) Type “wintool” at the MATLAB command line to use the Window Design and Analysis Tool.
wintool opens with a default Hamming window:
To get more familiar with the features of this toolbox read the MATLAB’s help. (Type “doc
wintool” in the MATLAB’s command line to see the guide)
Look at the time and frequency domain plots of the following 4 windows: Rectangular,
Hann, Hamming, Blackman and Kaiser. Use window length N=11. For each of the windows,
do the following:
1) Determine Main Lobe Width (MLW), Relative Side Lobe Attenuation, and Leakage Factor.
Note that with the Kaiser window, you have to use a value for 𝛽.
2) Confirm the MLW and attenuation with the known theoretical MLW and Ripple values.
3) Can you adjust 𝛽 value for Kaiser, to get, say, the rectangular window? The Blackman
window?
4) Evaluate the performance of the Kaiser window with different lengths and values of 𝛽.
3
2. Filter Design & Analysis Tool
Type “fdatool” at the command prompt to open FDATool. The Filter Design and Analysis
Tool opens with the Design Filter panel displayed.
IIR filters:
1) Design a Butterworth filter of order 15, Fc=9600, Fs=48000. Plot magnitude, zero-pole
and group delay of the above filter (Fc is the cutoff frequency.)
2) Design a Chebyshev Type I filter of order 7 and Fc=9600, Fs=48000 with maximum
tolerance of 0.3dB in pass band. Plot magnitude, zero-pole and group delay of the above
filter.
3) Design a Chebyshev Type II filter of order 7 and Fc=9600, Fs=48000 with maximum gain
of -30dB in stop band. Plot magnitude, zero-pole and group delay of the above filter.
4) Design an Elliptic filter of order 7 and Fc=9600, Fs=48000 with maximum gain of -30dB
in stop band and maximum tolerance of 0.3dB in pass band. Plot magnitude, zero-pole
and group delay of the above filter.
5) Compare results obtained in part 1 to 4. Do the results confirm your expectations?
6) Repeat part 1, but this time choose this filter to be of minimum order. Now you can assign
both Fstop and Fc. As you know you can just choose one of them (stop band or pass band)
to be matched exactly by using minimum order filters.
FIR filters:
7) Design a FIR low pass filter using Kaiser window of minimum order and Fc=9600,
Fs=48000 and Fstop=12000 with maximum gain of -30dB in stop band and maximum
tolerance of 0.3dB in pass band. Plot the magnitude and zero-pole of the above filter.
4
8) Design a FIR high pass filter using Kaiser window of minimum order and Fstop=9600,
Fs=48000 and Fc=12000 with maximum gain of -30dB in stop band and maximum
tolerance of 0.3dB in pass band. Plot the magnitude and zero-pole of the above filter.
9) Design a FIR high pass filter using Kaiser window of minimum order and Fstop1=7200,
Fs=48000 and Fc1=9600 with maximum gain of -30dB in stop band and maximum
tolerance of 0.3dB in pass band. Determine Fc2 and Fstop2 to make the response
symmetric. Plot the magnitude and zero-pole of the above filter.
3. Audio Processing (Extra Points)
Load the audio file using the format [y Fs]=wavread(‘Audio2.wav’). to that end, copy the
attached audio file into the MATLAB current directory.
a) Play the loaded file with the wavplay function. This function comes with an option called
‘async’. Explain the role of this option.
b) Use ‘upsample’ and ‘downsample’ functions with factors of 3 and play the results. Plot the
frequency spectrum of the resulting sequences.
𝐹𝑠
c) Play the file using the sampling frequencies 3Fs and . Compare both results with what you
3
d)
e)
f)
g)
have obtained in previous part.
Add white Gaussian noise to the file by adding a vector of noise generated by the ‘randn’
function to the audio sequence. Multiply this vector by different gains and compare the
results. Choose 2 gains in a manner that one dominates and audio sequence; while the other
one is audible but does not dominate the audio sequence thoroughly; then plot the frequency
spectrum of the main audio sequence in addition to the 2 cases explained above.
This time add the noise only to the magnitude of the frequency spectrum. Explain the
difference between adding noise to the original audio file directly and adding it to the
magnitude of the frequency spectrum.
In this part, add the white Gaussian noise to the phase of the frequency components. Try
different gains and explain the results.
Define the ideal lowpass filter function as following:
Output_signal = FFT_LP(input_signal , cutoff_frequency,
passband_gain)
Utilize this function to filter out the frequency components outside the [-2kHz, 2kHz] interval.
Play and Listen to the result, and explain the differences. Also, plot the frequency spectrum
of the filtered sequence.
5
h) Define a time vector for the interval t = [0 , 3]s with 6000 points and then generate the
sequence 𝑢 = 𝑠𝑖𝑛(900𝜋𝑡); then play the sequence using ‘wavplay’.
i) Downsample the sequence by the factor of 2 and play the result with the original sampling
rate. Explain the differences with last part, and plot the FFT of the resulting sequence.
j) Downsample the sequence by the factor of 6 and play the result with the original sampling
rate. Comment on the result and its difference with the previous part, and plot the FFT of the
resulting sequence.