Convert data from time domain to the frequency domain using F.T
2 ビュー (過去 30 日間)
古いコメントを表示
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
2021 年 1 月 18 日
Hi Kelvin,
The variable 'Fv' has not been defined in your code. Could you check that ?
回答 (1 件)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!