plot the frequencies and the amplitudes of a rectified 50hz half-wave sine in matlab

main.m
% Define parameters
f = 50; % Frequency of the sine wave
t = 0:0.0001:1; % Time vector with sampling interval of 0.0001 seconds

% Generate half-wave rectified sine wave
y = abs(sin(2*pi*f*t));

% Create FFT
N = length(y);
Y = fft(y)/N;
frequencies = linspace(0, 1, N);

% Plot the frequencies
figure;
plot(frequencies(1:N/2), abs(Y(1:N/2)));
title('FFT of Half-Wave Rectified 50Hz Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Amplitude');

% Plot the waveform
figure;
plot(t, y);
title('Half-Wave Rectified 50Hz Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
569 chars
26 lines

This code generates a half-wave rectified 50Hz sine wave, performs FFT to extract the frequencies and amplitudes, and plots both the frequencies and the waveform in MATLAB.

gistlibby LogSnag