Convert data from time domain to the frequency domain using F.T

2 ビュー (過去 30 日間)
kelvin
kelvin 2021 年 1 月 14 日
回答済み: Bladi Toaza 2021 年 1 月 25 日
Hello,
I'm trying to convert my data to the frequency domain. However when I ran my code it says the length dosent match when ploting.
Any help would be much appricated.
load('acceleration.mat');
load('time.mat');
time = time(:,1);
acc_z = accleration(:,3);
N = length(acc_z);
Samp_Interval = mean(diff(time)); % time each datapoint takes
%disp(Samp_Interval);
Fs = 1/Samp_Interval; % frequecy sample
disp(Fs);
Fn = Fs/2; % Nyquist frequency
%disp(Fn);
FT = fft(acc_z);
F =(0:1/N:1-1/N)*Fs;
%disp(Fv);
% graph
figure('Name', 'Sensor Data');
axis(1) = subplot(2,1,1);
hold on;
plot(time, accleration(:,3), 'b');
legend('Z');
xlabel('Time (s)');
ylabel('Acceleration (g)');
title('Accelerometer');
hold off;
axis(2) = subplot(2,1,1);
hold on;
plot(Fv,abs(F), 'r');
legend('acc-Z');
xlabel('Frequency (Hz)');
ylabel('Aamplitude)');
title('Frequency domain');
  1 件のコメント
Divija Aleti
Divija Aleti 2021 年 1 月 18 日
Hi Kelvin,
The variable 'Fv' has not been defined in your code. Could you check that ?

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

回答 (1 件)

Bladi Toaza
Bladi Toaza 2021 年 1 月 25 日
In plot(Fv,abs(F),'r') Fv has not been defined. I think you wanted to plot(FT,abs(F),'r').ç
Just remember the first argument of plot is the X data and the second the Y data. As well check if both vectors X and Y are the same length.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by