plot an half-wave rectified 50hz sine in time and plot its first seven fourier coefficients in frequency in matlab
main.m
% Define the parametersf = 50; % Frequency of the sine wave in Hzfs = 5000; % Sampling frequency in Hzt = 0:1/fs:0.1; % Time vector for one cycle% Generate the half-wave rectified sine wavex = abs(sin(2*pi*f*t));
x_rect_freq = fft(x); % Calculate the Fourier coefficientsn_harmonics = 7; % Number of harmonics to consider% Plot the half-wave rectified sine wave in timefigure;
subplot(2,1,1);
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Half-Wave Rectified 50Hz Sine Wave');
% Plot the Fourier coefficientsfrequencies = 0:fs/length(x):fs*(length(x)-1)/length(x);
subplot(2,1,2);
stem(frequencies(1:ceil(length(x)/2)), abs(x_rect_freq(1:ceil(length(x)/2))));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Fourier Coefficients of Half-Wave Rectified 50Hz Sine Wave');
802 chars
26 lines
Now, by running the above code in Matlab, you will create a plot of the half-wave rectified 50Hz sine wave in the time domain and its first seven Fourier coefficients in the frequency domain.