Workshop 2
LowpassFilter.h@0:86129f1b4a93, 2021-03-30 (annotated)
- Committer:
- pmic
- Date:
- Tue Mar 30 12:21:00 2021 +0000
- Revision:
- 0:86129f1b4a93
- Child:
- 4:9c003c402033
First commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 0:86129f1b4a93 | 1 | /* |
pmic | 0:86129f1b4a93 | 2 | * LowpassFilter.h |
pmic | 0:86129f1b4a93 | 3 | * Copyright (c) 2018, ZHAW |
pmic | 0:86129f1b4a93 | 4 | * All rights reserved. |
pmic | 0:86129f1b4a93 | 5 | */ |
pmic | 0:86129f1b4a93 | 6 | |
pmic | 0:86129f1b4a93 | 7 | #ifndef LOWPASS_FILTER_H_ |
pmic | 0:86129f1b4a93 | 8 | #define LOWPASS_FILTER_H_ |
pmic | 0:86129f1b4a93 | 9 | |
pmic | 0:86129f1b4a93 | 10 | #include <cstdlib> |
pmic | 0:86129f1b4a93 | 11 | |
pmic | 0:86129f1b4a93 | 12 | /** |
pmic | 0:86129f1b4a93 | 13 | * This class implements a time-discrete 2nd order lowpass filter for a series of data values. |
pmic | 0:86129f1b4a93 | 14 | * This filter can typically be used within a periodic task that takes measurements that need |
pmic | 0:86129f1b4a93 | 15 | * to be filtered, like speed or position values. |
pmic | 0:86129f1b4a93 | 16 | */ |
pmic | 0:86129f1b4a93 | 17 | class LowpassFilter { |
pmic | 0:86129f1b4a93 | 18 | |
pmic | 0:86129f1b4a93 | 19 | public: |
pmic | 0:86129f1b4a93 | 20 | |
pmic | 0:86129f1b4a93 | 21 | LowpassFilter(); |
pmic | 0:86129f1b4a93 | 22 | virtual ~LowpassFilter(); |
pmic | 0:86129f1b4a93 | 23 | void reset(); |
pmic | 0:86129f1b4a93 | 24 | void reset(float value); |
pmic | 0:86129f1b4a93 | 25 | void setPeriod(float period); |
pmic | 0:86129f1b4a93 | 26 | void setFrequency(float frequency); |
pmic | 0:86129f1b4a93 | 27 | float getFrequency(); |
pmic | 0:86129f1b4a93 | 28 | float filter(float value); |
pmic | 0:86129f1b4a93 | 29 | |
pmic | 0:86129f1b4a93 | 30 | private: |
pmic | 0:86129f1b4a93 | 31 | |
pmic | 0:86129f1b4a93 | 32 | float period; |
pmic | 0:86129f1b4a93 | 33 | float frequency; |
pmic | 0:86129f1b4a93 | 34 | float a11, a12, a21, a22, b1, b2; |
pmic | 0:86129f1b4a93 | 35 | float x1, x2; |
pmic | 0:86129f1b4a93 | 36 | }; |
pmic | 0:86129f1b4a93 | 37 | |
pmic | 0:86129f1b4a93 | 38 | #endif /* LOWPASS_FILTER_H_ */ |
pmic | 0:86129f1b4a93 | 39 | |
pmic | 0:86129f1b4a93 | 40 |