dsplib 1.1.0
C++ DSP library for MATLAB-like coding
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dsplib::MAFilter< T > Class Template Reference

Moving Average Filter implementation using binary tree summation. More...

#include <ma-filter.h>

Public Member Functions

 MAFilter (int len)
 Construct a MAFilter with specified window length.
 
 MAFilter (int len, const base_array< T > &init)
 Construct a MAFilter with initial state.
 
process (const T &in) noexcept
 Process single input sample.
 
base_array< T > process (span_t< T > in) noexcept
 Process array of input samples.
 
operator() (const T &x) noexcept
 Process single input sample (operator form)
 
base_array< T > operator() (span_t< T > x) noexcept
 Process array of input samples (operator form)
 

Detailed Description

template<typename T>
class dsplib::MAFilter< T >

Moving Average Filter implementation using binary tree summation.

Template Parameters
TData type for filter processing (real_t or cmplx_t recommended)

This class implements a computationally efficient moving average (MA) filter using a binary tree structure for O(log N) per-sample processing complexity.

Key features:

The filter computes the average over a sliding window of length N:

\[ y[n] = \frac{1}{N} \sum_{k=0}^{N-1} x[n - k] \]

See also
MAFilterR, MAFilterC

Constructor & Destructor Documentation

◆ MAFilter() [1/2]

template<typename T >
dsplib::MAFilter< T >::MAFilter ( int  len)
inlineexplicit

Construct a MAFilter with specified window length.

Parameters
lenWindow length (number of samples in moving average)
Precondition
len >= 1
Exceptions
DSPLIB_ASSERTThrows if len < 1

Initializes all filter states to zero.

◆ MAFilter() [2/2]

template<typename T >
dsplib::MAFilter< T >::MAFilter ( int  len,
const base_array< T > &  init 
)
inlineexplicit

Construct a MAFilter with initial state.

Parameters
lenWindow length
initInitial window values
Precondition
init.size() == len
Exceptions
DSPLIB_ASSERTThrows if init size doesn't match window length

Initializes the filter with predefined window values. Equivalent to:

  • Constructing with length
  • Processing init array through filter

Member Function Documentation

◆ operator()() [1/2]

template<typename T >
T dsplib::MAFilter< T >::operator() ( const T &  x)
inlinenoexcept

Process single input sample (operator form)

Parameters
xInput sample
Returns
Filtered output
See also
process()

◆ operator()() [2/2]

template<typename T >
base_array< T > dsplib::MAFilter< T >::operator() ( span_t< T >  x)
inlinenoexcept

Process array of input samples (operator form)

Parameters
xInput array
Returns
Output array
See also
process()

◆ process() [1/2]

template<typename T >
T dsplib::MAFilter< T >::process ( const T &  in)
inlinenoexcept

Process single input sample.

Parameters
inInput sample
Returns
Filtered output (average of current window)

Computational complexity: O(log N)

◆ process() [2/2]

template<typename T >
base_array< T > dsplib::MAFilter< T >::process ( span_t< T >  in)
inlinenoexcept

Process array of input samples.

Parameters
inInput array
Returns
Output array of filtered samples

Equivalent to sequential processing of each sample. For better performance on large arrays, consider block processing optimization.


The documentation for this class was generated from the following file: