|
Abstract
The methods of mathematical analysis are used to process data acquired from cell-phone accelerometers and gyroscopes to: (1) reconstruct the trajectory of the person carrying the cell-phone along a pre-determined path, and (2) determine data features that might identify the person.
1 Kinematics of rigid body motion ?
1.1Reference frames ?
1.2Matrix representation of rotations ?
1.3Matrix representation of infinitesimal rotations in relative coordinate system ?
1.4Change in the orientation of the relative coordinate system ?
1.5Change in position of the relative coordinate system ?
2Qualitative data analysis ?
2.1Data input ?
2.2Data plotting ?
2.2.1Linear accelerations ?
2.2.2Angular accelerations ?
3Trajectory reconstruction ?
3.1Integration ?
3.1.1Reconstructing angular velocities from gyroscope measurements ?
3.1.2Reconstructing the relative coordinate system basis ?
3.1.3Reconstructing the walker velocity and position ?
4Trajectory analysis ?
4.1Interpolation ?
4.2Least squares ?
4.3Min-max ?
Some basic theory on the kinematics of rigid body motion is necessary to process the acceleration data obtained from the Physics Toolbox Android application. It is assumed that the cell phone and walker form a rigid body, i.e., the cell phone is held rigidly at constant orientation. Note that this hypothesis is likely to be affected by natural flexural motions of the wrist and elbow.
Describing the kinematics (i.e., motion without consideration of forces) requires consideration of two reference frames:
A fixed coordinate system, i.e., with origin at the starting point of the walk and fixed axis orientations.
A moving coordinate system, carried by and centered on the sensor (i.e., cell-phone) motion, with variable axis orientations.
The notation for kinematic quantitites in the two reference systems is presented in Table 1, with a depiction represented in Figure 1. In particular, are the orientation, angular velocity of the relative system expressed as rotation angles, angular velocities around the axes of the absolute system . The orientation expressed as rotation angles in the relative coordinate system are denoted by , and are the corresponding angular velocities.
![]() |
Figure 1. Absolute reference system
, cell phone position ,
relative reference system
|
During motion, the orientation of the relative reference frame changes due to rotation of the walker. There exists some axis and angle of rotation around the axis that transforms the original orientation into the current orientation of the relative coordinate system ,
(1) |
The Euler representation of a rotation matrix is
(2) |
where is the completely anti-symmetric Levi-Civita tensor with components
(3) |
the sign of the permutation of into . The contraction of the rank-3 Levi-Civita tensor with a vector results in a rank-2 tensor (i.e., a matrix)
For an infinitesimal rotation , , , and the rotation matrix becomes
(4) |
where , and has inverse
(5) |
Consider now the rotation matrix that corresponds to the composition of three infinitesimal rotations around axes
(6) |
For infinitesimal rotations around the axes of the relative coordinate system , the composite rotation matrix is
(7) |
During the infinitesimal time step the relative coordinate axes undergo a rotation
which gives a differential system
(8) |
describing the change in the relative system orientation in terms of the rotation velocities around the axes of the relative system
(9) |
The current orientation of the relative coordinate system is the solution of the initial value problem (IVP)
The cell-phone measures accelerations along axes of the relative coordinate system, that are expressed in the global coordinate system as
The overall IVP to find the position is
(10) |
where the linear, angular accelerations are known from measurements.
A first step in processing the data acquired from the cell phone is to carry out some basic qualitative analysis, shown here using Octave (Matlab clone).
Cell-phone data saved in CSV format is read in and examined through the following steps:
Set the current directory
octave>
dir='/home/student/courses/MATH590/NUMdata';
chdir(dir);
octave>
Read the CSV-formatted data, and find the size of the data
octave>
data=csvread('Mitran.csv');
[m,d] = size(data); disp([m d]);
octave>
Visually examine some of the data
octave>
data(1:10,:)
octave>
Each line contains , with the elapsed time, the linear accelation at time , the angular acceleration at time . Note that there are several repeated values. Since solving the IVP (10) requires definition of the functions , some initial processing is required to eliminate duplicate values. The Octave unique function is used to obtain a vector t of the mu unique values, and the indices iu at which each unique value is first encountered.
octave>
[t,iu]=unique(data(:,1));
octave>
t(1:10)'
octave>
iu(1:16)'
octave>
mu=max(size(iu))
octave>
t(mu-6:mu)'
octave>
iu(mu-6:mu)'
octave>
raddeg=pi/180
octave>
Define vectors a, epsilon containing unique linear, angular acceleration values.
octave>
a=data(iu,2:4); epsilon=data(iu,5:7)/raddeg;
octave>
[a(1:6,:) epsilon(1:6,:)]
octave>
data(1:10,:)
octave>
Having ensured data corresponds to functions , a next step is data visualization. This shall be accomplished by writing the data to a text file and using the Gnuplot utility.
octave>
fid=fopen('Mitran.data','w');
fprintf(fid,'%f %f %f %f %f %f %f\n',[t a epsilon]');
fclose(fid);
octave>
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot 'Mitran.data' u 1:2 w l ls 1 title "a1",
” u 1:3 w l ls 2 title "a2", ” u 1:4
w l ls 3 title "a3"
GNUplot]
Observations on the above plot (qualitative data analysis):
average accelerations seem to be zero as expected for a closed path. This can readily be checked
octave>
mean(a)
octave>
std(a)
octave>
mean(a)./std(a)
octave>
From the above, the ratios of the means to the standard deviations are between 2% and 9%, hence relatively small.
In addition to the overall plot, it is useful to plot smaller time windows
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot "<(sed -n '300,800p' 'Mitran.data')" u
1:3 w l ls 1, ” u 1:4 w l ls 2, ” u 1:5 w l ls
3
GNUplot]
It is remarkable that a clear waveform appears in the data. The wave form along corresponds to left-right accelerations during bipedal walking. The wave form along corresponds to up-down accelerations.
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot 'Mitran.data' u 1:5 w l ls 1 title
"epsilon1", ” u 1:6 w l ls 2 title
"epsilon2", ” u 1:7 w l ls 3 title
"epsilon3"
GNUplot]
Observations:
There are bursts of large angular accelerations around the axis. As will be seen later, this generally corresponds to the vertical axis and the bursts correspond to turns in direction of the walker.
Recall that the integration
is essentially a non-compressive data transformation. The above is a cummulative sum, readily evaluated in Octave
octave>
shift([1 2 3 4],-1)
octave>
omega=zeros([mu,3]);
h = shift(t,-1)-t;
octave>
[h(1:10) t(1:10)]
octave>
omega(2:mu,1) = cumsum(h(1:mu-1).*epsilon(1:mu-1,1));
omega(2:mu,2) = cumsum(h(1:mu-1).*epsilon(1:mu-1,2));
omega(2:mu,3) = cumsum(h(1:mu-1).*epsilon(1:mu-1,3));
octave>
[omega(1:6,1) epsilon(1:6,1)]
octave>
The same procedure can be used to compute the time history of the relative reference frame orientation
octave>
U=zeros([mu,3,3]); I3=eye(3); U(1,:,:)=I3; U0=I3;
octave>
i=1; while(i<mu)
om(1:3) = omega(i,1:3);
S=[0 -om(3) om(2); om(3) 0 -om(1); -om(2) om(1) 0];
[U1,R1] = qr((I3 + h(i)*S)*U0);
U1 = U1*diag(sign(diag(R1)));
U(i+1,:,:)=U1;
i++; U0=U1;
endwhile
octave>
Display of successive clearly shows the rotation of the axes carried by the cell phone
octave>
i=1; di=50; while(i<300)
U1=reshape(U(i,:,:),3,3);
disp(strcat('At time t=',num2str(t(i)))); disp(U1);
disp(' ');
i=i+di;
endwhile
1 0 0 0 1 0 0 0 1 At time t=0.671 0.815161 -0.376014 0.440596 0.080612 0.826896 0.556548 -0.573597 -0.418159 0.704365 At time t=1.266 0.110337 -0.982359 0.150984 0.200490 0.170788 0.964694 -0.973463 -0.076171 0.215797 At time t=1.858 0.675025 -0.721612 0.153679 0.049460 0.252085 0.966440 -0.736135 -0.644770 0.205855 At time t=2.502 -0.96946 -0.20458 0.13529 0.16788 -0.15139 0.97411 -0.17880 0.96707 0.18111 At time t=3.062 -0.385709 0.914210 0.124289 -0.080865 -0.167693 0.982517 0.919070 0.368915 0.138608
octave>
Integration of and provides the walker trajectory
octave>
V=zeros([mu,3]); X=V; I3=eye(3); U(1,:,:)=I3; U0=I3;
octave>
i=1; while(i<mu)
U1=reshape(U(i+1,:,:),3,3);
V(i+1,:) = V(i,:) + h(i)*a(i+1,:)*U1';
X(i+1,:) = X(i,:) + h(i)*V(i+1,:);
i++;
endwhile
octave>
Write the resulting positions and velocities to a file in preparation for plotting
octave>
fid=fopen('MitranTrajectory.data','w');
fprintf(fid,'%f %f %f %f %f %f %f\n',[t X V]');
fclose(fid);
octave>
Plot the trajectory
GNUplot]
splot
'/home/student/courses/MATH590/NUMdata/MitranTrajectory.data'
u 2:3:4 w l
GNUplot]
After reconstructing the trajectory from accelerometer data, the problem of extracting individual walker features from the data is considered.
Recall that a regular pattern is apparent in the accelerometer data, one that we associate with the walker's gait. We now consider the problem of characterizing the gait
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot "<(sed -n '300,600p' 'Mitran.data')" u
1:2 w l ls 1, ” u 1:3 w l ls 2, ” u 1:4 w l ls
3
GNUplot]
Extract a data window of interest
octave>
iG0=300; nG=256; iG1=iG0+nG-1;
octave>
tG=t(iG0:iG1); aG=a(iG0:iG1,:);
octave>
Interpolate to obtain data at constant-spaced time increments. The second component of the acceleration vector, corresponding to vertical motion is chosen (green line in above plot).
octave>
tG0=tG(1); tG1=tG(nG); dt=(tG1-tG0)/nG;
octave>
tGi=tG0+(0:nG-1)*dt;
octave>
aGi=interp1(tG',aG(:,2)',tGi);
octave>
fid=fopen('InterpolatedVerticalAcceleration.data','w');
ta = [tGi' aGi'];
fprintf(fid,'%f %f\n',ta');
fclose(fid);
octave>
Plot the interpolated data
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "green" lw 3
plot "InterpolatedVerticalAcceleration.data"
u 1:2 w l ls 1
GNUplot]
Find the period by Fourier analysis
octave>
AGi=fft(aGi); PAGi = log10(AGi.*conj(AGi));
octave>
fid=fopen('GaitPowerSpectrum.data','w');
fprintf(fid,'%f\n',PAGi(1:nG/2-1));
fclose(fid);
octave>
A plot of the power spectrum (in logarithmic coordinates) shows a distinct maximum
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "green" lw 3
plot 'GaitPowerSpectrum.data' w l ls 1
GNUplot]
octave>
[val,idx] = max(PAGi); disp([val idx]);
octave>
Determine the period
octave>
TG = (tG1-tG0)/(idx-1)
octave>
nT=floor(max(size(aGi))/(idx-1))
octave>
Determine locations of the peak vertical accelerations. Note that the particular values for MinPeakHeight, MinPeakDistance have to be determined by experimentation, checking the plot to see the peaks have been identified.
octave>
[aPeak, iPeak] =
findpeaks(aGi-min(aGi),"MinPeakHeight",1.,"MinPeakDistance",nT/3);
fid=fopen('TrajectoryPeaks.data','w');
ta = [tGi(iPeak)' (aPeak+min(aGi))'];
fprintf(fid,'%f %f\n',ta');
fclose(fid);
octave>
nPeriods = max(size(iPeak))-1
octave>
iPeak
octave>
shift(iPeak,-1)
octave>
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot "InterpolatedVerticalAcceleration.data"
u 1:2 w l ls 2, "TrajectoryPeaks.data" u 1:2
w p ls 1
GNUplot]
Extract data during nPeriods
First find the maximum number of data points between the maxima, allocate space for the data, and extract the measured cycles
octave>
nT = (shift(iPeak,-1)-iPeak+1)(1:nPeriods)
octave>
nTmax = max(nT);
tT = zeros([nTmax,nPeriods]);
aT = zeros([nTmax,nPeriods]);
TT = zeros([nPeriods,1]);
i=1; while(i<=nPeriods)
tT(1:nT(i),i) = tGi(iPeak(i):iPeak(i+1));
aT(1:nT(i),i) = aGi(iPeak(i):iPeak(i+1));
TT(i) = tT(nT(i),i) - tT(1,i);
i++;
endwhile;
disp(TT');
octave>
Scale the data to have the same amplitude and period
octave>
i=1; while(i<=nPeriods)
tT(1:nT(i),i) = tT(1:nT(i),i) - tT(1,i);
tT(1:nT(i),i) = tT(1:nT(i),i)/TT(i);
amp = max(aT(1:nT(i),i)) - min(aT(1:nT(i),i));
aT(1:nT(i),i) = aT(1:nT(i),i)/amp;
i++;
endwhile;
octave>
Interpolate to obtain periods with equal number of samples, and also define an average waveform over the periods
octave>
nTi=100;
dt=1./(nTi-1); ti=(0:nTi-1)*dt; ti=ti';
aTi=zeros([nTi,nPeriods]); g=zeros([nTi,1]);
i=1; while(i<=nPeriods)
ai =
interp1(tT(1:nT(i),i),aT(1:nT(i),i),ti',"nearest");
aTi(:,i) = ai;
g = g + ai';
i++;
endwhile;
g = g/nPeriods;
g = g/(max(g)-min(g));
octave>
fid=fopen('Periods.data','w');
ta = [ti aTi g];
fprintf(fid,'%f %f %f %f %f %f\n',ta');
fclose(fid);
fid=fopen('AveragePeriod.data','w');
ta = [ti g];
fprintf(fid,'%f %f \n',ta');
fclose(fid);
octave>
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 6
set style line 2 lt 2 lc rgb "green" lw
3
set style line 3 lt 2 lc rgb "blue" lw 3
plot "Periods.data" u 1:2 w l ls 3,
” u 1:3 w l ls 3, ” u 1:4 w l ls 3,
” u 1:5 w l ls 3, ” u 1:6 w l ls 1
GNUplot]
Seek a more economical representation of the average gait waveform, currently stored as a vector of the vertical acceleration values at times within the vector . For example, consider approximating the waveform by a parabola , leading to the least squares problem
(11) |
A solution is found by projection onto the column space of ,
(12) |
octave>
L=[ti.^0 ti ti.^2]; [Q,R]=qr(L,0); [size(Q); size(R)]
octave>
c = R \ Q'*g
octave>
p = L*c;
fid=fopen('LeastSquares.data','w');
ta = [ti g p];
fprintf(fid,'%f %f %f\n',ta');
fclose(fid);
octave>
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 6
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 3
plot "LeastSquares.data" u 1:2 w l ls 2, ”
u 1:3 w l ls 1
GNUplot]
An alternative representation is through a linear combination of Chebyshev polynomials,
known to be a good approximation of the min-max polynomial of the data. The coefficient vector is more difficult to find by comparison to the least squares case, and is carried out through a procedure known as the exchange algorithm, implemented in Octave by the polyfitinf function.
octave>
d=polyfitinf(2,nTi,0,ti,g,5.0E-7,nTi)
octave>
q = polyval(d,ti);
fid=fopen('MinMax.data','w');
ta = [ti g q];
fprintf(fid,'%f %f %f\n',ta');
fclose(fid);
octave>
GNUplot]
cd '/home/student/courses/MATH590/NUMdata'
set terminal postscript eps enhanced color
set style line 1 lt 2 lc rgb "red" lw 6
set style line 2 lt 2 lc rgb "green" lw 3
set style line 3 lt 2 lc rgb "blue" lw 6
plot "LeastSquares.data" u 1:3 w l ls 1, ”
u 1:2 w p ls 2, "MinMax.data" u 1:3 w l ls 3
GNUplot]