Добавлен RMS фильтр

This commit is contained in:
2025-12-02 18:39:52 +03:00
parent c5a01c56ac
commit 1f7384c5ed
2 changed files with 234 additions and 14 deletions

View File

@@ -94,7 +94,7 @@ int32_t process_value_int(int32_t raw_adc_quant) {
#ifndef FILTERS_DISABLE_MOVING_AVERAGE
#define FILTER_AVERAGE_MAX_SIZE 100 ///< Размер окна усредняющего фильтра
#else
#define FILTER_AVERAGE_MAX_SIZE 100000 ///< Размер окна усредняющего фильтра без буфера
#define FILTER_AVERAGE_MAX_SIZE 65535 ///< Размер окна усредняющего фильтра без буфера
#endif
#endif
@@ -106,6 +106,9 @@ int32_t process_value_int(int32_t raw_adc_quant) {
#define FILTER_POLY_MAX_ORDER 4 ///< Максимальный порядок полинома
#endif
#ifndef FILTER_RMS_MAX_SIZE
#define FILTER_RMS_MAX_SIZE 128 ///< Максимальный размер окна (рекомендуется степень 2)
#endif
#define check_proccess_func(_ptr_) \
((_fltr_)->process != NULL) 1 : \
@@ -259,6 +262,22 @@ typedef struct _FilterLUT_t{
float (*process)(struct _FilterLUT_t *filter, float input);
} FilterLUT_t;
/**
* @brief Структура True RMS фильтра (float)
*/
typedef struct _FilterRMS_t {
FilterState_t state; ///< Состояние фильтра
float buffer_sq[FILTER_RMS_MAX_SIZE]; ///< Буфер квадратов значений
float sum_squares; ///< Текущая сумма квадратов
float last_rms; ///< Последнее рассчитанное RMS значение
uint32_t window_size; ///< Размер окна усреднения
uint32_t index; ///< Текущий индекс в буфере
uint32_t count; ///< Количество накопленных значений
uint8_t dataProcessing; ///< Флаг - данные в обработке
int (*reset)(struct _FilterRMS_t *filter, uint32_t window_size);
float (*process)(struct _FilterRMS_t *filter, float input);
} FilterRMS_t;
// Float версии функций
int FilterMedian_Init(FilterMedian_t* filter, uint8_t size, float init_val);
@@ -271,6 +290,8 @@ int FilterPoly_Init(FilterPoly_t* filter, float* coeffs, uint8_t order);
float FilterPoly_Process(FilterPoly_t* filter, float input);
int FilterLUT_Init(FilterLUT_t* filter, float* input_arr, float* output_arr, uint16_t size, uint8_t interpolation);
float FilterLUT_Process(FilterLUT_t* filter, float input);
int FilterRMS_Init(FilterRMS_t* filter, uint32_t window_size);
float FilterRMS_Process(FilterRMS_t* filter, float input);
/**
@@ -328,6 +349,7 @@ float FilterLUT_Process(FilterLUT_t* filter, float input);
typedef struct _FilterMedianInt_t{
FilterState_t state; ///< Состояние фильтра
int32_t buffer[FILTER_MEDIAN_MAX_SIZE]; ///< Буфер значений
int32_t sorted[FILTER_MEDIAN_MAX_SIZE]; ///< Буфер отсортированных значений
uint8_t index; ///< Текущий индекс
uint8_t size; ///< Фактический размер фильтра
uint8_t dataProcessing; ///< Флаг - данные в обработке
@@ -402,6 +424,23 @@ typedef struct _FilterLUTInt_t{
int32_t (*process)(struct _FilterLUTInt_t *filter, int32_t input);
} FilterLUTInt_t;
/**
* @brief Структура True RMS фильтра (int32_t)
*/
typedef struct _FilterRMSInt_t {
FilterState_t state; ///< Состояние фильтра
int64_t buffer_sq[FILTER_RMS_MAX_SIZE]; ///< Буфер квадратов значений
int64_t sum_squares; ///< Текущая сумма квадратов
int32_t last_rms; ///< Последнее рассчитанное RMS значение
uint32_t window_size; ///< Размер окна усреднения
uint32_t index; ///< Текущий индекс в буфере
uint32_t count; ///< Количество накопленных значений
uint8_t dataProcessing; ///< Флаг - данные в обработке
int (*reset)(struct _FilterRMSInt_t *filter, uint32_t window_size);
int32_t (*process)(struct _FilterRMSInt_t *filter, int32_t input);
} FilterRMSInt_t;
// Int32_t версии функций
int FilterMedianInt_Init(FilterMedianInt_t* filter, uint8_t size, int32_t init_val);
int32_t FilterMedianInt_Process(FilterMedianInt_t* filter, int32_t input);
@@ -413,6 +452,8 @@ int FilterPolyInt_Init(FilterPolyInt_t* filter, int32_t* coeffs, uint8_t order,
int32_t FilterPolyInt_Process(FilterPolyInt_t* filter, int32_t input);
int FilterLUTInt_Init(FilterLUTInt_t* filter, int32_t* input_arr, int32_t* output_arr, uint16_t size, uint8_t interpolation);
int32_t FilterLUTInt_Process(FilterLUTInt_t* filter, int32_t input);
int FilterRMSInt_Init(FilterRMSInt_t* filter, uint32_t window_size);
int32_t FilterRMSInt_Process(FilterRMSInt_t* filter, int32_t input);