plot the spectrum of fourier coefficients of a rectified 60hz sine wave in matlab
main.m
% Create a rectified 60Hz sine wavefs = 1000; % Sampling frequencyt = 0:1/fs:1; % Time vectorf = 60; % Frequency of the sine wavex = sin(2*pi*f*t); % 60Hz sine wavex(x<0) = 0; % Rectify the sine wave% Compute the Fourier TransformX = abs(fft(x));
L = length(x);
P2 = X/L;
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
frequencies = fs*(0:(L/2))/L;
% Plot the Spectrumplot(frequencies,P1);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Single-Sided Amplitude Spectrum of Rectified 60Hz Sine Wave');
517 chars
21 lines
This code will generate and plot the spectrum of Fourier coefficients of a rectified 60Hz sine wave in MATLAB.