DSP IIR filter

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Swabey89
Date:
Fri Nov 09 19:18:13 2018 +0000
Commit message:
Initial

Changed in this revision

filter_characteristics.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a994e937bae1 filter_characteristics.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filter_characteristics.h	Fri Nov 09 19:18:13 2018 +0000
@@ -0,0 +1,42 @@
+#define Fs      6000
+#define N       37
+
+float b[N]={
+-0.000000, 
+-0.000684, 
+0.001238, 
+-0.000000, 
+-0.003098, 
+0.004522, 
+-0.000000, 
+-0.008736, 
+0.011729, 
+-0.000000, 
+-0.020268, 
+0.026356, 
+-0.000000, 
+-0.045082, 
+0.060638, 
+-0.000000, 
+-0.133528, 
+0.273491,  
+0.666667, 
+0.273491, 
+-0.133528, 
+-0.000000, 
+0.060638, 
+-0.045082, 
+-0.000000, 
+0.026356, 
+-0.020268, 
+-0.000000, 
+0.011729, 
+-0.008736, 
+-0.000000, 
+0.004522, 
+-0.003098, 
+-0.000000, 
+0.001238, 
+-0.000684, 
+-0.000000
+};
diff -r 000000000000 -r a994e937bae1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 09 19:18:13 2018 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+
+//Add more to test different setups
+#include "filter_characteristics.h"
+
+
+#define ON      1
+#define OFF     0
+
+float x[N]={0};
+float yn;
+Timer t;
+
+void sampler(void);                     //Ticker routine PROTOTYPE
+
+//MBED Class Instances follows
+DigitalOut SampLED(LED1);               //Digital Output  (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate)
+DigitalOut testpin(PA_10);
+
+AnalogIn  Ain(PA_1);                    //Analog Input (Signal Input 0 to +3 Volts)
+AnalogOut Aout(PA_4);                   //Analog Output (Signal Input 0 to +3 Volts) NB PA_4 because Arduin Nano Compatability
+                                        //on STM32F303k8 uses I2C PA_5 to PB7
+
+Ticker sample_timer;                    //Ticker class instance called sample_timer
+
+PwmOut test(PWM_OUT);
+
+
+int main() {
+    float duty=0.1f;
+    test.period_ms(1);
+    test=duty;
+  
+    float sample_rate=(1.0/Fs)*1000000.0; //Calculate the number of uS required for a Frequency Sampling Rate
+                                          //Fs held in *.h
+  
+    sample_timer.attach_us(&sampler,(int)sample_rate);
+                                          //Ticker Instance serviced by routine at a repeat rate in microseconds
+  
+    while(1) {
+        sleep();
+    }
+}
+
+void sampler(void){                     //Ticker routine
+    SampLED = ON;                       //LED Indicates start of sampling
+    int i;                              //Initialise local variable i
+    testpin = 1;
+    x[0]=Ain;                           //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!!
+    yn=0.0;                             //output accumulation, start as zero
+    
+    
+    for(i=0; i<N; i++) yn+=x[i]*b[i];   //generate output from filter components FIR a=0
+    for(i=N-1; i!=0; i--) x[i]=x[i-1];  //shift data
+    
+    Aout=yn;                            //Output resultant to DAC. Again MBED uses 0.0 to 1.0 float!!!!!!
+    
+    testpin = 0;
+    
+    SampLED = OFF;                      //LED Indicates end of sampling
+    }
+
diff -r 000000000000 -r a994e937bae1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 09 19:18:13 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file