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 modular_signal_processing by
Diff: main.cpp
- Revision:
- 6:9c5c36d2c0e1
- Parent:
- 5:bbfcd046cd43
- Child:
- 7:cc766c97686a
--- a/main.cpp Thu Feb 15 22:04:22 2018 +0000
+++ b/main.cpp Fri Feb 16 15:57:50 2018 +0000
@@ -1,5 +1,8 @@
#include "mbed.h"
+//Testing
+Serial pc (USBTX, USBRX);
+
DigitalOut pulse(LED1);
AnalogIn Ain(PTB1);
AnalogOut Aout(PTE30);
@@ -11,10 +14,10 @@
//Constants
int const AVG_LEN = 160; //Lenght of Avg length buffer
int const BUFF_LEN = 20; //Length of sample buffer
-int const ALPHA = 0.5; //Aplha value used for filtering
-int const OFFSET = 0.2; //Used to ensure normalised values don't be come negative
-float const trigger_high = 0.8;
-float const trigger_low = 0.6;
+float const ALPHA = 0.5; //Aplha value used for filtering
+float const OFFSET = 0.2; //Used to ensure normalised values don't be come negative
+float const trigger_high = 0.21;
+float const trigger_low = 0.19;
//Buffers
float sample_buffer[BUFF_LEN] = {}; //Circular array storing values from sample interupt
@@ -102,33 +105,17 @@
return 0.0;
} else { //Main runtime of program
- int old_data = avg_buffer[avg_write]; // oldest value
+ float old_data = avg_buffer[avg_write]; // oldest value
avg_buffer[avg_write] = data; // over write oldest value with new data
avg_sum = avg_sum - old_data + data; //Update running sum to contain most recent 160 values
avg_write = avg_write%AVG_LEN; //Ensure avg_write wraps around
- if (avg_write == 1) { //160 new values have been added to buffer
-
- //Get reinitalise min and max
- max = initialMax();
- min = initialMin();
- }
-
-
- //Otherwise Check if new data sets new max
- else if (data > max) {
- max = data;
- }
-
- //Or check if new data sets new max
- else if (data < min) {
- min = data;
-
-
- }
-
- return data - avg_sum/AVG_LEN + OFFSET; //Remove trendline
+ max = initialMax();
+ min = initialMin();
+ float trendedData = data - (avg_sum/AVG_LEN);
+ float offsetData = trendedData+OFFSET;
+ return offsetData; //Remove trendline
}
}
@@ -137,8 +124,10 @@
float processing, processed;
processing = average(data); //Remove runnning average
processing = filter(processing, normalisedData); //Low pass filter signal
- processed = normalise(processing); //Normalise as per formula
- return processed;
+ pc.printf("%f \n \r", processing);
+ Aout.write(processing);
+ //processed = normalise(processing); //Normalise as per formula
+ return processing;
}
bool below_trig_low(float point) //Check if data goes below low trigger
@@ -185,14 +174,13 @@
while(1) {
if(dataReady) { //If more data has been sampled
-
//int local_write = write //Store local pointer for write pointer
while(read != write) { //While there is data left in sample buffer
- int data = sample_buffer[read++] ;
+ float data = sample_buffer[read++] ;
read = read%BUFF_LEN; //Ensure read pointer rolls around in sample buffer
normalisedData = processData(data, normalisedData);
-
+
if(intialised) { //Passed first two pulse
detectPulse(normalisedData);
}

