plot first seven fourier coefficients of an half wave rectified 50hz sine in matlab

main.m
f = 50;  % Frequency of the sine wave in Hz
T = 1/f; % Period of the sine wave in seconds
t = 0:1e-4:2*T;  % Time vector from 0 to 2 periods of the sine wave

% Generate the half wave rectified 50 Hz sine wave
x = abs(sin(2*pi*f*t));
x(t > T) = 0;  % Apply the rectification

% Find the Fourier coefficients
n = 1:7;  % Specify the first seven coefficients
A = zeros(size(n));  % Initialize vector to store coefficients
for i = 1:length(n)
    A(i) = 2*trapz(t, x.*sin(2*pi*n(i)*f*t))/T;
end

% Plot the coefficients
stem(n, A);
xlabel('n (Harmonic number)');
ylabel('Coefficient value');
title('Fourier Coefficients of Half Wave Rectified 50 Hz Sine Wave');
659 chars
21 lines

related categories

gistlibby LogSnag