plot the fourier series of a rectified 60hz sine wave in matlab

To plot the Fourier series of a rectified 60Hz sine wave in MATLAB, you can follow these steps:

  1. Define the parameters:
main.m
f = 60; % Frequency of the sine wave (in Hz)
T = 1/f; % Time period of the sine wave
t = 0:0.0001:5*T; % Time vector
rect_sine_wave = abs(sin(2*pi*f*t)); % Rectified 60Hz sine wave
181 chars
5 lines
  1. Compute the Fourier coefficients:
main.m
N = 50; % Number of harmonics
A = zeros(1, N); % Fourier series coefficients
for n = 1:N
    A(n) = 2 * trapz(t, rect_sine_wave .* sin(2*pi*n*f*t)); % Compute the Fourier coefficient using integration
end
205 chars
6 lines
  1. Plot the Fourier series:
main.m
y = zeros(size(t));
for n = 1:N
    y = y + A(n) * sin(2*pi*n*f*t); % Construct the Fourier series
end

figure;
subplot(2,1,1);
plot(t, rect_sine_wave, 'b'); % Plot the rectified sine wave
xlabel('Time (s)');
ylabel('Amplitude');
title('Rectified 60Hz Sine Wave');

subplot(2,1,2);
plot(t, y, 'r'); % Plot the Fourier series approximation
xlabel('Time (s)');
ylabel('Amplitude');
title('Fourier Series of Rectified 60Hz Sine Wave');
433 chars
18 lines

Run the above MATLAB code to plot the Fourier series of the rectified 60Hz sine wave.

gistlibby LogSnag