Question: % Parameters T = 4 ; % Defines the Period of T w 0 = 2 * pi / T; % Calculates the fundamental angular

% Parameters T =4;% Defines the Period of T w0=2* pi / T;% Calculates the fundamental angular frequency t =-6:0.01:6;% Creates a time vector ranging from 6 to 6 with a step size of 0.01% Coefficients a0=3/4; % Sets the DC component, representing the average value of the signal over one period an = @(n)-1./(pi*n).* sin(pi*n/2);% Formula for an calculated in task 1 A bn = @(n)(1./(pi*n)).* cos(pi*n/2)-2*cos(pi*n)+1./(pi*n);% Formula for bn calculated in task 1 A % Ideal signal definition x_ideal =((t >=0) & (t 1))+2*((t >=1) & (t 2));% Defines an ideal signal with amplitude 1 from 0 to 1, and amplitude 2 from 1 to 2% Fourier series approximations for N =17 and N =51 x_fourier_17= a0* ones(size(t));% Start with DC component for N=17 x_fourier_51= a0* ones(size(t));% Start with DC component for N=51% Define piecewise function f_piecewise = @(t)((t >=0) & (t 1))+2*((t >=1) & (t 2));% Defines a piecewise function with values 1 for 0= t 1 and 2 for 1= t 2% Functions to compute Fourier coefficients compute_coefficients = @(n) deal(...(2/ T)*(integral(@(t) f_piecewise(t).* cos(n * w0* t),0,1)+... integral(@(t) f_piecewise(t).* cos(n * w0* t),1,2)),...(2/ T)*(integral(@(t) f_piecewise(t).* sin(n * w0* t),0,1)+... integral(@(t) f_piecewise(t).* sin(n * w0* t),1,2))...);% Inputs the Fourier coefficients for the piecewise function over the interval [0,2]% Calculate Fourier series for N =17 harmonics for n =1:17[an, bn]= compute_coefficients(n);% Inputs the Fourier coefficients for the nth harmonic x_fourier_17= x_fourier_17+ an * cos(n * w0* t)+ bn * sin(n * w0* t);% Adds the nth harmonic to the Fourier series approximation end % Calculate Fourier series for N =51 harmonics for n =1:51[an, bn]= compute_coefficients(n);% Inputs the Fourier coefficients for the nth harmonic x_fourier_51= x_fourier_51+ an * cos(n * w0* t)+ bn * sin(n * w0* t);% Adds the nth harmonic to the Fourier series approximation end % Plotting figure('Color', 'white');% Creates a figure with a white background % Plot the ideal signal plot(t, x_ideal, 'k', 'LineWidth', 2, 'DisplayName', 'Ideal x(t)');% Plots the original ideal signal x(t) hold on;% Holds the current plot for further additions % Plot Fourier series approximations plot(t, x_fourier_17,'r--', 'LineWidth', 1.5, 'DisplayName', 'Fourier Approx (N=17)');% Plots the Fourier series approximation with 17 harmonics plot(t, x_fourier_51,'b-.', 'LineWidth', 1.5, 'DisplayName', 'Fourier Approx (N=51)');% Plots the Fourier series approximation with 51 harmonics % Add labels, legend, title, and grid xlabel('Time (t)'); % Labels the x-axis as "Time (t)" ylabel('x(t)'); % Labels the y-axis as "x(t)" title('Ideal Signal and Fourier Series Approximations'); % Adds a title displaying the Ideal Signal and Fourier Series Approximations legend('Location', 'best'); % Automatically place the legend grid on; % Turns on the grid for better visualization axis([-66-0.52.5]); % Sets the axis limits for the plot: x from -6 to 6 and y from -0.5 to 2.5% Add vertical and horizontal reference lines plot([00],[-0.52.5],'k--', 'LineWidth', 0.5); % Vertical line at t=0 plot([-66],[00],'k--', 'LineWidth', 0.5); % Horizontal line at x=0 hold off;% Release the plot for further change
Edit the code to plot magnitude and phase spectrum for x(t). The code has to work 100% Task 2- Signal Processing
Consider the signal given in Figure 2.
% Parameters T = 4 ; % Defines the Period of T w

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!