EE 450 Project 2

pdf

School

Grossmont College *

*We aren’t endorsed by this school

Course

450

Subject

Electrical Engineering

Date

May 25, 2024

Type

pdf

Pages

10

Uploaded by queenhabibi715

Report
EE-450 Project #2 Frequency-Domain Analysis of Discrete-Time Systems 1. Use MATLAB to find the DTFT of and plot its magnitude and phase for . You need to use “ freqz ” function in MATLAB (do not forget to use “ unwrap function!) 2. Find the impulse response of the following system and plot its frequency response (both magnitude and phase). . 3. Find the output of the system to given in part 1 using two different methods: a. Find it directly using “ filter ” function (initial conditions are zero). b. Find it by using the frequency response method (DFTF and IDTFT). You can use invfreqz ” to find the inverse DTFT. 4. Plot the outputs obtained from both methods and the error between them all in one window. What does the error signal show? x [ n ] = (0.5) n u [ n ] p w £ £ 0 ] 2 [ ] 1 [ 2 ] [ ] 3 [ 01 . 0 ] 2 [ 03 . 0 ] 1 [ 6 . 0 ] [ - - - + = - - - + - + n x n x n x n y n y n y n y ] [ n x Name: Wael Alkinan RedID: 824130548
EE-450 Project #2 Frequency-Domain Analysis of Discrete-Time Systems (1). Use MATLAB to find the DTFT of and plot its magnitude and phase for . You need to use “freqz” function in MATLAB (do not forget to use “unwrap” function!) % Define the signal x[n] n = 0:50; % Define the range of n x = (0.5).^n .* heaviside(n); % Compute the signal values % Compute the DTFT of x[n] w = linspace(0, pi, 1000); % Define the range of w X = freqz(x, 1, w); % Compute the DTFT magX = abs(X); % Compute the magnitude of the DTFT phaseX = unwrap(angle(X)); % Compute the phase of the DTFT % The signal x[n] has no denominator coefficients, we can set them to 1. figure(1) % Plot the magnitude and phase of the DTFT subplot(2,1,1); plot(w, magX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'Magnitude of DTFT of x[n]' ); grid minor subplot(2,1,2); plot(w, phaseX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'Phase of DTFT of x[n]' ); grid minor 1
(2). Find the impulse response of the following system and plot its frequency response (both magnitude and phase). To find the impulse response of the system, we can set the input x[n] to be the impulse function, which is 1 for n = 0 and 0 otherwise. Then the output of the system will be the impulse response h[n]. When the difference equation becomes: 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
To solve for h[n], we can use the z-transform. Taking the z-transform of both sides of the equation yields: Solving for H(z), we get: To find h[n], we can use the inverse z-transform. We can use partial fraction decomposition to express H(z) in terms of simpler fractions, and then look up the corresponding inverse z-transforms in a table. The partial fraction decomposition is: Taking Inverse Z-transform and using table, we have: To plot the frequency response of the system, we can take the Fourier transform of the impulse response. The magnitude and phase of the frequency response can be computed using the abs and angle functions in MATLAB, respectively. Here's the MATLAB code to compute and plot the frequency response: 3
% Define the impulse response h[n] n = 0:50; h = heaviside(-n) + (1 - heaviside(-n)).*(10.^(-n-5) .* (-972222*(-5).^n + 755555.*((-1).^n % Compute and plot the frequency response w = linspace(0, pi, 1000); H = freqz(h, 1, w); magH = abs(H); phaseH = unwrap(angle(H)); figure(2) subplot(2,1,1); plot(w, magH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'Magnitude of Frequency Response' ); grid minor subplot(2,1,2); plot(w, phaseH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'Phase of Frequency Response' ); grid minor 4
(3). Find the output of the system to given in part 1 using two different methods: a. Find it directly using “filter” function (initial conditions are zero). b. Find it by using the frequency response method (DFTF and IDTFT). You can use “invfreqz” to find the inverse DTFT. Using filter Function % Define the input signal x[n] n = 0:99; x = (0.5).^n.*heaviside(n); % Define the system impulse response h[n] h = heaviside(-n) + (1 - heaviside(-n)).*(10.^(-n-5) .* (-972222*(-5).^n + 755555.*((-1).^n % Compute the output using the filter function y1 = filter(h, 1, x); figure(3) subplot(1,2,1) % Plot the input signal stem(n, x); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid minor subplot(1,2,2) % Plot the output signal stem(n, y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n]' ); grid minor 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The resulting plot should show the input signal x[n] as a decaying exponential, and the output signal y[n] as a damped sinusoid. using the frequency response method % Define the input signal x[n] n = 0:99; x = (0.5).^n.*heaviside(n); % Compute the DTFT of the input signal X = fft(x); % Compute the frequency response of the system w = linspace(0, pi, length(X)); H = freqz(h, 1, w); % Multiply the DTFT of the input signal by the frequency response of the system Y = X .* H; % Compute the IDTFT of the product to obtain the output signal y2 = real(ifft(Y)); figure(4) 6
subplot(1,2,1) % Plot the input and output signals stem(n, x); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid minor subplot(1,2,2) stem(n, y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n]' ); grid minor 4. Plot the outputs obtained from both methods and the error between them all in one window. What does the error signal show? figure(5) subplot(3,1,1) % Plot the output signal stem(n, y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); 7
title( 'Output Signal y[n] using Filter function' ); grid minor subplot(3,1,2) % Plot the output signal stem(n, y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] using Frequency response' ); grid minor y_error = y1-y2; subplot(3,1,3) % Plot the output signal stem(n, y_error); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Error signal (difference between the two methods' ); grid minor The resulting plot should show three subplots, one for each signal: the output obtained using the filter function, the output obtained using the frequency response method, and the error signal (the difference between the two methods). 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The error signal shows the discrepancy between the two methods. Ideally, the error signal should be zero, indicating that both methods produce exactly the same output. In practice, however, there may be small differences due to numerical precision issues, finite-length effects, or other factors. The magnitude of the error signal indicates the size of the discrepancy between the two methods, while its phase indicates the phase difference between the two signals. By analyzing the error signal, we can gain insights into the limitations of each method and identify ways to improve their accuracy. 9