plot the frequencies and the amplitudes of a rectified 50hz half-wave sine in matlab
main.m
% Define parametersf = 50; % Frequency of the sine wavet = 0:0.0001:1; % Time vector with sampling interval of 0.0001 seconds% Generate half-wave rectified sine wavey = abs(sin(2*pi*f*t));
% Create FFTN = length(y);
Y = fft(y)/N;
frequencies = linspace(0, 1, N);
% Plot the frequenciesfigure;
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 waveformfigure;
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.