How to convert accelerometer data to find displacement graph

I have a triple axis accelerometer sensors. we are doing vibrational analysis for a Civil engg structure, we are able to successfully get raw data from the accelerometer (XYZ in g's). We transfered this raw data into matlab and did acceleration and Fast fourier transform plot to get frequency. We are stuck on writing the code to change the acceleration data into displacement. If anyone has any tips on where we should go with this, it would be greatly appreciated. Thanks in advance.I have attached the Accleration plot. I have tried using CumTrapz command but it dosent give proper results.

 Accepted Answer

hello
see my suggestion below
clc
clearvars
data = csvread('data.csv',1); % time & Acceleration data
t = data(:,1);
acc = data(:,2);
acc = detrend(acc,'linear');
N = length(t);
dt = mean(diff(t)); % Average dt
fs = 1/dt; % Frequency [Hz] or sampling rate
% some additionnal high pass filtering
N = 4;
fc = 0.05; % Hz
[B,A] = butter(N,2*fc/fs,'high');
acc2 = filter(B,A,acc);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
velocity = cumtrapz(dt,acc2);
velocity = detrend(velocity,'linear');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp = cumtrapz(dt,velocity);
%
figure(1)
subplot(311),plot(t,acc);
subplot(312),plot(t,velocity);
subplot(313),plot(t,disp);

10 Comments

hello again
my code assumes that acceleration unit is m/s²
if the data are in g's simply multiply by 9.81 (what I assume you already know)
all the best
Hello @Mathieu NOE Can you please tell me how did you take ' N ' and ' fc ' (Cutoff frequency)
hello
it' s a bit by trial and error
I start with a low N (2 to 4 max) , because high order butterworth filters are unstable
then I take fc = Fs /100 at a starting point - or maybe I do a fft analysis first to see the spectral content of the acceleration data and I choose fc below the lower limit of the spectral energy plot 60 dB below the peak amplitude
then I try to lower fc but there is usually a trade off ; if fc is very low, first issue is that the transient response of the filter is so long that the data record may be too short to simulate the filter in steady state. Second issue can be the low frequency noise background of the accel data will be more amplified as you go down with fc.
so a high quality , very low noise sensor is key for this application
Hi
if my contribution has helped you, do you mind accepting it ?
tx
surely it helped me ! Appreciate your help.
@Mathieu NOE one last request, can you send some online reference link for understanding fc value (cutoff- frequency).
(any pdf or youtube video)
hello
what is not clear regarding fc (the concept or how to tune it ? )
If you want some general lecture about signal processing and digital filters , see "Scientists and Engineers Guide to DSP" at The Scientist and Engineer's Guide to Digital Signal Processing (dspguide.com)
hi, could you explain me why do you use "detrend" for acceleration and butter, with factors fc and N ?
I used Newmark method without cut off frequence and i have high displacements.
do you have a "special case" that need my support ?
if you have data / code to share , I can throw an eye on it

Sign in to comment.

More Answers (1)

The new convertVibration function in MATLAB R2024a release of the Predictive Maintenance Toolbox lets you compute baseline-corrected and filtered acceleration, velocity, and displacement signals from vibration measurements using a single sensor output from either an accelerometer, velocity sensor, or displacement sensor.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!