parent
472f557e7a
commit
c002b1fd80
|
@ -422,6 +422,7 @@ bool BleFingerprint::seen(BLEAdvertisedDevice *advertisedDevice) {
|
||||||
raw = pow(10, float(get1mRssi() - rssi) / (10.0f * BleFingerprintCollection::absorption));
|
raw = pow(10, float(get1mRssi() - rssi) / (10.0f * BleFingerprintCollection::absorption));
|
||||||
filteredDistance.addMeasurement(raw);
|
filteredDistance.addMeasurement(raw);
|
||||||
dist = filteredDistance.getDistance();
|
dist = filteredDistance.getDistance();
|
||||||
|
vari = filteredDistance.getVariance();
|
||||||
|
|
||||||
if (!added) {
|
if (!added) {
|
||||||
added = true;
|
added = true;
|
||||||
|
@ -442,6 +443,7 @@ bool BleFingerprint::fill(JsonObject *doc) {
|
||||||
|
|
||||||
if (isnormal(raw)) (*doc)[F("raw")] = serialized(String(raw, 2));
|
if (isnormal(raw)) (*doc)[F("raw")] = serialized(String(raw, 2));
|
||||||
if (isnormal(dist)) (*doc)[F("distance")] = serialized(String(dist, 2));
|
if (isnormal(dist)) (*doc)[F("distance")] = serialized(String(dist, 2));
|
||||||
|
if (isnormal(vari)) (*doc)[F("var")] = serialized(String(vari, 2));
|
||||||
if (close) (*doc)[F("close")] = true;
|
if (close) (*doc)[F("close")] = true;
|
||||||
|
|
||||||
(*doc)[F("int")] = (millis() - firstSeenMillis) / seenCount;
|
(*doc)[F("int")] = (millis() - firstSeenMillis) / seenCount;
|
||||||
|
|
|
@ -132,7 +132,7 @@ class BleFingerprint {
|
||||||
int rssi = NO_RSSI;
|
int rssi = NO_RSSI;
|
||||||
int8_t calRssi = NO_RSSI, bcnRssi = NO_RSSI, mdRssi = NO_RSSI, asRssi = NO_RSSI;
|
int8_t calRssi = NO_RSSI, bcnRssi = NO_RSSI, mdRssi = NO_RSSI, asRssi = NO_RSSI;
|
||||||
unsigned int qryAttempts = 0, qryDelayMillis = 0;
|
unsigned int qryAttempts = 0, qryDelayMillis = 0;
|
||||||
float raw = 0, dist = 0, lastReported = 0, temp = 0, humidity = 0;
|
float raw = 0, dist = 0, vari = 0, lastReported = 0, temp = 0, humidity = 0;
|
||||||
unsigned long firstSeenMillis, lastSeenMillis = 0, lastReportedMillis = 0, lastQryMillis = 0;
|
unsigned long firstSeenMillis, lastSeenMillis = 0, lastReportedMillis = 0, lastQryMillis = 0;
|
||||||
unsigned long seenCount = 1, lastSeenCount = 0;
|
unsigned long seenCount = 1, lastSeenCount = 0;
|
||||||
uint16_t mv = 0;
|
uint16_t mv = 0;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
FilteredDistance::FilteredDistance(float minCutoff, float beta, float dcutoff)
|
FilteredDistance::FilteredDistance(float minCutoff, float beta, float dcutoff)
|
||||||
: minCutoff(minCutoff), beta(beta), dcutoff(dcutoff), x(0), dx(0), lastDist(0), lastTime(0), total(0), readIndex(0) {
|
: minCutoff(minCutoff), beta(beta), dcutoff(dcutoff), x(0), dx(0), lastDist(0), lastTime(0), total(0), totalSquared(0), readIndex(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilteredDistance::initSpike(float dist) {
|
void FilteredDistance::initSpike(float dist) {
|
||||||
|
@ -15,12 +15,17 @@ void FilteredDistance::initSpike(float dist) {
|
||||||
readings[i] = dist;
|
readings[i] = dist;
|
||||||
}
|
}
|
||||||
total = dist * NUM_READINGS;
|
total = dist * NUM_READINGS;
|
||||||
|
totalSquared = dist * dist * NUM_READINGS; // Initialize sum of squared distances
|
||||||
}
|
}
|
||||||
|
|
||||||
float FilteredDistance::removeSpike(float dist) {
|
float FilteredDistance::removeSpike(float dist) {
|
||||||
total -= readings[readIndex]; // Subtract the last reading
|
total -= readings[readIndex]; // Subtract the last reading
|
||||||
readings[readIndex] = dist; // Read the sensor
|
totalSquared -= readings[readIndex] * readings[readIndex]; // Subtract the square of the last reading
|
||||||
|
|
||||||
|
readings[readIndex] = dist; // Read the sensor
|
||||||
total += readings[readIndex]; // Add the reading to the total
|
total += readings[readIndex]; // Add the reading to the total
|
||||||
|
totalSquared += readings[readIndex] * readings[readIndex]; // Add the square of the reading
|
||||||
|
|
||||||
readIndex = (readIndex + 1) % NUM_READINGS; // Advance to the next position in the array
|
readIndex = (readIndex + 1) % NUM_READINGS; // Advance to the next position in the array
|
||||||
|
|
||||||
auto average = total / static_cast<float>(NUM_READINGS); // Calculate the average
|
auto average = total / static_cast<float>(NUM_READINGS); // Calculate the average
|
||||||
|
@ -62,3 +67,9 @@ float FilteredDistance::getAlpha(float cutoff, float dT) {
|
||||||
float tau = 1.0f / (2 * M_PI * cutoff);
|
float tau = 1.0f / (2 * M_PI * cutoff);
|
||||||
return 1.0f / (1.0f + tau / dT);
|
return 1.0f / (1.0f + tau / dT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float FilteredDistance::getVariance() const {
|
||||||
|
float mean = total / static_cast<float>(NUM_READINGS);
|
||||||
|
float meanOfSquares = totalSquared / static_cast<float>(NUM_READINGS);
|
||||||
|
return meanOfSquares - (mean * mean); // Variance formula: E(X^2) - (E(X))^2
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define SPIKE_THRESHOLD 1.0f // Threshold for spike detection
|
#define SPIKE_THRESHOLD 1.0f // Threshold for spike detection
|
||||||
#define NUM_READINGS 10 // Number of readings to keep track of
|
#define NUM_READINGS 12 // Number of readings to keep track of
|
||||||
|
|
||||||
class FilteredDistance {
|
class FilteredDistance {
|
||||||
public:
|
public:
|
||||||
|
@ -12,6 +12,8 @@ class FilteredDistance {
|
||||||
void addMeasurement(float dist);
|
void addMeasurement(float dist);
|
||||||
const float getMedianDistance() const;
|
const float getMedianDistance() const;
|
||||||
const float getDistance() const;
|
const float getDistance() const;
|
||||||
|
const float getVariance() const;
|
||||||
|
|
||||||
bool hasValue() const { return lastTime != 0; }
|
bool hasValue() const { return lastTime != 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,6 +29,7 @@ class FilteredDistance {
|
||||||
float readings[NUM_READINGS]; // Array to store readings
|
float readings[NUM_READINGS]; // Array to store readings
|
||||||
int readIndex; // Current position in the array
|
int readIndex; // Current position in the array
|
||||||
float total; // Total of the readings
|
float total; // Total of the readings
|
||||||
|
float totalSquared; // Total of the squared readings
|
||||||
|
|
||||||
void initSpike(float dist);
|
void initSpike(float dist);
|
||||||
float removeSpike(float dist);
|
float removeSpike(float dist);
|
||||||
|
|
3811
src/ui_index_js.h
3811
src/ui_index_js.h
File diff suppressed because it is too large
Load Diff
|
@ -31,6 +31,14 @@
|
||||||
sortable: true,
|
sortable: true,
|
||||||
class: "px-0 py-0 whitespace-nowrap",
|
class: "px-0 py-0 whitespace-nowrap",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: "var",
|
||||||
|
title: "Var",
|
||||||
|
value: (v) => v.var ?? 0,
|
||||||
|
renderValue: (v) => v.var === undefined ? "n/a" : `${v.var?.toLocaleString(undefined, { minimumFractionDigits: 2 })} m`,
|
||||||
|
sortable: true,
|
||||||
|
class: "px-0 py-0 whitespace-nowrap",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "id",
|
key: "id",
|
||||||
title: "ID",
|
title: "ID",
|
||||||
|
|
Loading…
Reference in New Issue