Biquad filter library in C++ template form. On mbed LPC1768, can run about 100K operations per second with double precision float, or about 200K with single precision float.
Diff: biquad.h
- Revision:
- 3:abd20f34fd68
- Parent:
- 2:9a9b643fcc66
--- a/biquad.h Wed Feb 15 18:12:50 2012 +0000 +++ b/biquad.h Thu Feb 16 00:07:57 2012 +0000 @@ -1,8 +1,9 @@ /* * biquad.h * - * Original source material from Robert Bristow Johnson at + * Original source material from Robert Bristow-Johnson at * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt + * and Nigel Redmon at http://www.earlevel.com/ * * Derived from public domain C implementation by Tom St. Denis * @@ -25,6 +26,12 @@ #define M_PI 3.14159265358979323846 #endif +/* formulation types */ +typedef enum { + DIRECT_FORM_I = 0, + TRANSPOSED_DIRECT_FORM_II +} BIQUAD_FORMULATION_TYPE; + /* filter types */ typedef enum { LPF, /* low pass filter */ @@ -41,17 +48,29 @@ public: Biquad(BIQUAD_FILTER_TYPE type, - T dbGain, /* gain of filter */ + T dbGain, /* peak gain of filter */ T freq, /* center frequency */ T srate, /* sampling rate */ - T bandwidth); /* bandwidth in octaves */ + T Q, /* Q */ + BIQUAD_FORMULATION_TYPE form = DIRECT_FORM_I); - void Reset(BIQUAD_FILTER_TYPE type, T dbGain, T freq, T srate, T bandwidth, bool clearHistory = false); + void Reset(BIQUAD_FILTER_TYPE type, T dbGain, T freq, T srate, T Q, bool clearHistory = false, BIQUAD_FORMULATION_TYPE form = DIRECT_FORM_I); + + void CalcCoefficientsDirectI(BIQUAD_FILTER_TYPE type, T dbGain, T freq, T srate, T Q); + + void CalcCoefficientsTransposedDirectII(BIQUAD_FILTER_TYPE type, T dbGain, T freq, T srate, T Q); T Calculate(T sample); - T a0, a1, a2, a3, a4; + BIQUAD_FORMULATION_TYPE form; + + // used for DIRECT_FORM_1 + T a0_I, a1_I, a2_I, a3_I, a4_I; T x1, x2, y1, y2; + + // used for TRANSPOSED_DIRECT_FORM_II + T a0_II, a1_II, a2_II, b1_II, b2_II; + T z1, z2; };