create half-rectified sine plots both in time and in frequency with fourier coefficients in matlab
main.m
% Generate a half-rectified sine wavefs = 1000; % Sampling frequency in Hzt = 0:1/fs:1; % Time vectorf = 10; % Frequency of the sine wave in Hzx = sin(2*pi*f*t); % Generate a sine wavex(x<0) = 0; % Half-rectify the sine wave% Time domain plotfigure;
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Half-rectified Sine Wave in Time Domain');
% Fourier TransformN = length(x); % Length of the signalX = fft(x,N)/N; % Compute the Fourier TransformX_mag = abs(X); % Magnitude spectrumfrequencies = linspace(0, fs, N); % Frequency axis% Frequency domain plotfigure;
stem(frequencies, X_mag);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Half-rectified Sine Wave in Frequency Domain');
% Display Fourier Coefficientsdisp('Fourier Coefficients:');
disp(X);