diff --git a/firmware/util/math/avg_values.cpp b/firmware/util/math/avg_values.cpp deleted file mode 100644 index 17d78c3e8d..0000000000 --- a/firmware/util/math/avg_values.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * avg_values.c - * - * @date Jul 23, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "avg_values.h" -#include - -void avgFill(AvgTable *table, int count, float value) { - for (int i = 0; i < AVG_TAB_SIZE; i++) { - for (int j = 0; j < AVG_TAB_SIZE; j++) { - table->counts[i][j] = count; - table->values[i][j] = value; - } - } -} - -void avgReset(AvgTable *table) { - avgFill(table, 0, 0); -} - -void avgAddValue(AvgTable *table, int rpm, float key, float value) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - - table->values[i][j] += value; - table->counts[i][j]++; -} - -float avgGetValueByIndexes(AvgTable *table, int i, int j) { - int count = table->counts[i][j]; - if (count == 0) { - return NAN; - } - return table->values[i][j] / count; -} - -float avgGetValue(AvgTable *table, int rpm, float key) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return NAN; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - return avgGetValueByIndexes(table, i, j); -} - -int avgGetValuesCount(AvgTable *table, int rpm, float key) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return 0; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - - return table->counts[i][j]; -} diff --git a/firmware/util/math/avg_values.h b/firmware/util/math/avg_values.h deleted file mode 100644 index c7e4133662..0000000000 --- a/firmware/util/math/avg_values.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * avg_values.h - * - * @date Jul 23, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#define AVG_TAB_SIZE 48 - -#define MAX_RPM 8000 -#define MAX_KEY 5 - -typedef struct { - float values[AVG_TAB_SIZE][AVG_TAB_SIZE]; - int counts[AVG_TAB_SIZE][AVG_TAB_SIZE]; -} AvgTable; - - -void avgReset(AvgTable *table); -void avgFill(AvgTable *table, int count, float value); - -void avgAddValue(AvgTable *table, int rpm, float key, float value); -float avgGetValueByIndexes(AvgTable *table, int i, int j); -float avgGetValue(AvgTable *table, int rpm, float key); -int avgGetValuesCount(AvgTable *table, int rpm, float key); diff --git a/firmware/util/math/signal_filtering.c b/firmware/util/math/signal_filtering.c deleted file mode 100644 index 3b8454954b..0000000000 --- a/firmware/util/math/signal_filtering.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * @file signal_filtering.c - * - * @date Aug 5, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#ifndef SIGNAL_FILTERING_C_ -#define SIGNAL_FILTERING_C_ - -#include "signal_filtering.h" - -void sfInit(SignalFiltering *fs, float K, float initialValue) { - fs->pointer = 0; - fs->K = K; - fs->Vout = initialValue; - fs->Vacc = initialValue * K; -} - -static void addCopyAndSort(SignalFiltering *fs, float value) { - fs->values[fs->pointer] = value; - fs->pointer = ++fs->pointer == FILTER_SIZE ? 0 : fs->pointer; - - copyArray(fs->sorted, fs->values); - - for (int i = 0; i < FILTER_SIZE; i++) - for (int j = i + 1; j < FILTER_SIZE; j++) - if (fs->sorted[i] < fs->sorted[j]) { - float temp = fs->sorted[i]; - fs->sorted[i] = fs->sorted[j]; - fs->sorted[j] = temp; - } -} - -void sfAddValue(SignalFiltering *fs, float value) { - addCopyAndSort(fs, value); - float Vin = fs->sorted[FILTER_SIZE / 2]; - - fs->Vacc += Vin - fs->Vout; - fs->Vout = fs->Vacc / fs->K; -} - -void sfAddValue2(SignalFiltering *fs, float value) { - addCopyAndSort(fs, value); - - int fromIndex = FILTER_SIZE / 4; - int toIndex = FILTER_SIZE / 4 + FILTER_SIZE / 2; - - /** - * this implementation takes the average of the middle hald of the sorted values - */ - float result = 0; - for (int i = fromIndex; i < toIndex; i++) - result += fs->sorted[i]; - - fs->Vout = result / (FILTER_SIZE / 2); -} - -float sfGetValue(SignalFiltering *fs) { - return fs->Vout; -} - -#endif /* SIGNAL_FILTERING_C_ */ diff --git a/firmware/util/math/signal_filtering.h b/firmware/util/math/signal_filtering.h deleted file mode 100644 index 01df176e19..0000000000 --- a/firmware/util/math/signal_filtering.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * @file signal_filtering.h - * - * @date Aug 5, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#define FILTER_SIZE 5 - -typedef struct { - float values[FILTER_SIZE]; - float sorted[FILTER_SIZE]; - int pointer; - float K, Vacc, Vout; -} SignalFiltering; - -void sfInit(SignalFiltering *fs, float K, float initialValue); -void sfAddValue(SignalFiltering *fs, float value); -void sfAddValue2(SignalFiltering *fs, float value); -float sfGetValue(SignalFiltering *fs); diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 4eb73569b0..699aff16de 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -13,7 +13,6 @@ UTILSRC_CPP = \ $(UTIL_DIR)/containers/local_version_holder.cpp \ $(UTIL_DIR)/containers/table_helper.cpp \ $(UTIL_DIR)/math/pid.cpp \ - $(UTIL_DIR)/math/avg_values.cpp \ $(UTIL_DIR)/math/interpolation.cpp \ $(PROJECT_DIR)/util/datalogging.cpp \ $(PROJECT_DIR)/util/loggingcentral.cpp \