How can I get the FFT (Amplitude - Frequency) from Time (s) - Acceleartion(m/s^2) data?

3 ビュー (過去 30 日間)
Bob
Bob 2016 年 3 月 21 日
コメント済み: Star Strider 2016 年 3 月 21 日
clc;
clear all;
close all;
Time = xlsread('Data','A2:A513'); % Time (s)
Acceleration = xlsread('Data','B2:B513'); % Acceleration (m/s^2)
n = length(Acceleration);
Ts = Time(2)-Time(1); % Sample Time
Fs = 1/Ts; % Sampling Frequency
NFFT = 2^nextpow2(n); % Next power of 2 from length of data
Y = fft(Acceleration,NFFT)/n;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,Y)
xlabel('Frequency (Hz)')
ylabel('Amplitude (m)')
I am trying to get the FFT from Time Acceleration Data.
Error using plot
Vectors must be the same length.
P.S I have attached the Data.xlsx

採用された回答

Star Strider
Star Strider 2016 年 3 月 21 日
In your code, ‘f’ is half the length of ‘y’ so you need to create an ‘index vector’.
Try this:
... CODE ...
Y = fft(Acceleration,NFFT)/n;
f = Fs/2*linspace(0,1,NFFT/2+1);
Iv = 1:length(f); % Index Vector
plot(f,abs(Y(Iv)))
xlabel('Frequency (Hz)')
ylabel('Amplitude (m)')
That should work.
  4 件のコメント
Bob
Bob 2016 年 3 月 21 日
Ok, thanks for your answer.
Star Strider
Star Strider 2016 年 3 月 21 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by