plot the spectrum of a rectified half-wave 50hz sine in matlab

main.m
% Generate a half-wave rectified sine wave with frequency 50 Hz
f = 50; % Frequency in Hz
t = 0:0.0001:1; % Time vector from 0 to 1 second with a step of 0.0001
x = abs(sin(2*pi*f*t)); % Generating half-wave rectified sine wave

% Take the FFT of the signal
X = fft(x);

% Calculate the frequency axis
Fs = 1/(t(2)-t(1)); % Sampling frequency
f_axis = (-Fs/2:Fs/length(t):Fs/2-Fs/length(t)); % Frequency axis for the FFT

% Plot the spectrum
figure;
plot(f_axis, abs(fftshift(X))/length(X));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Spectrum of Rectified Half-wave 50Hz Sine Wave');
596 chars
19 lines

gistlibby LogSnag