Single sided spectrum of vector y obtained using fft

8 vues (au cours des 30 derniers jours)
Diya Samanta
Diya Samanta le 1 Sep 2020
how to plot a single sided spectrum of vector y obtained using fft?

Réponse acceptée

Star Strider
Star Strider le 1 Sep 2020
The way I usually calculate and plot it:
t = linspace(0, 1, 1E+4);
s = sum(sin([0; 100; 200; 300]*2*pi*t*10)) .* randn*10;
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L1 = numel(t);
FTs1 = fft(s)/L1; % FFT Of Original Signal
Fv1 = linspace(0, 1, fix(L1/2)+1)*Fn; % Frequency Vector
Iv1 = 1:numel(Fv1); % Index Vector
L2 = 2^nextpow2(L1);
FTs2 = fft(s,L2)/L1; % FFT Of Zero-Padded Signal
Fv2 = linspace(0, 1, fix(L2/2)+1)*Fn; % Frequency Vector
Iv2 = 1:numel(Fv2); % Index Vector
figure
subplot(2,1,1)
plot(Fv1, abs(FTs1(Iv1))*2)
title('FFT of Original Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
grid
subplot(2,1,2)
plot(Fv2, abs(FTs2(Iv2))*2)
title('FFT of Zero-Padded Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
grid
This also demonstrates a way to increase the frequency resolution of the fft result by zero-padding it.
.
  1 commentaire
Star Strider
Star Strider le 1 Sep 2020
Modifié(e) : Star Strider le 1 Sep 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Deepak Gupta
Deepak Gupta le 1 Sep 2020
Modifié(e) : Deepak Gupta le 1 Sep 2020
You can refer FFT Documentation. There are multiple examples to obtain this.

Community Treasure Hunt

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

Start Hunting!

Translated by