Process consecutive values. Returns the central value of three consecutive values.
SpikeRemoveFilter.h@0:d8d565a9d473, 2020-04-20 (annotated)
- Committer:
- Chi7Shi
- Date:
- Mon Apr 20 15:28:40 2020 +0000
- Revision:
- 0:d8d565a9d473
- Child:
- 1:d34bcdec7177
First Commit 2020.4.21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Chi7Shi | 0:d8d565a9d473 | 1 | /* |
Chi7Shi | 0:d8d565a9d473 | 2 | * Copyright (c) 2017 Koichi Shibata |
Chi7Shi | 0:d8d565a9d473 | 3 | */ |
Chi7Shi | 0:d8d565a9d473 | 4 | |
Chi7Shi | 0:d8d565a9d473 | 5 | #ifndef SPIKE_REMOVE_FILTER_H |
Chi7Shi | 0:d8d565a9d473 | 6 | #define SPIKE_REMOVE_FILTER_H |
Chi7Shi | 0:d8d565a9d473 | 7 | |
Chi7Shi | 0:d8d565a9d473 | 8 | #include "mbed.h" |
Chi7Shi | 0:d8d565a9d473 | 9 | |
Chi7Shi | 0:d8d565a9d473 | 10 | template <class T> class SpikeRemoveFilter |
Chi7Shi | 0:d8d565a9d473 | 11 | { |
Chi7Shi | 0:d8d565a9d473 | 12 | protected: |
Chi7Shi | 0:d8d565a9d473 | 13 | |
Chi7Shi | 0:d8d565a9d473 | 14 | T x0; // latest data |
Chi7Shi | 0:d8d565a9d473 | 15 | T x1; |
Chi7Shi | 0:d8d565a9d473 | 16 | T x2; // oldest data |
Chi7Shi | 0:d8d565a9d473 | 17 | |
Chi7Shi | 0:d8d565a9d473 | 18 | public: |
Chi7Shi | 0:d8d565a9d473 | 19 | |
Chi7Shi | 0:d8d565a9d473 | 20 | // Constructor |
Chi7Shi | 0:d8d565a9d473 | 21 | SpikeRemoveFilter( void ); |
Chi7Shi | 0:d8d565a9d473 | 22 | |
Chi7Shi | 0:d8d565a9d473 | 23 | // Destructor |
Chi7Shi | 0:d8d565a9d473 | 24 | virtual ~SpikeRemoveFilter( void ); |
Chi7Shi | 0:d8d565a9d473 | 25 | |
Chi7Shi | 0:d8d565a9d473 | 26 | T process( T x ); |
Chi7Shi | 0:d8d565a9d473 | 27 | |
Chi7Shi | 0:d8d565a9d473 | 28 | }; |
Chi7Shi | 0:d8d565a9d473 | 29 | |
Chi7Shi | 0:d8d565a9d473 | 30 | // Constructor |
Chi7Shi | 0:d8d565a9d473 | 31 | template <class T> SpikeRemoveFilter<T>::SpikeRemoveFilter( void ) |
Chi7Shi | 0:d8d565a9d473 | 32 | { |
Chi7Shi | 0:d8d565a9d473 | 33 | } |
Chi7Shi | 0:d8d565a9d473 | 34 | |
Chi7Shi | 0:d8d565a9d473 | 35 | // Destructor |
Chi7Shi | 0:d8d565a9d473 | 36 | template <class T> SpikeRemoveFilter<T>::~SpikeRemoveFilter( void ) |
Chi7Shi | 0:d8d565a9d473 | 37 | { |
Chi7Shi | 0:d8d565a9d473 | 38 | } |
Chi7Shi | 0:d8d565a9d473 | 39 | |
Chi7Shi | 0:d8d565a9d473 | 40 | template <class T> T SpikeRemoveFilter<T>::process( T x ) |
Chi7Shi | 0:d8d565a9d473 | 41 | { |
Chi7Shi | 0:d8d565a9d473 | 42 | x2 = x1; |
Chi7Shi | 0:d8d565a9d473 | 43 | x1 = x0; |
Chi7Shi | 0:d8d565a9d473 | 44 | x0 = x; |
Chi7Shi | 0:d8d565a9d473 | 45 | if ( x1 < x2 ) { |
Chi7Shi | 0:d8d565a9d473 | 46 | if ( x0 < x1 ) { |
Chi7Shi | 0:d8d565a9d473 | 47 | return x1; |
Chi7Shi | 0:d8d565a9d473 | 48 | } else if ( x2 < x0 ) { |
Chi7Shi | 0:d8d565a9d473 | 49 | return x2; |
Chi7Shi | 0:d8d565a9d473 | 50 | } else { |
Chi7Shi | 0:d8d565a9d473 | 51 | return x0; |
Chi7Shi | 0:d8d565a9d473 | 52 | } |
Chi7Shi | 0:d8d565a9d473 | 53 | } else { // x2 <= x1 |
Chi7Shi | 0:d8d565a9d473 | 54 | if ( x0 < x2 ) { |
Chi7Shi | 0:d8d565a9d473 | 55 | return x2; |
Chi7Shi | 0:d8d565a9d473 | 56 | } else if ( x1 < x0 ) { |
Chi7Shi | 0:d8d565a9d473 | 57 | return x1; |
Chi7Shi | 0:d8d565a9d473 | 58 | } else { |
Chi7Shi | 0:d8d565a9d473 | 59 | return x0; |
Chi7Shi | 0:d8d565a9d473 | 60 | } |
Chi7Shi | 0:d8d565a9d473 | 61 | } |
Chi7Shi | 0:d8d565a9d473 | 62 | } |
Chi7Shi | 0:d8d565a9d473 | 63 | |
Chi7Shi | 0:d8d565a9d473 | 64 | #endif |
Chi7Shi | 0:d8d565a9d473 | 65 |