plot magnitude vs frequency of a rectified sine in matlab

main.m
% Define the parameters
fs = 1000; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
f = 5; % Frequency of the sine wave
A = 1; % Amplitude of the sine wave

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

% Compute the magnitude spectrum using FFT
X = abs(fft(x));

% Define the frequency axis for plotting
f_axis = (0:length(X)-1)*fs/length(X);

% Plot magnitude vs frequency
plot(f_axis, X);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude vs Frequency of a Rectified Sine Wave');
518 chars
21 lines

Make sure you provide the correct sampling rate (fs), frequency of the sine wave (f), and other parameters based on your requirements.

gistlibby LogSnag