OpenCPN Partial API docs
Loading...
Searching...
No Matches
iir_filter.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 2016 Transmitterdan *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 *************************************************************************/
17
41#if !defined(IIRFILTER_CLASS_HEADER)
42#define IIRFILTER_CLASS_HEADER
43
44// Filter types
45enum {
46 IIRFILTER_TYPE_LINEAR = 1 << 0,
47 IIRFILTER_TYPE_DEG = 1 << 1,
48 IIRFILTER_TYPE_RAD = 1 << 2
49};
50
51class IirFilter {
52public:
53 // iirfilter() {setFC(0.5); type = IIRFILTER_TYPE_LINEAR; reset();};
54
55 IirFilter(double fc = 0.5, int tp = IIRFILTER_TYPE_LINEAR);
56 ~IirFilter() = default;
57 double Filter(double data); // Return filtered data given new data point
58 void reset(double a = 0.0); // Clear filter
59 void SetFc(double fc = 0.1); // Set cutoff frequency
60 void SetType(int tp); // Set type of filter (linear or angle type)
61 double GetFc() const; // Return cutoff frequency
62 int GetType() const; // Return type of filter
63 double get() const; // Return the current filtered data
64
65protected:
66 void UnwrapDeg(double deg);
67 void UnwrapRad(double rad);
68
69private:
70 double a0;
71 double b1;
72 double accum;
73 double oldDeg;
74 double oldRad;
75 int wraps;
76 int type;
77};
78
79#endif // IIRFILTER_CLASS_HEADER