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

12

Uploaded by queenhabibi715

Report
EE-450 Project-2 Frequency-Domain Analysis of Discrete-Time Systems Maria Dawood 822489441 March rd, 2024
1. Use MATLAB to find the DTFT of and plot its magnitude and phase 𝑥[𝑛] = (0. 5) 𝑛 𝑢[𝑛] for . You need to use “freqz” function in MATLAB (do not forget to use 0 ≤ ω ≤ π “unwrap” function!) This questions instructs us to use MATLAB to calculate and visualize the Discrete Time Fourier Transform (DTFT) of the given signal . This is accomplished by 𝑥[𝑛] = (0. 5) 𝑛 𝑢[𝑛] employing the “freqz” function to compute the DTFT and then plotting both the magnitude and phase of the resulting transform. The magnitude plot reveals how much of each frequency component is present in the signal, while the phase plot shows the phase shift that each component undergoes. Using the “unwrap” function ensures that the phase plot is continuous, making it easier to interpret. This process is crucial for understanding the frequency characteristics of the signal, which is essential in fields like signal processing and communications. Matlab Code: % Initialize the signal x[n] index_n = 0:50; % Setting the range for n x_signal = (0.5).^index_n .* heaviside(index_n); % Calculating the values for the signal % Calculate the Discrete Time Fourier Transform (DTFT) of x[n] omega = linspace(0, pi, 1000); % Defining the omega range X_dtft = freqz(x_signal, 1, omega); % DTFT calculation magnitudeX = abs(X_dtft); % Magnitude of the DTFT phaseX = unwrap(angle(X_dtft)); % Phase of the DTFT % Since there are no denominator coefficients in x[n], we use 1. figure(1) % Display the magnitude and phase of the DTFT subplot(2,1,1); plot(omega, magnitudeX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'DTFT Magnitude of x[n]' ); grid on % minor grid is not available in all MATLAB versions, using 'on' for broader compatibility subplot(2,1,2); plot(omega, phaseX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'DTFT Phase of x[n]' ); grid on % Using 'grid on' for compatibility
Output: 2. Find the impulse response of the following system and plot its frequency response (both magnitude and phase. To determine the system's impulse response, the input signal x[n] is designated as the delta function, characterized by a value of 1 at n = 0 and 0 at all other values. The resulting output from the system, denoted as h[n], will represent the impulse response of the system. When the difference equation becomes: 𝑥[𝑛] = δ[𝑛] ℎ[𝑛] + 0. 06ℎ[𝑛 − 1] + 0. 03ℎ[𝑛 − 2] − 0. 01ℎ[𝑛 − 1] = δ[𝑛] + 2δ[𝑛 − 1] − δ[𝑛 − 2] To compute h[n], we can employ the z-transform technique. By applying the z-transform to each side of the equation, we obtain: 𝐻(𝑧) + 0. 06 𝑧 −1 𝐻(𝑧) + 0. 03 𝑧 −2 𝐻(𝑧) − 0. 01 𝑧 −3 𝐻(𝑧) = 1 + 2 𝑧 −1 − 𝑧 −2 Then solving for H(z), we then will get the following:
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
𝐻(𝑧)(1 + 0. 6𝑧 −1 + 0. 03𝑧 −2 − 0. 01𝑧 −3 ) = (1 + 2𝑧 −1 − 𝑧 −2 ) 𝐻(𝑧) = (1+2𝑧 −1 −𝑧 −2 ) (1+0.6𝑧 −1 +0.03𝑧 −2 −0.01𝑧 −3 ) 𝐻(𝑧) = (𝑧 3 +2𝑧 2 −𝑧) (𝑧 3 +0.6𝑧 2 +0.03𝑧−0.01) To determine h[n], the inverse z-transform can be applied. By breaking down H(z) into simpler fractions through partial fraction decomposition, we can then reference a table to find the corresponding inverse z-transforms for these simpler terms. The decomposition process is as follows: 𝐻(𝑧) = 1 − 0.438889 (−0.1+𝑧) 3.02222 (0.2+𝑧) + 4.86111 (0.5+𝑧) 𝐻(𝑧) = 1 − 0.438889𝑧 −1 (1−0.1𝑧 −1 ) 3.02222𝑧 −1 (1+0.2𝑧 −1 ) + 4.86111𝑧 −1 (1+0.5𝑧 −1 ) By taking the inverse z-transform and using the table we then will have: ℎ[𝑛] = 𝑢[− 𝑛] + (1 − 𝑢[− 𝑛])[10 −𝑛−5 (− 972222(− 5) 𝑛 + 755555(− 1) 𝑛 2 𝑛+1 − 438889)] To visualize the system's frequency response, we apply the Fourier transform to the impulse response. In MATLAB, the “abs” and “angle” functions are utilized to calculate the magnitude and phase of the frequency response, respectively. Below is the MATLAB script to execute the computation and plotting of the frequency response: Matlab Code: % Initialize the impulse response h[n] index = 0:50; h = heaviside(-index) + (1 - heaviside(-index)) .* (10.^(-index - 5) .* (-972222 .* (-5).^index + 755555 .* ((-1).^index))); % Calculate and display the frequency response frequency = linspace(0, pi, 1000); H_freq = freqz(h, 1, frequency); magnitudeH = abs(H_freq); phaseH = unwrap(angle(H_freq)); figure(2) subplot(2,1,1); plot(frequency, magnitudeH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'Frequency Response Magnitude' );
grid on ; % Changed to 'grid on' for compatibility subplot(2,1,2); plot(frequency, phaseH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'Frequency Response Phase' ); grid on ; % Changed to 'grid on' for compatibility Output: 3. Find the output of the system to x[n] 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 a) I will first be using the filter function in matlab to find the output system of x[n]. Matlab Code: % Specify the input signal x[n] sample_points = 0:99; input_sequence = (0.5).^sample_points .* heaviside(sample_points); % Establish the impulse response of the system h[n] impulse_response = heaviside(-sample_points) + (1 - heaviside(-sample_points)) .* (10.^(-sample_points - 5) .* (-972222 * (-5).^sample_points + 755555 .* ((-1).^sample_points))); % Determine the system's output using the filter function
output_y1 = filter(impulse_response, 1, input_sequence); figure(3) subplot(1,2,1) % Illustrate the input signal stem(sample_points, input_sequence); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid on subplot(1,2,2) % Illustrate the first output signal stem(sample_points, output_y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] - Filter Function Method' ); grid on Output: b) Now, I will be using the frequency response method and the resulting graph is expected to display the input signal x[n] as a diminishing exponential function, while the output signal y[n] should appear as a decaying sinusoidal wave. Matlab Code: % Define the input signal for DTFT computation Discrete_Fourier_transform_input = fft(input_sequence); % Calculate the system's frequency response frequency_vector = linspace(0, pi, length(Discrete_Fourier_transform_input));
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
frequency_response = freqz(impulse_response, 1, frequency_vector); % Apply the frequency response to the DTFT of the input signal output_frequency_domain = Discrete_Fourier_transform_input .* frequency_response; % Compute the inverse DTFT to get the second output signal output_y2 = real(ifft(output_frequency_domain)); figure(4) subplot(1,2,1) % Display the input alongside the output stem(sample_points, input_sequence); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid on subplot(1,2,2) % Display the second output signal stem(sample_points, output_y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] - Frequency Response Method' ); grid on Output: 4. Plot the outputs obtained from both methods and the error between them all in one window. What does the error signal show?
Matlab Code: figure(5) subplot(3,1,1) % Exhibit the first output signal stem(sample_points, output_y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] via Filter Function' ); grid on subplot(3,1,2) % Exhibit the second output signal stem(sample_points, output_y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] via Frequency Response' ); grid on % Calculate and exhibit the error between the two outputs output_error = output_y1 - output_y2; subplot(3,1,3) stem(sample_points, output_error); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Error Signal (Difference Between Two Outputs)' ); grid on Output:
The resulting graph will display three separate subplots corresponding to each signal: the output derived using the filter function, the output calculated via the frequency response approach, and the error signal, which represents the variance between these two methods. The error signal illustrates the level of agreement between the two approaches. Ideally, this error signal would be zero, signifying that both methods yield identical results. However, due to practical issues like numerical precision limitations, the effects of using finite-length sequences, or other factors, there might be minor discrepancies. The error signal's magnitude reveals the extent of these discrepancies, and its phase shows the phase shift differences between the outputs. By examining the error signal, we can understand the constraints of each method and identify strategies to enhance their precision.
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
APPENDIX Question 1: Matlab % Initialize the signal x[n] index_n = 0:50; % Setting the range for n x_signal = (0.5).^index_n .* heaviside(index_n); % Calculating the values for the signal % Calculate the Discrete Time Fourier Transform (DTFT) of x[n] omega = linspace(0, pi, 1000); % Defining the omega range X_dtft = freqz(x_signal, 1, omega); % DTFT calculation magnitudeX = abs(X_dtft); % Magnitude of the DTFT phaseX = unwrap(angle(X_dtft)); % Phase of the DTFT % Since there are no denominator coefficients in x[n], we use 1. figure(1) % Display the magnitude and phase of the DTFT subplot(2,1,1); plot(omega, magnitudeX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'DTFT Magnitude of x[n]' ); grid on % minor grid is not available in all MATLAB versions, using 'on' for broader compatibility subplot(2,1,2); plot(omega, phaseX); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'DTFT Phase of x[n]' ); grid on % Using 'grid on' for compatibility Question 2: Matlab % Initialize the impulse response h[n] index = 0:50; h = heaviside(-index) + (1 - heaviside(-index)) .* (10.^(-index - 5) .* (-972222 .* (-5).^index + 755555 .* ((-1).^index))); % Calculate and display the frequency response frequency = linspace(0, pi, 1000); H_freq = freqz(h, 1, frequency); magnitudeH = abs(H_freq); phaseH = unwrap(angle(H_freq)); figure(2) subplot(2,1,1); plot(frequency, magnitudeH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Magnitude' ); title( 'Frequency Response Magnitude' ); grid on ; % Changed to 'grid on' for compatibility subplot(2,1,2); plot(frequency, phaseH); xlabel( 'Frequency (rad/sample)' ); ylabel( 'Phase (rad)' ); title( 'Frequency Response Phase' ); grid on ; % Changed to 'grid on' for compatibility
Question 3: Matlab a) % Specify the input signal x[n] sample_points = 0:99; input_sequence = (0.5).^sample_points .* heaviside(sample_points); % Establish the impulse response of the system h[n] impulse_response = heaviside(-sample_points) + (1 - heaviside(-sample_points)) .* (10.^(-sample_points - 5) .* (-972222 * (-5).^sample_points + 755555 .* ((-1).^sample_points))); % Determine the system's output using the filter function output_y1 = filter(impulse_response, 1, input_sequence); figure(3) subplot(1,2,1) % Illustrate the input signal stem(sample_points, input_sequence); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid on subplot(1,2,2) % Illustrate the first output signal stem(sample_points, output_y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] - Filter Function Method' ); grid on b) % Define the input signal for DTFT computation Discrete_Fourier_transform_input = fft(input_sequence); % Calculate the system's frequency response frequency_vector = linspace(0, pi, length(Discrete_Fourier_transform_input)); frequency_response = freqz(impulse_response, 1, frequency_vector); % Apply the frequency response to the DTFT of the input signal output_frequency_domain = Discrete_Fourier_transform_input .* frequency_response; % Compute the inverse DTFT to get the second output signal output_y2 = real(ifft(output_frequency_domain)); figure(4) subplot(1,2,1) % Display the input alongside the output stem(sample_points, input_sequence); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Input Signal x[n]' ); grid on subplot(1,2,2) % Display the second output signal stem(sample_points, output_y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] - Frequency Response Method' ); grid on
Question 4: Matlab figure(5) subplot(3,1,1) % Exhibit the first output signal stem(sample_points, output_y1); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] via Filter Function' ); grid on subplot(3,1,2) % Exhibit the second output signal stem(sample_points, output_y2); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Output Signal y[n] via Frequency Response' ); grid on % Calculate and exhibit the error between the two outputs output_error = output_y1 - output_y2; subplot(3,1,3) stem(sample_points, output_error); xlabel( 'Time (samples)' ); ylabel( 'Amplitude' ); title( 'Error Signal (Difference Between Two Outputs)' ); grid on
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