plot magnitude vs frequency of a rectified sine without fft in matlab

You can achieve this by generating a rectified sine wave and then plotting its magnitude vs. frequency without using FFT in MATLAB. Here is an example code to do this:

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

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

% Compute the frequency vector
N = length(x);
frequencies = 0:fs/N:fs*(N-1)/N;

% Plot the magnitude vs frequency
plot(frequencies, x);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude vs. Frequency of Rectified Sine Wave');
417 chars
18 lines

This code will generate a rectified sine wave with a frequency of 5 Hz, compute the frequency vector, and then plot the magnitude vs frequency.

related categories

gistlibby LogSnag