plot the spectrum of the first seven fourier coefficients of a rectified 60hz sine wave in matlab
main.m
% Generating the rectified 60Hz sine wavefs = 1000; % sampling frequencyt = 0:1/fs:1; % time vector from 0 to 1 secf = 60; % frequency of the sine wavex = abs(sin(2*pi*f*t)); % rectified sine wave% Computing the Fourier coefficientsN = 7; % number of coefficients to computeX = zeros(1, N); % Fourier coefficientsfor n = 1:N
X(n) = 2/1i/n/pi*(1-(-1)^n)*sinc(n*f*t(end));
end% Plotting the amplitude spectrumfrequencies = (0:N-1)*60;
stem(frequencies, abs(X), 'filled')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('Amplitude Spectrum of the First Seven Fourier Coefficients')