In the present day we’re joined by Rafael Otero, Alejandro Sánchez Roncero, Víctor Manuel López Higueras, and Pablo Pastor, who received first place at MATHACK 2022 by growing an software that may detect if somebody has skilled a bodily shock and, if that’s the case, ship an alert to a selected emergency contact. Over to you guys!
Breaking down the issue
All of the members of the workforce had earlier expertise working with MATLAB since it’s included in our college diploma curriculum (Aerospace Engineering). Nonetheless, the actual fact of getting to use our information to an actual drawback was initially troublesome for us as a result of wehadn’t used MATLAB Cellular earlier than and we had problem collectively producing our personal datasets for coaching and validation (normally they’re supplied in school classes). For a similar motive, we have been additionally excited to get fingers on expertise and deal with this problem.After a couple of minutes of brainstorming and a few concepts, we got here up with the thought to implement a Shock Alert Monitor (SAM). SAM would have two predominant functionalities: estimate the present dynamic state of the individual carrying the cellular (i.e., idle, strolling or operating) and detecting shocks. On this approach, the appliance might notify to the individual’s kin by way of Telegram if a shock was detected, in order that medical help could possibly be supplied quicker than in regular conditions.
This challenge is thus associated to the next SDGs:
- SDG3 (Good well being and well-being) by bettering healthcare because it drastically reduces the arrival time of medical workers.
- SDG10 (Reduces inequalities): by serving to individuals who reside removed from hospitals in large cities and whose entry to healthcare shouldn’t be completely assured.
- SDG11 (Sustainable cities and communities): by extending theSmart Metropolis idea since itprovides helpful data for metropolis companies.
How SAM works?
Through the competitors, all members of the workforce labored arduous to develop the Shock Alert Monitor. The SAM challenge will be divided into 5 components: Knowledge acquisition, Filtering, State classification, Shock detection and Shock Notification. These components will be seen within the followingfigure:
1. Knowledge acquisition
Utilizing the appliance MATLAB Cellular, we collect from the sensors of the smartphone the next knowledge:
- Acceleration (linear and angular) within the physique reference system of the cellular.
- Place (i.e., latitude, longitude and altitude).
The info is streamed repeatedly and in actual time from the cell phone to the pc by way of web. This offers a fantastic benefit since each units should not required to stay shut to one another for the appliance to work accurately. The acquisition frequency was set to 100 Hz (the utmost allowed by the appliance). With the assistance of MATLAB documentation, the implementation was easy: from the cellular facet, we solely want to put in the appliance and connect with the MATLAB cloud. From the pc facet, we additionally connect with the MATLAB cloud and create a moviledev object which will get up to date repeatedly.
Tovalidate the mannequin in later phases, we additionally allowed the choice to decide on between real-time knowledge or knowledge that was logged beforehand. Utilizing the second possibility, a datafile was loaded through the setup of our program.
obj.offline_data.Acceleration = Acceleration;
obj.offline_data.Place = Place;
% Allows the cellular to log and stream knowledge
obj.mobile_obj = mobiledev;
obj.mobile_obj.SampleRate = 100; % Units pattern fee at which gadget will purchase the info
obj.mobile_obj.AngularVelocitySensorEnabled = 1;
obj.mobile_obj.OrientationSensorEnabled = 1;
obj.mobile_obj.AccelerationSensorEnabled = 1;
obj.mobile_obj.PositionSensorEnabled = 1;
obj.mobile_obj.MagneticSensorEnabled = 1;
obj.mobile_obj.Logging = 1; % Begin the transmission of information from all chosen sensors
error(‘Chosen mode: %s not legitimate’, obj.mode);
The speed and the place weren’t required to be filtered.
3. State classifier
The pace of the person, which will be obtained via MATLAB Cellular, is used to find out if they’re idle, strolling, operating or driving.However why do we have to know the state of the smartphone if we solely need to detect acceleration shocks? For a security motive: If we detect a 2g shock whereas the person is driving, it is going to be extra harmful than the identical shock when the person is idle or strolling. That motive makes this a part of the challenge essential as a result of if we all know the state of the person, we will decide how dangerous the detected shock has been.
velocity = dataset.velocity;
mannequin = fitcknn(velocity,label,‘OptimizeHyperparameters’,‘auto’);
%% Compute the loss and get the confusion chart
predictions = predict(mannequin,velocity);
As soon as the mannequin is skilled, we’re able to predict the state of the person with the subsequent MATLAB operate:
operate state = getState(velocity,mannequin,interval,Fs)
% state -> State of the sensor based mostly in its velocity
% velocity -> Velocity magnitude time vector (m/s)
% mannequin -> Machine Studying mannequin used for prediction
% interval -> Interval used for computing the imply of velocity (s)
% Fs -> Sampling fee (Hz)
Vmean = imply(velocity(end-interval*Fs:finish));
state = char(predict(mannequin,Vmean));
4. Shock detection
To handle if the smartphone of the person has suffered an necessary acceleration shock, we simply compute the utmost acceleration in a pre-defined interval. Then, we examine this most with our threshold acceleration and if the brink is exceeded, we detect the shock with a Boolean variable:
operate [shock, Amax] = isShock(acceleration,threshold,interval,Fs)
% shock -> Signifies a shock within the acceleration knowledge (boolean)
% Amax -> Most acceleration within the samples (m/s2)
% acceleration -> Acceleration magnitude time vector (m/s2)
% threshold -> Acceleration above this worth might be thought of as shocks (m/s2)
% interval -> Interval used within the shock search (s)
% Fs -> Sampling fee (Hz)
Amax = max(acceleration(end-interval*Fs:finish));
SAM solely sends a notification if the acceleration threshold has been exceeded. Within the message we will see the magnitude of the shock (measured in g’s), the state of the person (IDLE, WALKING, RUNNING or DRIVING) and the situation of the influence in a map.
% state -> State of the sensor based mostly in its velocity
% Amax -> Most acceleration of the shock (m/s2)
BotToken = ‘HERE YOUR BOT TOKEN’;
ChatID = ‘HERE THE CHAT ID OF THE PERSON YOU WANT TO NOTIFY’;
ShockBot = telegram_bot(BotToken);
mapsURL = [‘https://www.google.es/maps/dir//’ sprintf(‘%.7f’,lat)…
‘,’ sprintf(‘%.7f’,lon) ‘/@’ sprintf(‘%.7f’,lat) ‘,’ sprintf(‘%.7f’,lon) ‘,16z?hl=es’];
geolimits([lat-0.001 lat+0.001],[lon-0.001 lon+0.001])
msg = [‘System detected a <b>’ sprintf(‘%.2f’,Amax/9.81) ‘g shock</b> while ‘…
‘user was <b>’ state ‘</b>. Google Maps: ‘ mapsURL];
ShockBot.sendPhoto(ChatID, ‘photo_file’, ‘map.png’,… % photograph
‘usepm’, true,… % present progress monitor
‘caption’, msg,‘parse_mode’,‘HTML’); % caption of photograph
Combining each defined step within the earlier sections, we will now see how SAM works. To check and validate the mannequin, we implement a simulation surroundings in Simulink. To debug the mannequin in real-time, we choose as solver an ode1 (Euler) with a fixed-step (1 s) and a cease time of infinity. On this approach, the mannequin will be operating on a regular basis it’s wanted, and we will visualise and debug the leads to actual time. Within the following image we present the scheme of the Simulink mannequin, the place the main_class refers a to a MATLAB class which implements all of the features that have been described beforehand.
Now we use this mannequin to check SAM. First, we will see one member of the workforce hanging his smartphone. The acceleration measurements are under the brink (he isn’t shaking his telephone) so no shock is detected by SAM.
Then, he throws his telephone, and a giant acceleration spike is captured. When the sign is larger than the acceleration threshold, SAM detects a shock as we will see within the subsequent picture:
When the shock is detected, a message via a Telegram bot is shipped to a different gadget. The alert accommodates the utmost acceleration detected, the recognized state by the ML mannequin and the situation of the telephone in a map: