# 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.

4 vues (au cours des 30 derniers jours)
yafiet solomon le 28 Nov 2022
%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 ' )
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

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.
Hope this information helps you.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Spectral Measurements dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by