plot an half-wave rectified 50hz sine in time and plot first seven harmonics in frequency in matlab
main.m
% Generate a half-wave rectified sine wavef = 50; % Frequency of the sine wavet = 0:0.0001:1; % Time vector from 0 to 1 secondx = sin(2*pi*f*t); % Generate the sine wavex(x<0) = 0; % Half-wave rectification% Plot the half-wave rectified sine wave in time domainfigure;
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Half-wave rectified 50Hz sine wave in time domain');
% Plot the first seven harmonics in frequency domainN = 7; % Number of harmonicsFs = 1000; % Sampling frequencyY = fft(x, Fs); % Compute Fast Fourier Transformfrequencies = linspace(0, Fs, length(Y));
figure;
stem(frequencies(1:Fs/2), abs(Y(1:Fs/2)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('First seven harmonics of the half-wave rectified sine wave');