ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RunningAverageFilter.h
Go to the documentation of this file.
1/**
2 * @file RunningAverageFilter.h
3 * @brief Implements a running average filter for smoothing data.
4 *
5 * The `RunningAverageFilter` class uses a specified memory size to smooth
6 * incoming data values over time, providing a low-pass filtering effect.
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 RunningAverageFilter
19 * @brief Smooths data values using a weighted running average.
20 *
21 * The `RunningAverageFilter` class calculates a running average based on
22 * a fixed memory size, applying a gain to control the influence of new values.
23 *
24 * @tparam memory The size of the memory buffer for storing recent values.
25 */
26template <size_t memory>
28private:
29 float gain; ///< The gain factor for the filter, controlling smoothing intensity.
30 float values[memory]; ///< Buffer to store the recent values.
31 uint8_t currentAmount; ///< The current number of valid entries in the buffer.
32
33public:
34 /**
35 * @brief Default constructor for `RunningAverageFilter`.
36 *
37 * Initializes the filter with default parameters and a memory buffer of zeros.
38 */
40
41 /**
42 * @brief Constructs a `RunningAverageFilter` with a specified gain.
43 *
44 * @param gain The gain factor for the filter (typically between 0.0 and 1.0).
45 */
47
48 /**
49 * @brief Sets the gain for the filter.
50 *
51 * @param gain The new gain value, controlling smoothing intensity.
52 */
53 void SetGain(float gain);
54
55 /**
56 * @brief Filters the input value using the running average.
57 *
58 * Calculates the smoothed output based on the memory buffer and gain.
59 *
60 * @param value The new input value to filter.
61 * @return The filtered output value.
62 */
63 float Filter(float value);
64};
65
Smooths data values using a weighted running average.
uint8_t currentAmount
The current number of valid entries in the buffer.
RunningAverageFilter()
Default constructor for RunningAverageFilter.
RunningAverageFilter(float gain)
Constructs a RunningAverageFilter with a specified gain.
float values[memory]
Buffer to store the recent values.
float Filter(float value)
Filters the input value using the running average.
float gain
The gain factor for the filter, controlling smoothing intensity.
void SetGain(float gain)
Sets the gain for the filter.