I'm trying to convert accelerometer data from accelerations to displacement,
I assume that the initial velocity is zero and the initial position is also zero.
Here's my code,
Fs = 500;
T = 1/Fs;
t = (0:length(y) -1)*T;
vel = cumtrapz(t, acc);
disp = cumtrapz(t, vel);
here are the respective plots from acceleration to displacement,
what am I doing wrong?
I've implemented a kalman filter but the result is the same. I'm trying to work around with wavelet decomposition, any help would be very appreciated to resolve this problem.
Answer
I resolved the issue, applying a butterworth band-pass in both acceleration and velocity,
close all
clear all
clc
addpath(genpath('/home/samuel/Dropbox/WORK/ISRProject/Mass_project/'));
load acc;
Fs = 500;
T = 1/Fs;
x = linspace(1,2000,2000);
t = (0:length(a) -1)*T;
a = a.*9.8;
al = bandpass_butterworth(a, [0.5 25], Fs,2);
vel = cumtrapz(t,al);
vel = bandpass_butterworth(vel, [0.5 25], Fs,2);
pos = cumtrapz(t,vel);
subplot(311), plot(t,al);
ylabel('Acceleration [m/s^2]');
subplot(312), plot(t,vel);
ylabel('Velocity [m/s]');
subplot(313), plot(t,pos);
ylabel('Position [m]');
xlabel('Time [s]');
As you can see, the initial position almost corresponds to the final one. This example is not the same as the original signal as I don't have the other one anymore.
No comments:
Post a Comment