Accelerometer data filtering during standing balance measurement

I was using a body worn tri-axial accelerometer for measuring sway during standing balance. In the literature, I have read something about eliminating gravitational component followed by filtering the data in the accelerometer. As I am from medical background I don't have much knowledge on this. does anyone knows something about this and filtering a accelerometer data measured at 100hz sampling rate like what kind of filtering and cut-off frequency i should use for those data..

Answers (1)

The filter you design depends on the signals you have. In order to filter out the gravitational component (a constant), you probably need to design a bandpass filter with a stopband lower cutoff of 0.1 Hz, and an upper cutoff of about 40 Hz. If you have the Signal Processing Toolbox, you can see if this filter design does what you want:
Fs = 100; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
passband = [5.0 20]/Fn; % Passband (Hz)
stopband = [0.1 40]/Fn; % Stopband (Hz)
passripple = 1; % Passband Ripple (dB)
stopripple = 10; % Stopband Ripple (dB)
[n,Wn] = buttord(passband, stopband, passripple, stopripple);
[z,p,k] = butter(n,Wn);
[sos,g] = zp2sos(z,p,k);
figure(1)
freqz(sos,[0:0.1:50], Fs)
then use the filtfilt function to filter your data. See the documentation for the various functions for details on them. If you get too much noise, reduce the upper passband and stopband frequencies. You will probably have to experiment with it to get the result you want.

8 Comments

Hi Star strider,
Thank you for your answer but still i am not sure how to use the filtfilt function, could you shed some more light on this.. I can attach a file of my data, you can go through it.. the column 2, 3 and 4 belongs to the accelerometer data.
My pleasure.
Put the code in this comment in your script after the code in my Answer.
You need to define the filter passbands to pass and reject the frequencies you are comfortable with, but using the filter I designed in my Answer, this is how I filtered and plotted your data. The filtfilt function can filter all three signals in a single call to it, so you do not have to filter every signal individually. Note that the constants (including the gravitational acceleration) do not appear in the filtered signal because the filter is designed to exclude such constants, so no other processing other than the filter is necessary:
[d,s,r] = xlsread('Surendar PAT113069_0E_14_07.csv','B1:D107517');
Lv = size(d,1); % Length Of Data Vectors
Ts = 1/Fs; % Sampling Interval (s)
Tv = linspace(0,(Lv-1)*Ts,Lv); % Time Vector
df = filtfilt(sos,g,d); % Filter Signals
figure(2)
plot(Tv, d)
grid
xlabel('Time (s)')
ylabel('Acceleration (G)')
title('Unfiltered Signals')
figure(3)
subplot(3,1,1)
plot(Tv, df(:,1))
grid
ylabel('Acceleration (G)')
title('Channel #1 (X?)')
subplot(3,1,2)
plot(Tv, df(:,2))
grid
ylabel('Acceleration (G)')
title('Channel #2 (Y?)')
subplot(3,1,3)
plot(Tv, df(:,3))
grid
xlabel('Time (s)')
ylabel('Acceleration (G)')
title('Channel #3 (Z?)')
figure(4)
plot3(df(:,1), df(:,2), df(:,3))
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
Figures 1 through 3 are self-explanatory. Figure 4 plots all three together in a 3D plot. (I include figure(4) for illustration. It is not necessary to understand your data.)
Hi Star Strider,
I run the script as you have mentioned above but it shows an error in line 26 and when i opened 'r' it does not has any values except showing 'NaN'. there was nothing in Figure 2 and 3 and i did not get the Figure 4. Can you tell me what might be the problem here. Thank You.
Surendar
It ran perfectly with the file you gave me. I would not have posted it if it didn’t.
I renamed your file so I can keep track of downloaded files. You may want to change the xlsread line to:
[d,s,r] = xlsread('PAT113069_0E_14_07.csv','B1:D107517');
I’m using R2014b, so if you have a different release you may need to consult the documentation for xlsread for your version. (My code doesn’t use ‘s’ and ‘r’. I read them in so I can see where any problems might arise. You only need to read in ‘d’.)
I am also using the same version of MAtlab, I will work on it again and let you know again. If you are good at working with Accelerometers, you can see my data that the gravitational acceleration was measured in negative, so i guess the other two axes also measured differently. my question is, will it affect if i try to calculate the root mean square or sway path or velocity.. do you have any idea how to rectify this issue?
You can simply negate all the values in the filtered accelerometer data if that works for you. It would not affect the RMS, it would reverse the sway path in every dimension, and would reverse the sign of the velocity (after you integrate the acceleration with the cumtrapz function), so you may not want to negate them.
They are your data, so these decisions are yours. I would follow whatever the literature conventions are, since those are the standards you want to meet.
So, you mean to say, i can filter the data first and after that can do the Sway analysis. I am quite confused in this as this may affect my entire analysis as i mounted the sensor upside down..
If you mounted the sensor upside down your other axes would likely be flipped as well, so you would likely need to negate all your x,y,z data with d=-d for the rest of your analyses. You may have to re-run your experiment with the accelerometer oriented correctly to determine how best to correct your current data.
Otherwise, since the idea of the filter is to eliminate the constant offsets and high-frequency noise, the filter should not adversely affect your results. You may want to correct for the baseline effects, the baselines given by their respective means over a range of data:
BLI = 20000:100000; % Representative Baseline Data Indices
dm = mean(d(BLI,:)); % Means
xm = dm(1); % X-Mean
ym = dm(3); % Y-Mean
zm = dm(2); % Z-Mean
You can use those to adjust your data based on those collected with your accelerometer mounted correctly.
The orientation of your accelerometer will not affect the results of the filter output. You may want to add back the ‘xm’, ‘ym’, and ‘zm’ offsets to the filtered data depending on how you designed your experiment.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 2 Dec 2014

Commented:

on 3 Dec 2014

Community Treasure Hunt

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

Start Hunting!