plot the first seven fourier coefficients of a 50hz rectified sine wave in matlab

main.m
% Define the parameters
f = 50; % Frequency of the sine wave
t = 0:0.0001:0.1; % Time vector
x = abs(sin(2*pi*f*t)); % Rectified sine wave

% Compute the Fourier series coefficients
N = 7; % Number of coefficients
coefficients = zeros(1, N);
for n = 1:N
    coefficients(n) = integral(@(t) abs(sin(2*pi*f*t)).*cos(2*pi*n*f*t), 0, 1/f) / (1/f); % Fourier coefficient formula
end

% Plot the first seven Fourier coefficients
stem(1:N, coefficients);
xlabel('Coefficient Index');
ylabel('Coefficient Value');
title('First Seven Fourier Coefficients of 50Hz Rectified Sine Wave');
577 chars
18 lines

gistlibby LogSnag