1 Sharif University of Technology Computer Engineering Department DSP Dr. Manzuri Computer Assignment 1 Dear All, This assignment is intended to make you familiar with MATLAB’s DSP-related functions. Please e-mail a zip file including your Mfiles and the word document to [email protected]. The subject of your mail and the name of your zip file should be HW1_xxxxxxxx in which the 8-digit number is your student ID. Note that all the curves should be automatically plotted and no one will debug the code. Choose proper titles for your plots and separate M-files for each problem. 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. 2 1. Ideal Filtering a) Define a vector for the time interval [0,2s] with 44100 points per second (the sampling rate is 44.1kHz) b) Generate the following vectors in the above-mentioned time interval and plot the results over [0,5ms] using stem and xlim (samples of the continuous-time signal) : cos 2 cos 2 400 400 0.5 cos 2 4000 1 c) Use fft function to compute and plot the magnitude of the DFT of the sequence x. Be careful of the interval over which the output lies. d) Apply fftshift function on the result and plot the output’s magnitude. Describe the difference made. e) What is the relationship between the computed DFT and the fourier transform of the continuous-time signal? Plot the magnitude of the fourier transform of the continuoustime signal as well. f) Define a function output_signal=FFT_LP (input_signal,cutoff_frequency,passband_gain) that implements a discrete-time lowpass filter. The input and output signals are in time domin and the cutoff frequency is over 0, . Use ifft to calculate the inverse fourier transform (use the ‘symmetric’ option and explain what it does) g) Apply this filter on the sequence x and try to diminish the higher frequency component (4kHz). Plot the result in both time and frequency domains (use fftshift). 2. FIR Filtering a) Define a vector as following: 1 1 4 4 that represents the impulse response of a moving average system. plot the magnitude and phase of the fft of the sequence. b) As you see the result does not look like the DTFT of the sequence. Try to somehow modify the vector to increase the number of samples given by fft function to over 100. Plot the magnitude and phase of the fft for the new sequence. c) Use unwrap function and plot the phase again. Describe the difference made. 1 DTFT of a vector is a continuous function with a period of 2 . DFT of a vector gives a number of samples of the DTFT equal to the length of the vector in the time domain and equally spaced along the interval [0, 2 ]. Check out MATLAB’s help for further information. 3 d) Now define the function output_signal=moving_average(input_signal,M1,M2) that implents a moving average filter with parameters M1 and M2 doing calculations in the time domain (Adjust the output length properly). e) Apply this function on the sequence x as defined in problem 1. Try to choose a proper set of M1 and M2 so as to attenuate the higher frequency component. Plot the result in both time and frequency (phase and magnitude) domains. Comment your choice of M1 and M2 as well. What is the difference between the impulse response of the moving_average filter and the FFT_LP filter in both time and frequency domains? 3. Z-Transform & Sampling a) Calculate and stem the impulse response of a system defined by the following difference equation for 0 100: 1 2 1 b) Now use impz and stepz functions to calculate and stem the impulse and step responses. c) Calculate and stem the output of the system for the following input sequences over 0 100 using filter function: cos 6 1 d) Calculate and plot the magnitude of the DFT of the above sequences. e) Downsample both sequences by 2 and plot the magnitude of the DFT for the resulting signals. Also stem the output of the filter for the resulting input signals (Use downsample). f) Now Upsample both sequences ( and ) by 3 and plot the magnitude of the DFT for the resulting signals. Stem the output of the filter for these input signals as well (Use upsample). g) Use zplane and freqz and plot the results (Magnitude and Phase). Referring to these diagrams, discuss the system’s stability and the results you have observed in parts e and f.
© Copyright 2025 Paperzz