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.

6 次查看(过去 30 天)
%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 ' )

回答(1 个)

Pravarthana P
Pravarthana P 2022-12-1
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.

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by