Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Biquad_multiChan.h@0:675506e540be, 2015-03-23 (annotated)
- Committer:
- biomurph
- Date:
- Mon Mar 23 19:22:04 2015 +0000
- Revision:
- 0:675506e540be
Publishing this old ADS1299 code for the first time!
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| biomurph | 0:675506e540be | 1 | // |
| biomurph | 0:675506e540be | 2 | // Biquad_multiChan.h |
| biomurph | 0:675506e540be | 3 | // |
| biomurph | 0:675506e540be | 4 | // Created by Nigel Redmon on 11/24/12 |
| biomurph | 0:675506e540be | 5 | // EarLevel Engineering: earlevel.com |
| biomurph | 0:675506e540be | 6 | // Copyright 2012 Nigel Redmon |
| biomurph | 0:675506e540be | 7 | // |
| biomurph | 0:675506e540be | 8 | // For a complete explanation of the Biquad code: |
| biomurph | 0:675506e540be | 9 | // http://www.earlevel.com/main/2012/11/25/biquad-c-source-code/ |
| biomurph | 0:675506e540be | 10 | // |
| biomurph | 0:675506e540be | 11 | // License: |
| biomurph | 0:675506e540be | 12 | // |
| biomurph | 0:675506e540be | 13 | // This source code is provided as is, without warranty. |
| biomurph | 0:675506e540be | 14 | // You may copy and distribute verbatim copies of this document. |
| biomurph | 0:675506e540be | 15 | // You may modify and use this source code to create binary code |
| biomurph | 0:675506e540be | 16 | // for your own purposes, free or commercial. |
| biomurph | 0:675506e540be | 17 | // |
| biomurph | 0:675506e540be | 18 | // Extended by Chip Audette (Nov 2013) to handle multiple channels of data |
| biomurph | 0:675506e540be | 19 | // that are being filtered by the same coefficients |
| biomurph | 0:675506e540be | 20 | // |
| biomurph | 0:675506e540be | 21 | |
| biomurph | 0:675506e540be | 22 | #ifndef Biquad_multiChan_h |
| biomurph | 0:675506e540be | 23 | #define Biquad_multiChan_h |
| biomurph | 0:675506e540be | 24 | |
| biomurph | 0:675506e540be | 25 | enum { |
| biomurph | 0:675506e540be | 26 | bq_type_lowpass = 0, |
| biomurph | 0:675506e540be | 27 | bq_type_highpass, |
| biomurph | 0:675506e540be | 28 | bq_type_bandpass, |
| biomurph | 0:675506e540be | 29 | bq_type_notch, |
| biomurph | 0:675506e540be | 30 | bq_type_peak, |
| biomurph | 0:675506e540be | 31 | bq_type_lowshelf, |
| biomurph | 0:675506e540be | 32 | bq_type_highshelf |
| biomurph | 0:675506e540be | 33 | }; |
| biomurph | 0:675506e540be | 34 | |
| biomurph | 0:675506e540be | 35 | class Biquad_multiChan { |
| biomurph | 0:675506e540be | 36 | public: |
| biomurph | 0:675506e540be | 37 | //Biquad_multiChan(); |
| biomurph | 0:675506e540be | 38 | Biquad_multiChan(int Nchan, int type, double Fc, double Q, double peakGainDB); |
| biomurph | 0:675506e540be | 39 | ~Biquad_multiChan(); |
| biomurph | 0:675506e540be | 40 | void setType(int type); |
| biomurph | 0:675506e540be | 41 | void setQ(double Q); |
| biomurph | 0:675506e540be | 42 | void setFc(double Fc); |
| biomurph | 0:675506e540be | 43 | void setPeakGain(double peakGainDB); |
| biomurph | 0:675506e540be | 44 | void setBiquad(int type, double Fc, double Q, double peakGain); |
| biomurph | 0:675506e540be | 45 | float process(float in,int Ichan); |
| biomurph | 0:675506e540be | 46 | |
| biomurph | 0:675506e540be | 47 | protected: |
| biomurph | 0:675506e540be | 48 | void calcBiquad(void); |
| biomurph | 0:675506e540be | 49 | |
| biomurph | 0:675506e540be | 50 | int Nchan; |
| biomurph | 0:675506e540be | 51 | int type; |
| biomurph | 0:675506e540be | 52 | double a0, a1, a2, b1, b2; |
| biomurph | 0:675506e540be | 53 | double Fc, Q, peakGain; |
| biomurph | 0:675506e540be | 54 | double *z1, *z2; |
| biomurph | 0:675506e540be | 55 | }; |
| biomurph | 0:675506e540be | 56 | |
| biomurph | 0:675506e540be | 57 | inline float Biquad_multiChan::process(float in,int Ichan) { |
| biomurph | 0:675506e540be | 58 | double out = in * a0 + z1[Ichan]; |
| biomurph | 0:675506e540be | 59 | z1[Ichan] = in * a1 + z2[Ichan] - b1 * out; |
| biomurph | 0:675506e540be | 60 | z2[Ichan] = in * a2 - b2 * out; |
| biomurph | 0:675506e540be | 61 | return out; |
| biomurph | 0:675506e540be | 62 | } |
| biomurph | 0:675506e540be | 63 | |
| biomurph | 0:675506e540be | 64 | #endif // Biquad_multiChan_h |