plot a rectified half sine wave in time and plot its spectrum of the first seven fourier coefficients in matlab
main.m
% Generating a rectified half sine wavet = linspace(0, 2*pi, 1000); % time vectory = abs(sin(t)); % rectified half sine wave% Plotting the rectified half sine wave in time domainfigure;
subplot(2,1,1);
plot(t, y);
title('Rectified Half Sine Wave in Time Domain');
xlabel('Time');
ylabel('Amplitude');
% Performing Fourier Transform to get the spectrumN = 7; % Number of Fourier coefficientsdt = t(2) - t(1); % Time stepFs = 1/dt; % Sampling frequencyY = fft(y) / length(y); % Fourier Transformfrequencies = Fs*(0:(length(y)/2))/length(y);
% Plotting the spectrum of the first seven Fourier coefficientssubplot(2,1,2);
stem(frequencies(1:N), abs(Y(1:N)));
title('Spectrum of first seven Fourier coefficients');
xlabel('Frequency');
ylabel('Magnitude');