Hi I need to write a code to plot the magnitude spectra of the following signals using MATLAB fft() function and relate the spectral lines with the constituent frequencies.

9 vues (au cours des 30 derniers jours)
%this is the orginal functions that i need fft()
clc ; close all ;
t = 0: .02 : 4 * pi ;
x = zeros ( size ( t ) ) ;
for k = 1 : 2 : 19
x = x + sin ( k * t ) / k ; % Square wave
end
subplot (3,1,1)
plot (t, x )
title ( ' Square wave ' )
y = zeros ( size ( t ) ) ;
for k = 1 : 19
y = y- ( -1 ) ^ k * sin ( k * t ) / k ; % Sawtooth wave
end
subplot ( 3,1,2 )
plot ( t , y )
title ( ' Sawtooth wave ' )
z = zeros ( size ( t ) ) ;
for k = 1 : 2 : 19
z = z + cos ( k * t ) / ( k * k ) ; % Triangular wave
end
subplot ( 3,1,3 )
plot ( t , z )
title ( ' Triangular wave ' )

Réponses (1)

Pravarthana P
Pravarthana P le 1 Déc 2022
Hi Yafiet Solomon,
I understand that you are trying to plot the Magnitude spectra of the signals against their corresponding frequencies.
The "fft" function computes the discrete Fourier transform (DFT) of the input signal using a fast Fourier transform (FFT) algorithm. After computing the Fourier transform of the signal, compute the vector that depicts the signal’s sampling in frequency space. Finally, plot the computed signal’s FFT with their corresponding sampling frequency.
For more information refer to the documentation links below:
Hope this information helps you.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by