Matlab_HW1_Revised.pdf

1
Sharif University of Technology
DSP
Dr. Sameti
Computer Assignment 1
Dear All,
This assignment is intended to make you familiar with MATLAB’s DSPrelated 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 just contain your answers to the explanatory questions
presented in each problem. If you have any questions please contact me by email
[email protected].
2
1. Analysis of Periodic Signals in the Frequency Domain
1
a) Consider the signal π‘₯(𝑑) = sin(2πœ‹π‘“π‘‘ + πœƒ) + cos(2πœ‹4000𝑑) , plot this signal for 𝑓 = 10 and
πœ‹
πœƒ = 6 using the command plot. Generate a discrete time vector with length 100000 with
time interval [0,10]𝑠 and assume the sampling rate of 10π‘˜π»π‘§.
b) Plot the phase and magnitude of the spectrum of the above mentioned signal using the
function fft.
c) Apply fftshift function on the result and plot the output’s magnitude. Describe the
difference made.
d) Try to use three periods of the signal to determine and sketch the magnitude and phase of
the spectrum. How and why these plots differ from the previous parts?
e) Now define the function below to implement a discrete time lowpass filter
Output = FFT_LP (input, cutoff_frequency, passband_gain)
That implement a discrete time lowpass filter and cutoff frequency is over [0, πœ‹]. Use ifft
with the β€˜symmetric' option for calculating the invers Fourier transform in the function,
and explain what is does.
f) Apply this filter on the signal x and try to diminish the higher frequency component (4 kHz).
Plot the result in both time and frequency domains (use fftshift).
2. Z transform
a) Consider the following difference equation for 0 ≀ 𝑛 < 300:
𝑦[𝑛] βˆ’ 𝑦 [𝑛 βˆ’ 1] + 0.9 𝑦[𝑛 βˆ’ 2] = π‘₯[𝑛] βˆ’ π‘₯[𝑛 βˆ’ 2]
Calculate the impulse response of the above mentioned filter for 0 ≀ 𝑛 < 300 without using
MATLAB’s built in functions and display your impulse response using stem.
b) Using impa and steps functions calculate the impulse and step response and display
them in two separate figures.
3πœ‹π‘›
8
c) Calculate and show the output of the filter for input sequence π‘₯1[𝑛] = sin (
5πœ‹π‘›
) π‘œπ‘£π‘’π‘Ÿ
8
cos (
0 ≀ 𝑛 < 300 using the filter function.
d) Calculate and plot the magnitude of the DFT of the above sequence.
+
πœ‹
)+
16
3
e) Downsample and unsample x1[n] by the factor of 3 using downsample and unsample
functions. Calculate and show the filter output for the two new signals.
f) Utilize freqz and zplane commands in order to display the pole-zero diagram of the filter,
then discuss whether the filter is stable or not. Also, try to explain the results obtained in
parts (c) and (d) based on the diagram and your knowledge.