How are your distances determined?
RSSI filtering
RSSI needs to be (low-pass) filtered to become accurate (try filterFactor=0.1):
filteredRSSI = beacon.RSSI * filterFactor + filteredRSSI * (1.0 - filterFactor)
RSSI to distance (meters)
Distance in meters can be calculated by txPower and measured RSSI:
double calculateDistance( int txPower, double rssi ) {
if (rssi == 0) return -1.0; // if we cannot determine accuracy, return -1.
double ratio = rssi*1.0/txPower;
if (ratio < 1.0) return pow(ratio,10);
else return (0.89976) * pow(ratio,7.7095) + 0.111;
}
Trilateration
}
I have also The Trialateration code for 3 Beacons But I Need Trilateration for N Beacons (Rilevated from a scanning functions).
Trilateration
Trilateration estimates the receivers’s position (using 3 or more) measured distances (meters) to the beacons and the known beacons positions.
float xa = beacon1.locationX;
float ya = beacon1.locationY;
float xb = beacon2.locationX;
float yb = beacon2.locationY;
float xc = beacon3.locationX;
float yc = beacon3.locationY;
float ra = beacon1.filteredDistance;
float rb = beacon2.filteredDistance;
float rc = beacon3.filteredDistance;
float S = (pow(xc, 2.) - pow(xb, 2.) + pow(yc, 2.) - pow(yb, 2.) + pow(rb, 2.) - pow(rc, 2.)) / 2.0;
float T = (pow(xa, 2.) - pow(xb, 2.) + pow(ya, 2.) - pow(yb, 2.) + pow(rb, 2.) - pow(ra, 2.)) / 2.0;
float y = ((T * (xb - xc)) - (S * (xb - xa))) / (((ya - yb) * (xb - xc)) - ((yc - yb) * (xb - xa)));
float x = ((y * (ya - yb)) - T) / (xb - xa);
// now x, y is the estimated receiver position