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

3 Ansichten (letzte 30 Tage)
yafiet solomon am 28 Nov. 2022
Beantwortet: Pravarthana P am 1 Dez. 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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Pravarthana P am 1 Dez. 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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by