ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MaxFilter.h
Go to the documentation of this file.
1/**
2 * @file MaxFilter.h
3 * @brief Implements a moving maximum filter for processing data streams.
4 *
5 * The `MaxFilter` maintains a window of the largest values over a specified
6 * memory range. It can be used to smooth data while capturing peak values.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Math/Mathematics.h"
16
17/**
18 * @class MaxFilter
19 * @brief Implements a maximum filter over a sliding window.
20 *
21 * This class filters input data by maintaining a history of maximum values
22 * over a specified memory window. It is particularly useful for detecting
23 * and tracking peak values in data streams.
24 *
25 * @tparam memory The size of the memory window for tracking maximum values.
26 */
27template<size_t memory>
28class MaxFilter {
29private:
30 const int maxMemory = static_cast<int>(std::ceil(memory / 10.0)); ///< Number of memory blocks for peak tracking.
31 float values[memory]; ///< Circular buffer of values.
32 float maxValues[memory / 10]; ///< Array of maximum values in each block.
33 uint8_t currentAmount = 0; ///< Number of values currently stored in the buffer.
34
35 /**
36 * @brief Shifts the values in the specified array to make room for a new value.
37 *
38 * @param mem The size of the array.
39 * @param arr The array to shift.
40 */
41 void ShiftArray(uint8_t mem, float* arr);
42
43public:
44 /**
45 * @brief Constructs a `MaxFilter` with the specified memory size.
46 */
48
49 /**
50 * @brief Filters the given value, updating the maximum value within the memory window.
51 *
52 * @param value The input value to filter.
53 * @return The maximum value within the memory window after updating with the new value.
54 */
55 float Filter(float value);
56};
57
58#include "MaxFilter.tpp" // Includes the implementation of the template class.
Implements a maximum filter over a sliding window.
Definition MaxFilter.h:28
uint8_t currentAmount
Number of values currently stored in the buffer.
Definition MaxFilter.h:33
void ShiftArray(uint8_t mem, float *arr)
Shifts the values in the specified array to make room for a new value.
MaxFilter()
Constructs a MaxFilter with the specified memory size.
float values[memory]
Circular buffer of values.
Definition MaxFilter.h:31
float Filter(float value)
Filters the given value, updating the maximum value within the memory window.
const int maxMemory
Number of memory blocks for peak tracking.
Definition MaxFilter.h:30
float maxValues[memory/10]
Array of maximum values in each block.
Definition MaxFilter.h:32