Convert Accelerometer data to displacement values
Convert Accelerometer data to displacement values
(OP)
Hello,
I'm sure this topic has been covered before, but I'm still struggling with it.
The Story:
I have signal data from an accelerometer mounted to a car - one lap around a track. After filtering this data (high pass 13Hz) to remove ridgid body motion, I used it to drive a shaker rig with a component attached. An accelerometer on the conpoent was used to measure the response acceleration.
In order to convert to displacement (which I gather isn't an ideal process) I FFT the response, divide by the samping frequency squared then inverse FFT...?
My displacements are tiny, not really sure why. This is my m-file:
Fs = 512; % Sampling frequency
T = 1/Fs; % Sample time
L = 53760; % Length of signal(no. of data lines)
t = (0:L-1)*T; % Time vector
a = load('TrackReplay Z-axis.txt');
x = a(:,2);
y = a(:,3);
z = a(:,4);
x = x-mean(x*9.81);
x = detrend(x, 'linear');
y = y-mean(y*9.81);
y = detrend(y, 'linear');
z = z-mean(z*9.81);
z = detrend(z, 'linear');
X = fft(x,L)/L; % FFT of x
Y = fft(y,L)/L;
Z = fft(z,L)/L;
Xd = X/(2*pi*Fs)^2;
Yd = Y/(2*pi*Fs)^2;
Zd = Z/(2*pi*Fs)^2;
dx = ifft(Xd);
dy = ifft(Yd);
dz = ifft(Zd);
figure(1)
plot(t,dy)
Any help greatly appreciated
Tom
I'm sure this topic has been covered before, but I'm still struggling with it.
The Story:
I have signal data from an accelerometer mounted to a car - one lap around a track. After filtering this data (high pass 13Hz) to remove ridgid body motion, I used it to drive a shaker rig with a component attached. An accelerometer on the conpoent was used to measure the response acceleration.
In order to convert to displacement (which I gather isn't an ideal process) I FFT the response, divide by the samping frequency squared then inverse FFT...?
My displacements are tiny, not really sure why. This is my m-file:
Fs = 512; % Sampling frequency
T = 1/Fs; % Sample time
L = 53760; % Length of signal(no. of data lines)
t = (0:L-1)*T; % Time vector
a = load('TrackReplay Z-axis.txt');
x = a(:,2);
y = a(:,3);
z = a(:,4);
x = x-mean(x*9.81);
x = detrend(x, 'linear');
y = y-mean(y*9.81);
y = detrend(y, 'linear');
z = z-mean(z*9.81);
z = detrend(z, 'linear');
X = fft(x,L)/L; % FFT of x
Y = fft(y,L)/L;
Z = fft(z,L)/L;
Xd = X/(2*pi*Fs)^2;
Yd = Y/(2*pi*Fs)^2;
Zd = Z/(2*pi*Fs)^2;
dx = ifft(Xd);
dy = ifft(Yd);
dz = ifft(Zd);
figure(1)
plot(t,dy)
Any help greatly appreciated
Tom





RE: Convert Accelerometer data to displacement values
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Convert Accelerometer data to displacement values
That is initially what I did, but there was a great deal of drift etc. Saw someone on the internet suggesting this approach. I think the logic is:
convert to frequency domain, then:
(1) x=Asin(wt)
(2) v=wAcos(wt)
(3) a=-w^2Asin(wt)
Substitute (1) in (3): a /-w^2 = x
I had misunderstood last night what I used my sampling frequency for w. I think I should have divided by a frequency vector from 0-512 Hz. This gives a sensible plot but the values are all too small.
Have a completely misunderstood this subject?
RE: Convert Accelerometer data to displacement values
Bear in mind that your results from double integrating an acceleration spectrum in the frequency domain should match the spectrum of the signal resulting from double integrating the original signal in the time domain, which is easy peasy to program.
Cheers
Greg Locock
New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?
RE: Convert Accelerometer data to displacement values
Fe
RE: Convert Accelerometer data to displacement values
Well, I thought it seemed too good to be true.
RE: Convert Accelerometer data to displacement values
RE: Convert Accelerometer data to displacement values
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Convert Accelerometer data to displacement values
By small I mean microns. Its quite a flappy component too, you can see it moving +- 15mm on the shaker rig. First mode is 77 Hz so I should easily have kept the peak displacements.
David, good suggestion but I think my units are consistant.
I was hoping someone might have done this before and tell me straight away that i'm either totally wrong, or point out what I'm doing wrong..
RE: Convert Accelerometer data to displacement values
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Convert Accelerometer data to displacement values
RE: Convert Accelerometer data to displacement values
Just make sure that the accel. is calibrated properly, otherwise you will get wacky numbers
Fe
RE: Convert Accelerometer data to displacement values
tjakeman - 3 things to consider
Run a perfect sinusoid through it and see if it gives you the expected result from hand calcs.
When you perform the ifft the resulting numbers should be real (exept for a small round-off error of 1e-15 or so), If there is any imaginary component then you have done something wrong
Check the scaling of the amplitudes following FFT. You are dividing by L. I *think* you should be dividing by L/2 (although it is always best to check you scaling by running a sinusoid through the code).
Here is a link that may be useful
http://www
M
--
Dr Michael F Platten
RE: Convert Accelerometer data to displacement values
Thanks for your input. Even with a pure sine wave I don't get the expected results. The imaginary part after ifft is of the same magnitude as the real part. I followed the FFT example you linked me to and did the following:
Fs = 512; % Sampling frequency
T = 1/Fs; % Sample time
L = 4096; % Length of signal(no. of data lines)
t = (0:L-1)*T; % Time vector
% x =Asin(wt)
% v =wAcos(wt)
f = 10;
w = 2*pi*f;
A = 20;
y2=-w^2*A*sin(w*t);
y = detrend(y2, 'constant');
nfft = 2^(nextpow2(length(y))); % Use next highest power of 2 greater than or equal to length(x) to calculate FFT.
ffty = fft(y,nfft); % Take fft, padding with zeros so that length(fftx) is equal to nfft
NumUniquePts = ceil((nfft+1)/2); % Calculate the number of unique points
ffty = ffty(1:NumUniquePts); % FFT is symmetric, throw away second half
my = abs(ffty)/length(y); % Take the magnitude of fft of x and scale the fft so that it is not a function of the length of x
my = my.^2; % Take the square of the magnitude of fft of x.
% Since we dropped half the FFT, we multiply mx by 2 to keep the same energy.
% The DC component and Nyquist component, if it exists, are unique and should not be multiplied by 2.
if rem(nfft, 2) % odd nfft excludes Nyquist point
my(2:end) = my(2:end)*2;
else
my(2:end -1) = my(2:end -1)*2;
end
f = (0:NumUniquePts-1)*Fs/nfft; % This is an evenly spaced frequency vector with NumUniquePts points.
% Generate the plot, title and labels.
figure(1)
subplot(211)
plot(t,y)
subplot(212)
plot(f,my);
title('Power Spectrum of response in y');
w2 = w.^2;
Yd = my./-w2;
dy = ifft(Yd);
t2 = [0:8/(L/2):8];
figure(2)
plot(t2,dy)
I'm not sure if its appropriate to only take the absolute values after FFT in this case, but it doesn't seem to affect the results either way...
RE: Convert Accelerometer data to displacement values
Of course, but is x=Asin(wt) not a steady state response only?
imo, power spectrum vs. frequency is a different story.
So are we saying that: dy = ifft(Yd) is valid for any signal?
Fe
RE: Convert Accelerometer data to displacement values
Check you disp. values by high pass filtering and numerically integrating twice.....usually works nicely, ss or not ss.
Fe
RE: Convert Accelerometer data to displacement values
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Convert Accelerometer data to displacement values
Cheers
Greg Locock
New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?
RE: Convert Accelerometer data to displacement values
Cheers
Greg Locock
New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?