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

2 visualizzazioni (ultimi 30 giorni)
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');

Risposte (1)

Bladi Toaza
Bladi Toaza il 25 Gen 2021
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.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by