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

main.m
% Create a rectified 60Hz sine wave
fs = 1000; % Sampling frequency
t = 0:1/fs:1; % Time vector
f = 60; % Frequency of the sine wave
x = sin(2*pi*f*t); % 60Hz sine wave
x(x<0) = 0; % Rectify the sine wave

% Compute the Fourier Transform
X = 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 Spectrum
plot(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.

gistlibby LogSnag