plot first seven fourier coefficients of an half wave rectified 50hz sine in matlab
main.m
f = 50; % Frequency of the sine wave in HzT = 1/f; % Period of the sine wave in secondst = 0:1e-4:2*T; % Time vector from 0 to 2 periods of the sine wave% Generate the half wave rectified 50 Hz sine wavex = abs(sin(2*pi*f*t));
x(t > T) = 0; % Apply the rectification% Find the Fourier coefficientsn = 1:7; % Specify the first seven coefficientsA = zeros(size(n)); % Initialize vector to store coefficientsfori = 1:length(n)
A(i) = 2*trapz(t, x.*sin(2*pi*n(i)*f*t))/T;
end% Plot the coefficientsstem(n, A);
xlabel('n (Harmonic number)');
ylabel('Coefficient value');
title('Fourier Coefficients of Half Wave Rectified 50 Hz Sine Wave');