plot the spectrum of a rectified 50hz sine in matlab

main.m
% Define the parameters
f = 50; % frequency of 50 Hz
fs = 1000; % Sampling frequency of 1000 Hz
t = 0:1/fs:1-1/fs; % Time vector

% Create rectified sine wave
x = abs(sin(2*pi*f*t));

% Plot the rectified sine wave in time domain
subplot(2,1,1);
plot(t,x);
title('Rectified 50 Hz Sine Wave in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');

% Plot the spectrum of the rectified sine wave
Y = fft(x);
frequencies = linspace(0, fs, length(Y));
amplitude = abs(Y)/length(Y);

subplot(2,1,2);
stem(frequencies, amplitude);
title('Spectrum of Rectified 50 Hz Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
623 chars
26 lines

This code first generates a rectified sine wave signal with a frequency of 50 Hz. Then it plots the rectified sine wave in the time domain and computes and plots its spectrum using the Fast Fourier Transform (FFT).

related categories

gistlibby LogSnag