plot spectrum of a rectified sine wave without fft in matlab

To plot the spectrum of a rectified sine wave without using FFT in MATLAB, you can use the Discrete Cosine Transform (DCT) which is a type of Fourier-related transform. Below is an example code snippet:

main.m
% Define parameters
Fs = 1000; % sampling frequency
t = 0:1/Fs:1; % time vector
f = 5; % frequency of the sine wave
A = 2; % amplitude of the sine wave

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

% Compute Discrete Cosine Transform
N = length(y); % length of signal
n = 0:N-1;
k = 0:N-1;
DCT_matrix = sqrt(2/N) * cos(pi/N * (n' + 0.5) * k);
spectrum = DCT_matrix * y';

% Plot spectrum
stem(k, spectrum);
xlabel('Frequency (k)');
ylabel('Magnitude');
title('Spectrum of Rectified Sine Wave without FFT using DCT');
530 chars
22 lines

In this code:

  1. We create a rectified sine wave signal by taking the absolute value of a sine wave.
  2. We construct the DCT matrix and calculate the spectrum by multiplying the DCT matrix with the signal.
  3. Finally, we plot the spectrum using stem function.

This code will allow you to plot the spectrum of a rectified sine wave without using FFT in MATLAB.

related categories

gistlibby LogSnag