From c1c949156f831aa617bcf40b9be2eb49d2a023f9 Mon Sep 17 00:00:00 2001
From: Federico Lolli <federico.lolli@skywarder.eu>
Date: Tue, 14 Nov 2023 19:13:42 +0100
Subject: [PATCH] [SFD] fixed logic bugs with GNC - various logic bugs solved -
 added a bit of documentation - removed unneeded comments and unused variables

---
 src/shared/algorithms/SFD/SFDAscent.cpp | 2 +-
 src/shared/algorithms/SFD/SFDAscent.h   | 5 +++++
 src/shared/algorithms/SFD/SFDDescent.h  | 5 +++++
 src/shared/sensors/SFD/PressureSFD.cpp  | 3 ---
 src/shared/sensors/SFD/PressureSFD.h    | 2 +-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/shared/algorithms/SFD/SFDAscent.cpp b/src/shared/algorithms/SFD/SFDAscent.cpp
index 355faf8e2..4a5270544 100644
--- a/src/shared/algorithms/SFD/SFDAscent.cpp
+++ b/src/shared/algorithms/SFD/SFDAscent.cpp
@@ -52,7 +52,7 @@ SFDAscent::FeaturesVec SFDAscent::getFeatures(const SFDVectorIn& input)
     s2  = x0.array().pow(2).mean();
     m4  = x0.array().pow(4).mean();
 
-    rfourier = FFT32::fft(data).real();  // TODO: fix complex -> float
+    rfourier = FFT32::fft(data).cwiseAbs();  // TODO: fix complex -> float
     rfmean   = rfourier.mean();
     rfvar = (rfourier - rfmean * SFDVectorIn::Ones()).squaredNorm() / LEN_CHUNK;
 
diff --git a/src/shared/algorithms/SFD/SFDAscent.h b/src/shared/algorithms/SFD/SFDAscent.h
index 95f98437c..93b79568b 100644
--- a/src/shared/algorithms/SFD/SFDAscent.h
+++ b/src/shared/algorithms/SFD/SFDAscent.h
@@ -48,6 +48,11 @@ public:
 
     explicit SFDAscent(const SFDAscentConfig& config);
 
+    /**
+     * @brief Classifies the input vector as faulty or not.
+     *
+     * @return true if the input is faulty, false otherwise.
+     */
     bool classify(const SFDVectorIn& input);
 
 private:
diff --git a/src/shared/algorithms/SFD/SFDDescent.h b/src/shared/algorithms/SFD/SFDDescent.h
index c41a57aa3..a435fdb94 100644
--- a/src/shared/algorithms/SFD/SFDDescent.h
+++ b/src/shared/algorithms/SFD/SFDDescent.h
@@ -48,6 +48,11 @@ public:
 
     explicit SFDDescent(const SFDDescentConfig& config);
 
+    /**
+     * @brief Classifies the input vector as faulty or not.
+     *
+     * @return true if the input is faulty, false otherwise.
+     */
     bool classify(const SFDVectorIn& input);
 
 private:
diff --git a/src/shared/sensors/SFD/PressureSFD.cpp b/src/shared/sensors/SFD/PressureSFD.cpp
index 7aead52a5..e5c4d369a 100644
--- a/src/shared/sensors/SFD/PressureSFD.cpp
+++ b/src/shared/sensors/SFD/PressureSFD.cpp
@@ -110,7 +110,6 @@ PressureSFDData PressureSFD::sampleImpl()
     processed_value = medianFilter.filter(processed_value);
     processed_value = lowPassFilter.filter(processed_value);
 
-    samples       = sampleWindow.last();
     data.pressure = processed_value;
 
     return data;
@@ -147,7 +146,6 @@ void PressureSFD::setDisabledSensors()
                     skipped++;
                     continue;
                 }
-                // TODO: check if the score is correct (true means faulty)
                 if (sfdAscent.classify(sensor_samples[i]))
                 {
                     disabledSensors[i] = true;
@@ -164,7 +162,6 @@ void PressureSFD::setDisabledSensors()
                     skipped++;
                     continue;
                 }
-                // TODO: check if the score is correct (true means faulty)
                 if (sfdDescent.classify(sensor_samples[i]))
                 {
                     disabledSensors[i] = true;
diff --git a/src/shared/sensors/SFD/PressureSFD.h b/src/shared/sensors/SFD/PressureSFD.h
index 553c77d3a..98a7d3c4b 100644
--- a/src/shared/sensors/SFD/PressureSFD.h
+++ b/src/shared/sensors/SFD/PressureSFD.h
@@ -49,7 +49,7 @@ class PressureSFD : public Sensor<PressureSFDData>
 {
 public:
     static constexpr int MASKED_SENSORS = 2;
-    static constexpr int WIN_LEN        = MASKED_SENSORS * LEN_CHUNK;
+    static constexpr int WIN_LEN        = LEN_CHUNK;
 
     // TODO: set these values
     static constexpr int MED_FILTER_WIN_LEN   = 25;
-- 
GitLab