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: HIDScope biquadFilter mbed
Diff: main.cpp
- Revision:
- 4:4ca76ebca1d1
- Parent:
- 3:5fe9ccd93f82
- Child:
- 5:7f6d142e633a
--- a/main.cpp Mon Sep 28 11:28:33 2015 +0000
+++ b/main.cpp Mon Sep 28 15:11:30 2015 +0000
@@ -42,8 +42,8 @@
InterruptIn cali_button(PTA4); // initialize interrupt button for calibration stuff
double cali_fact = 8; // calibration factor to normalize filter output to a scale of 0 - 1
-double cali_array[5120] = {}; // array to store values in
-double cali_array2[3072] = {}; // reduced array size, by getting rid of the first/last 2 seconds.
+double cali_array[2560] = {}; // array to store values in
+
void sample_filter()
{
@@ -58,24 +58,21 @@
sample_go = 1;
}
-void calibrate() // function to calibrate the emg signals from the user. It takes 10 seconds of measurements of maximum output, then takes the average and normalizes to that.
+void calibrate() // function to calibrate the emg signals from the user. It takes 5 seconds of measurements of maximum output, then takes the max and normalizes to that.
{
- double cali_mean = 0; // declare mean
- for(int cali_index = 0; cali_index < 5120; cali_index++)
+ double cali_max = 0; // declare max
+ for(int cali_index = 0; cali_index < 2560; cali_index++)
{
sample_filter;
cali_array[cali_index] = y1;
wait((float)1/Fs);
}
- for(int cali_index2 = 1023; cali_index2 < 4096; cali_index2++) // taking for loop to get rid of first/last 2 seconds
- {
- cali_array2[cali_index2 - 1023] = cali_array[cali_index2];
- }
- for(int cali_index3 = 0; cali_index3 < 3072; cali_index3++)
- {
- cali_mean += cali_array2[cali_index3];
- }
- cali_fact = 3072.0 / cali_mean; // taking the reciprocal of the average and setting it equal to the calibration factor
+ for(int cali_index2 = 0; cali_index2<2560; cali_index2++)
+ {
+ if(cali_array[cali_index2] > cali_max)
+ cali_max = cali_array[cali_index2];
+ }
+ cali_fact = (double)1/cali_max;
}
int main()