gistlib
main.m% Define parameters f = 60; % Frequency in Hz Fs = 1000; % Sampling frequency in Hz T = 1/Fs; % Sampling period L = 1000; % Length of signal t = (0:L-1)*T; % Time vector % Generate the rectified 60Hz sine wave x = abs(sin(2*pi*f*t)); % Compute the Fourier Transform Y = fft(x); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; % Plot the spectrum in amplitude-phase form subplot(2,1,1); stem(f,P1); title('Single-Sided Amplitude Spectrum of Rectified Sine Wave'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(2,1,2); stem(f,angle(Y(1:L/2+1))); title('Single-Sided Phase Spectrum of Rectified Sine Wave'); xlabel('Frequency (Hz)'); ylabel('Phase'); 736 chars30 lines
% Define parameters f = 60; % Frequency in Hz Fs = 1000; % Sampling frequency in Hz T = 1/Fs; % Sampling period L = 1000; % Length of signal t = (0:L-1)*T; % Time vector % Generate the rectified 60Hz sine wave x = abs(sin(2*pi*f*t)); % Compute the Fourier Transform Y = fft(x); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; % Plot the spectrum in amplitude-phase form subplot(2,1,1); stem(f,P1); title('Single-Sided Amplitude Spectrum of Rectified Sine Wave'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(2,1,2); stem(f,angle(Y(1:L/2+1))); title('Single-Sided Phase Spectrum of Rectified Sine Wave'); xlabel('Frequency (Hz)'); ylabel('Phase');
gistlibby LogSnag