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.
Dependencies: mbed
Fork of PE_11-01_DSPInOut by
Revision 1:92e81744d2f8, committed 2014-12-12
- Comitter:
- Richard37
- Date:
- Fri Dec 12 12:43:12 2014 +0000
- Parent:
- 0:9ba494009efb
- Commit message:
- Low Pass Filter from Toulson
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPF.cpp Fri Dec 12 12:43:12 2014 +0000
@@ -0,0 +1,19 @@
+/*Program Example 11.2 Low pass filter function
+ */
+float LPF(float LPF_in){
+
+ float a[4]={1,2.6235518066,-2.3146825811,0.6855359773};
+ float b[4]={0.0006993496,0.0020980489,0.0020980489,0.0006993496};
+ static float LPF_out;
+ static float x[4], y[4];
+
+ x[3] = x[2]; x[2] = x[1]; x[1] = x[0]; //move x values by one sample
+ y[3] = y[2]; y[2] = y[1]; y[1] = y[0]; //move y values by one sample
+
+ x[0] = LPF_in; // new value for x[0]
+ y[0] = (b[0]*x[0]) + (b[1]*x[1]) + (b[2]*x[2]) + (b[3]*x[3])
+ + (a[1]*y[1]) + (a[2]*y[2]) + (a[3]*y[3]);
+
+ LPF_out = y[0];
+ return LPF_out; // output filtered value
+}
\ No newline at end of file
--- a/main.cpp Sun Jun 16 15:18:06 2013 +0000
+++ b/main.cpp Fri Dec 12 12:43:12 2014 +0000
@@ -1,25 +1,31 @@
-/* Program Example 11.1 DSP input and Output
+/* Program Example 11.2 DSP input and Output
+ IIR Filter from Toulson and Wilmhurst
*/
#include "mbed.h"
//mbed objects
-AnalogIn Ain(p15);
-AnalogOut Aout(p18);
+DigitalOut myled(LED1);
+AnalogIn Ain(A0);
+AnalogOut Aout(PA_4);
Ticker s20khz_tick;
//function prototypes
void s20khz_task(void);
+float LPF(float);
+
//variables and data
float data_in, data_out;
//main program start here
int main() {
- s20khz_tick.attach_us(&s20khz_task,50); //attach task to 50us tick
+ myled=1;
+ s20khz_tick.attach_us(&s20khz_task,100); //attach task to 1000us tick
}
// function 20khz_task
void s20khz_task(void){
data_in=Ain;
- data_out=data_in;
+ data_out=LPF(data_in);
Aout=data_out;
+ //myled=!myled;
}
--- a/mbed.bld Sun Jun 16 15:18:06 2013 +0000 +++ b/mbed.bld Fri Dec 12 12:43:12 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
