Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H |
| 18 | #define ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | |
| 25 | namespace android { |
| 26 | // --------------------------------------------------------------------------- |
| 27 | |
| 28 | class BiquadFilter; |
| 29 | |
| 30 | /* |
| 31 | * State of a 2nd order low-pass IIR filter |
| 32 | */ |
| 33 | class SecondOrderLowPassFilter { |
| 34 | friend class BiquadFilter; |
| 35 | float iQ, fc; |
| 36 | float K, iD; |
| 37 | float a0, a1; |
| 38 | float b1, b2; |
| 39 | public: |
| 40 | SecondOrderLowPassFilter(float Q, float fc); |
| 41 | void setSamplingPeriod(float dT); |
| 42 | }; |
| 43 | |
| 44 | /* |
| 45 | * Implements a Biquad IIR filter |
| 46 | */ |
| 47 | class BiquadFilter { |
| 48 | float x1, x2; |
| 49 | float y1, y2; |
| 50 | const SecondOrderLowPassFilter& s; |
| 51 | public: |
| 52 | BiquadFilter(const SecondOrderLowPassFilter& s); |
| 53 | float init(float in); |
| 54 | float operator()(float in); |
| 55 | }; |
| 56 | |
Mathias Agopian | 6038db3 | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 57 | /* |
| 58 | * Two cascaded biquad IIR filters |
| 59 | * (4-poles IIR) |
| 60 | */ |
| 61 | class CascadedBiquadFilter { |
| 62 | BiquadFilter mA; |
| 63 | BiquadFilter mB; |
| 64 | public: |
| 65 | CascadedBiquadFilter(const SecondOrderLowPassFilter& s); |
| 66 | float init(float in); |
| 67 | float operator()(float in); |
| 68 | }; |
Mathias Agopian | 671a6ff | 2010-11-11 17:58:51 -0800 | [diff] [blame] | 69 | |
| 70 | // --------------------------------------------------------------------------- |
| 71 | }; // namespace android |
| 72 | |
| 73 | #endif // ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H |