22 #ifndef EDSP_FILTER_MOVING_AVERAGE_FILTER_H 23 #define EDSP_FILTER_MOVING_AVERAGE_FILTER_H 27 namespace edsp {
namespace filter {
47 template <
typename T,
typename Allocator = std::allocator<T>>
84 template <
typename InputIt,
typename OutputIt>
85 void filter(InputIt first, InputIt last, OutputIt d_first);
94 edsp::ring_buffer<T, Allocator> window_;
98 template <
typename T,
typename Allocator>
101 template <
typename T,
typename Allocator>
103 return window_.capacity();
106 template <
typename T,
typename Allocator>
111 template <
typename T,
typename Allocator>
112 template <
typename InputIt,
typename OutputIt>
114 if (window_.full()) {
115 for (; first != last; ++d_first, ++first) {
116 accumulated_ -= window_.front();
117 accumulated_ += *first;
118 window_.push_back(*first);
119 *d_first = accumulated_ /
static_cast<T
>(window_.size());
122 for (; first != last; ++d_first, ++first) {
123 accumulated_ += *first;
124 window_.push_back(*first);
125 *d_first = accumulated_ /
static_cast<T
>(window_.size());
130 template <
typename T,
typename Allocator>
135 template<
typename T,
typename Allocator>
137 if (window_.full()) {
138 accumulated_ -= window_.front();
139 accumulated_ += tick;
140 window_.push_back(tick);
142 accumulated_ += tick;
143 window_.push_back(tick);
145 return accumulated_ /
static_cast<T
>(window_.size());
150 #endif // EDSP_FILTER_MOVING_AVERAGE_FILTER_H void resize(size_type N)
Resizes the moving window to the specified number of elements.
Definition: moving_average_filter.hpp:131
T value_type
Definition: moving_average_filter.hpp:51
value_type tick(value_type tick)
Applies a moving average filter to the single element.
Definition: moving_average_filter.hpp:136
void reset()
Reset the moving window to the original state.
Definition: moving_average_filter.hpp:107
void filter(InputIt first, InputIt last, OutputIt d_first)
Applies a moving average filter to the elements in the range [first, last) and stores the result in a...
Definition: moving_average_filter.hpp:113
std::size_t size_type
Definition: moving_average_filter.hpp:50
logger & reset(logger &stream)
Resets the logger to default configuration.
Definition: logger.hpp:416
moving_average(size_type N)
Creates a moving_average with a window of length N.
Definition: moving_average_filter.hpp:99
size_type size() const
Returns the size of the moving window.
Definition: moving_average_filter.hpp:102
This class implement a cumulative moving average (rolling average or running average) filter...
Definition: moving_average_filter.hpp:48
Definition: amplifier.hpp:29