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

main.m
% Generating the rectified 60Hz sine wave
fs = 1000; % sampling frequency
t = 0:1/fs:1; % time vector from 0 to 1 sec

f = 60; % frequency of the sine wave
x = abs(sin(2*pi*f*t)); % rectified sine wave

% Computing the Fourier coefficients
N = 7; % number of coefficients to compute
X = zeros(1, N); % Fourier coefficients

for n = 1:N
    X(n) = 2/1i/n/pi*(1-(-1)^n)*sinc(n*f*t(end));
end

% Plotting the amplitude spectrum
frequencies = (0:N-1)*60;
stem(frequencies, abs(X), 'filled')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Amplitude Spectrum of the First Seven Fourier Coefficients')
600 chars
22 lines

gistlibby LogSnag