plot the spectrum of a rectified half-wave 50hz sine in matlab
main.m
% Generate a half-wave rectified sine wave with frequency 50 Hzf = 50; % Frequency in Hzt = 0:0.0001:1; % Time vector from 0 to 1 second with a step of 0.0001x = abs(sin(2*pi*f*t)); % Generating half-wave rectified sine wave% Take the FFT of the signalX = fft(x);
% Calculate the frequency axisFs = 1/(t(2)-t(1)); % Sampling frequencyf_axis = (-Fs/2:Fs/length(t):Fs/2-Fs/length(t)); % Frequency axis for the FFT% Plot the spectrumfigure;
plot(f_axis, abs(fftshift(X))/length(X));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Spectrum of Rectified Half-wave 50Hz Sine Wave');