by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Sun Jun 16 15:18:39 2013 +0000
Revision:
0:1c941e8eb861
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:1c941e8eb861 1 /*Program Example 11.2 Low pass filter function
robt 0:1c941e8eb861 2 */
robt 0:1c941e8eb861 3 float LPF(float LPF_in){
robt 0:1c941e8eb861 4
robt 0:1c941e8eb861 5 float a[4]={1,2.6235518066,-2.3146825811,0.6855359773};
robt 0:1c941e8eb861 6 float b[4]={0.0006993496,0.0020980489,0.0020980489,0.0006993496};
robt 0:1c941e8eb861 7 static float LPF_out;
robt 0:1c941e8eb861 8 static float x[4], y[4];
robt 0:1c941e8eb861 9
robt 0:1c941e8eb861 10 x[3] = x[2]; x[2] = x[1]; x[1] = x[0]; //move x values by one sample
robt 0:1c941e8eb861 11 y[3] = y[2]; y[2] = y[1]; y[1] = y[0]; //move y values by one sample
robt 0:1c941e8eb861 12
robt 0:1c941e8eb861 13 x[0] = LPF_in; // new value for x[0]
robt 0:1c941e8eb861 14 y[0] = (b[0]*x[0]) + (b[1]*x[1]) + (b[2]*x[2]) + (b[3]*x[3])
robt 0:1c941e8eb861 15 + (a[1]*y[1]) + (a[2]*y[2]) + (a[3]*y[3]);
robt 0:1c941e8eb861 16
robt 0:1c941e8eb861 17 LPF_out = y[0];
robt 0:1c941e8eb861 18 return LPF_out; // output filtered value
robt 0:1c941e8eb861 19 }
robt 0:1c941e8eb861 20