Acceleration vs Time; Magnitude vs Frequency

5 vues (au cours des 30 derniers jours)
Farrukh Karimov
Farrukh Karimov le 13 Juil 2017
Commenté : Star Strider le 13 Juil 2017
Hello, I need to plot two graphs (Acceleration vs Time and Magnitude vs Frequency) and present both of it. Here is the code that I have done (a-acceleration (Length of signal N=2048), vt=time vector (1.2048s), Fs=32768Hz)
signal = a; time=vt;
% Plot Original signal in Time Domain
plot(vt,a);
title('Original signal in Time Domain');
xlabel('Time [s]');
ylabel('Acceleration [m/s^2]');
% Plot FFT signal
N = pow2(nextpow2(length(signal)));
y = fft(signal,N);
plot(1:N,abs(y));
title('FFT');
xlabel('Frequency [Hertz]');
ylabel('Magnitude');
Could you help me with that? Thank you in advance!

Réponse acceptée

Star Strider
Star Strider le 13 Juil 2017
Modifié(e) : Star Strider le 13 Juil 2017
Try this:
% Plot FFT signal
N = pow2(nextpow2(length(signal)));
y = fft(signal,N)/length(signal);
Fn = Fs/2;
Fv = linspace(0, 1, fix(length(y)/2)+1)*Fn;
Iv = 1:length(Fv);
plot(Fv,abs(y(Iv))*2);
title('FFT');
xlabel('Frequency [Hertz]');
ylabel('Magnitude');
NOTE I have not tested this. It should work.
  3 commentaires
Farrukh Karimov
Farrukh Karimov le 13 Juil 2017
As I understood, should it be like this (without "-2") ?:
Iv = 1:length(Fv);
plot(Fv,abs(y(Iv)))
Star Strider
Star Strider le 13 Juil 2017
Typographical error I didn’t catch.
Should be:
plot(Fv,abs(y(Iv))*2);
I also corrected it in my original Answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by