Skip to content

PHP class that compares a multidimensional array to other multidimensional arrays and computes the similarity (Euclidian distance) between them

License

Notifications You must be signed in to change notification settings

ericntully/CrossCorellationAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quickstart:
    1.  php examples/usage_in_a_test.php

You've given panic devices to the housekeeping staff at your hotel to call for help in an 
emergency.  Since GPS wouldn't be able to determine what floor of the hotel they're on, 
you've installed radio beacons in each hotel room broadcasting their specific location.  

Pressing the panic button causes the device to listen for as many beacons as it can hear 
and it reports the beacon with the strongest signal strength.

The problem is that the radio signals are stronger than you expected and the panic 
device is able to hear five or six beacons (on different floors, no less), each with
100% signal strength.

The solution:  Do some pre-processing to take a one-time sample of the hotel.  Stop in 
each room to take a reading of ALL the signals that can be heard there.  The list of 
beacons (and their signal strengths) form a unique fingerprint.  

For example, there is ONLY ONE ROOM in the hotel where 
this set of beacons can be heard at these signal strengths:

[	"Room 310,  80%"  , 	"Room 311, 98%"   , 	"Room 312, 100%"   , 
	"Room 410, 100%"  , 	"Room 411, 98%"   , 	"Room 412, 85%"   ,
	"Room 510,  40%"  , 	"Room 511, 100%"   , 	"Room 512, 75%"   
]

When an emergency call is received with a list of beacon signals, use the cross-corellation 
algorithm to find room with the best statistical match. Even when the panic device can hear 
five (or even ten) beacons, all with 100% signal strength, this statistical technique will 
identify the room's location with 100% accuracy.

Installation:
    1.  composer install
    2.  create database table "signals" with fields:
            room_number, beacon_id, signal_strength
    3.  install BLE beacons in every room.
    4.  use PERS unit to sample every room.
    5.  record signal results of ALL beacons in EACH room. 
        ie:  room #410,  PERS unit detects FIVE beacons, then  insert 5 rows 
             into the signals table like this:

             INSERT INTO signals (room_number, beacon_id, signal_strength)
             VALUES ( 410,  12345678,  50),
                    ( 410,  12345679,  90),
                    ( 410,  12345680,  90),
                    ( 410,  12345681,  50),
                    ( 410,  12345682,   5);

        repeat this step for EVERY room in the building,  recording ALL the 
        beacon IDs and signal strengths that were detected each room.

    6.  modify the EmergencySignal class to enable DB connections 
        based on the framework you are using.

Usage:

    - Assuming that a PERS unit has detected BLE signals in an unknown 
        room and makes API call to your script passing an array of the 
        BLE signals it heard and their signal strengths, like this:

        $em_sig = Array(    Array( 12345678,  45),
                            Array( 12345679,  90),
                            Array( 12345680,  85),
                            Array( 12345681,  60),
                            Array( 12345682,   4)
        );

    - Create an instance of the EmergencySignal class, passing  $em_sig  like this:

            $es = new EmergencySignal($em_sig);

    - Find the best matching room number:

            $best_match_room_number = $es->get_best_match();


----------------------------------------------------------------------------------


Project Summary:  Identifying Indoor Locations

Background: The company, a major supplier of PERS devices (Personal Emergency Response
System), was asked to provide emergency call devices to hospital and hotel "lone workers" 
(nurses, housekeeping, etc.).  The units include GPS, WiFi, cellular, and Bluetooth, 
connections.  They have a single push button for use in an emergency.

The challenge:  Identifying the precise location during an emergency.  GPS signal is 
unreliable indoors and, more importantly, lacks the ability to determine floor level 
in multi-story buildings.

Our initial solution:  Installing Bluetooth Low Energy (BLE) beacons in every room and
listening for the strongest beacon signal failed because the PERS unit registered 
simultaneous detection of multiple beacons - often five or more from adjacent rooms and 
floors - all registering near-maximum signal strength.  Reliance on strongest signal 
strength was insufficient.

I was appointed to lead a project to improve the accuracy of room identification. It was
assumed that machine learning would be required.  My core insight was to recognize that
the unique combination and strength of all detectable beacons in any given room created
a unique fingerprint.

We conducted an initial site survey, visiting each room and recording the signal strengths
of all beacons that could be heard in each room and stored the results in a table called
sample_readings.

When an emergency call is activated, the PERS unit reports the list of beacons that are
detectable along with their respective signal strengths.  To find the location, we perform
a comparison between the beacons included in the emergency signal to the readings that
were taken during the site survey.

The SQL query retrieves all sample readings that share at least one beacon in the emergency
signal.

The Algorithm: I used the Cross-Correlation Algorithm (specifically, the Pearson Correlation
Coefficient), which uses Euclidean distance to compare the "similarity" between the emergency
signal's fingerprint to the fingerprints of the stored sample. The highest correlation
score identifies the correct room.

Performance and Conclusion:  The project was initially estimated to require three developers
for a month, with time allocated for researching complex machine learning solutions.

I wrote my solution in four hours.  In a real-world hotel setting (500 rooms), the time
required to perform the SQL query and run the comparison algorithm on each result is able
to identify the room in less than 2ms.  This solution, using a fundamental statistical
algorithm, provides an immediate response with 100% accuracy - and saved three months
of development time.

About

PHP class that compares a multidimensional array to other multidimensional arrays and computes the similarity (Euclidian distance) between them

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages