mobiledev
object in MATLAB; for example: m = mobiledev with properties: Connected: 1 Available Cameras: {'back' 'front'} Logging: 0 InitialTimestamp: '' AccelerationSensorEnabled: 0 AngularVelocitySensorEnabled: 0 MagneticSensorEnabled: 0 OrientationSensorEnabled: 0 PositionSensorEnabled: 0
The displayed output should show
Connected:
1
,indicating that the
mobiledev
object has successfully established a connection to the app.Prepare for Data Acquisition
Enable the acceleration sensor on the device.
Start Acquiring Data
Logging
property allows you to begin sending sensor data to mobiledev
. m.Logging = 1;
The device is now transmitting sensor data.
During logging, the device is held or kept in a pocket while walking around. This generates changes in acceleration across all three axes, regardless of device orientation.
Retrieve Logged Data
accellog
is used to retrieve the XYZ acceleration data and timestamps transmitted from the device tomobiledev
.[a,t] = accellog(m);Plot Raw Sensor Data
The logged acceleration data for all three axes can be plotted together.plot(t,a); legend('X', 'Y', 'Z'); xlabel('Relative time (s)'); ylabel('Acceleration (m/s^2)');Process Raw Acceleration Data
To convert the XYZ acceleration vectors at each point in time into scalar values, the magnitude is calculated. This allows large changes in overall acceleration, such as steps taken while walking, to be detected regardless of device orientation.x = a(:,1); y = a(:,2); z = a(:,3); mag = sqrt(sum(x.^2 + y.^2 + z.^2, 2));The magnitude is plotted to visualize the general changes in acceleration.
plot(t,mag); xlabel('Time (s)'); ylabel('Acceleration (m/s^2)');The plot shows that the acceleration magnitude is not zero-mean. Subtracting the mean from the data will remove any constant effects, such as gravity.magNoG = mag - mean(mag); plot(t,magNoG); xlabel('Time (s)'); ylabel('Acceleration (m/s^2)');The plotted data is now centered about zero, and clearly shows peaks in acceleration magnitude. Each peak corresponds to a step being taken while walking.
Count the Number of Steps Taken
findpeaks
is a function from Signal Processing Toolbox that is used to find the local maxima of the acceleration magnitude data. Only peaks with a minimum height above one standard deviation are treated as a step. This threshold should be tuned experimentally to match a person's level of movement while walking, hardness of floor surfaces, etc.The number of steps taken is simply the number of peaks found.
The peak locations can be visualized with the acceleration magnitude data.
Clean Up
Turn off the acceleration sensor and clear
mobiledev
.
No comments:
Post a Comment