LinearCharacteristics.cpp@10:eb29810d831b, 2022-05-05 (annotated)
- Committer:
- pmic
- Date:
- Thu May 05 09:18:40 2022 +0000
- Revision:
- 10:eb29810d831b
- Parent:
- 5:75dc97c6c98e
Adjusted AvgFilter (damn...)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 5:75dc97c6c98e | 1 | #include "LinearCharacteristics.h" |
pmic | 5:75dc97c6c98e | 2 | |
pmic | 5:75dc97c6c98e | 3 | LinearCharacteristics::LinearCharacteristics(float gain, float offset) |
pmic | 5:75dc97c6c98e | 4 | { |
pmic | 5:75dc97c6c98e | 5 | setup(gain, offset); |
pmic | 5:75dc97c6c98e | 6 | } |
pmic | 5:75dc97c6c98e | 7 | |
pmic | 5:75dc97c6c98e | 8 | LinearCharacteristics::LinearCharacteristics(float x0, float x1, float y0, float y1) |
pmic | 5:75dc97c6c98e | 9 | { |
pmic | 5:75dc97c6c98e | 10 | setup(x0, x1, y0, y1); |
pmic | 5:75dc97c6c98e | 11 | } |
pmic | 5:75dc97c6c98e | 12 | |
pmic | 5:75dc97c6c98e | 13 | LinearCharacteristics::LinearCharacteristics(float x0, float x1, float y0, float y1, float yMin, float yMax) |
pmic | 5:75dc97c6c98e | 14 | { |
pmic | 5:75dc97c6c98e | 15 | setup(x0, x1, y0, y1, yMin, yMax); |
pmic | 5:75dc97c6c98e | 16 | } |
pmic | 5:75dc97c6c98e | 17 | |
pmic | 5:75dc97c6c98e | 18 | LinearCharacteristics::~LinearCharacteristics() {} |
pmic | 5:75dc97c6c98e | 19 | |
pmic | 5:75dc97c6c98e | 20 | float LinearCharacteristics::evaluate(float x) |
pmic | 5:75dc97c6c98e | 21 | { |
pmic | 5:75dc97c6c98e | 22 | float y = this->gain*(x - this->offset); |
pmic | 5:75dc97c6c98e | 23 | if(y > this->yMax) |
pmic | 5:75dc97c6c98e | 24 | y = this->yMax; |
pmic | 5:75dc97c6c98e | 25 | if(y < this->yMin) |
pmic | 5:75dc97c6c98e | 26 | y = this->yMin; |
pmic | 5:75dc97c6c98e | 27 | return y; |
pmic | 5:75dc97c6c98e | 28 | } |
pmic | 5:75dc97c6c98e | 29 | |
pmic | 5:75dc97c6c98e | 30 | void LinearCharacteristics::setup(float gain, float offset) |
pmic | 5:75dc97c6c98e | 31 | { |
pmic | 5:75dc97c6c98e | 32 | this->gain = gain; |
pmic | 5:75dc97c6c98e | 33 | this->offset = offset; |
pmic | 5:75dc97c6c98e | 34 | this->yMin = -999999.0; |
pmic | 5:75dc97c6c98e | 35 | this->yMax = 999999.0; |
pmic | 5:75dc97c6c98e | 36 | } |
pmic | 5:75dc97c6c98e | 37 | |
pmic | 5:75dc97c6c98e | 38 | void LinearCharacteristics::setup(float x0, float x1, float y0, float y1) |
pmic | 5:75dc97c6c98e | 39 | { |
pmic | 5:75dc97c6c98e | 40 | this->gain = (y1 - y0)/(x1 - x0); |
pmic | 5:75dc97c6c98e | 41 | this->offset = x1 - y1/this->gain; |
pmic | 5:75dc97c6c98e | 42 | this->yMin = -999999.0; |
pmic | 5:75dc97c6c98e | 43 | this->yMax = 999999.0; |
pmic | 5:75dc97c6c98e | 44 | } |
pmic | 5:75dc97c6c98e | 45 | |
pmic | 5:75dc97c6c98e | 46 | void LinearCharacteristics::setup(float x0,float x1, float y0, float y1, float yMin, float yMax) |
pmic | 5:75dc97c6c98e | 47 | { |
pmic | 5:75dc97c6c98e | 48 | this->gain = (y1 - y0)/(x1 - x0); |
pmic | 5:75dc97c6c98e | 49 | this->offset = x1 - y1/this->gain; |
pmic | 5:75dc97c6c98e | 50 | this->yMin = yMin; |
pmic | 5:75dc97c6c98e | 51 | this->yMax = yMax; |
pmic | 5:75dc97c6c98e | 52 | } |
pmic | 5:75dc97c6c98e | 53 | |
pmic | 5:75dc97c6c98e | 54 | void LinearCharacteristics::correctExistingOffset(float y_offset) |
pmic | 5:75dc97c6c98e | 55 | { |
pmic | 5:75dc97c6c98e | 56 | if(gain > 0.0) this->offset = this->offset + 1.0/(this->gain)*y_offset; |
pmic | 5:75dc97c6c98e | 57 | } |
pmic | 5:75dc97c6c98e | 58 |