Saturday, February 25, 2023

Mobile Sensor fusion with MATLAB


In this project we will learn how to transfer our realtime mobile sensor data to our desktop ,now we apply algorithm on these sensor data to get some meaningful result,This whole procedure we have divided into three steps.
  1.Setup required in desktop
  2.Setup required in mobile
  3.Algorithm 

1. Setup required in desktop:-On the desktop open the MATLAB command window and type there first command (connector on <password>) 

after hitting the enter we get the DNS name or the IP address of the desktop  . Now we will use this IP address  in further setup in mobile application 
 
2.Setup required in mobile:-Download the MATLAB app from the given link .After installing the app you get the the interface like this
 



 click on the link "Connect to Your Computer" after that you will we redirect to this interface 


 







  At top right end  click on "Add a Computer"  after that you will get the interface given below now here put the computer IP address ( port :-31415 -by default) password will same as you have set in first heading after filling all this click on the link top right("Connect")


 



After clicking the connect come to the desktop . Further procedure is explained under the third heading 
  
3.Algorithms:-In the Command Window, create a 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.

m.AccelerationSensorEnabled = 1;

Start Acquiring Data 

After enabling the sensor, the Sensors screen of MATLAB Mobile will show the current data measured by the sensor. The 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 to mobiledev

[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.

minPeakHeight = std(magNoG);

[pks,locs] = findpeaks(magNoG,'MINPEAKHEIGHT',minPeakHeight);

The number of steps taken is simply the number of peaks found.

numSteps = numel(pks)

The peak locations can be visualized with the acceleration magnitude data.

hold on;
plot(t(locs), pks, 'r', 'Marker', 'v', 'LineStyle', 'none');
title('Counting Steps');
xlabel('Time (s)');
ylabel('Acceleration Magnitude, No Gravity (m/s^2)');
hold off;

Clean Up

Turn off the acceleration sensor and clear mobiledev.

m.AccelerationSensorEnabled = 0;

clear m;



No comments:

Post a Comment

Mobile Sensor fusion with MATLAB

In this project we will learn how to transfer our realtime mobile sensor data to our desktop ,now we apply algorithm on these sensor data to...