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 mbed-dsp mbed
Fork of Project5-filtering2 by
Revision 30:2162f7a82fc7, committed 2014-10-20
- Comitter:
- DominiqueC
- Date:
- Mon Oct 20 07:47:41 2014 +0000
- Parent:
- 29:40a157c53841
- Commit message:
- median
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 17 18:18:23 2014 +0000
+++ b/main.cpp Mon Oct 20 07:47:41 2014 +0000
@@ -54,29 +54,42 @@
arm_biquad_cascade_df1_f32(&lowpass, &filtered_emg_notch_highpass, &filtered_emg_notch_highpass_lowpass, 1 );
filtered_emg_eindsignaal_abs = 10*fabs(filtered_emg_notch_highpass_lowpass); //gelijkrichter
- //Movag berekenen
-
- float mean(float *60, int n) {
- float sum = 0.0;
- for (int i=0; i<n; i++) {
- sum += samples[i];
- }
- return sum / (float)n;
-}
+ //(Movag) Median berekenen
- //of
- typdef struct
+ int compare (const void * a, const void * b)
{
- int32_t prev;
- uint16_t gain;
-}IIR_Filter_Data;
-
-int16_t IIR_Filter(int16_t input, IIR_Filter_Data* Fdata)
-{
- Fdata->prev += input * Fdata->gain;
-
- return (Fdata->prev >> 16);
+ return ( *(int*)a - *(int*)b );
}
+
+int main() {
+
+ float samples[5]={};
+ float med[5]={};
+ int count = 0;
+ float sensval;
+ while(1)
+ {
+ count += 1;
+ sensval = input;
+ med[4] = med[3];
+ med[3] = med[2];
+ med[2] = med[1];
+ med[1] = med[0];
+ med[0] = sensval;
+
+ samples[4] = med[4];
+ samples[3] = med[3];
+ samples[2] = med[2];
+ samples[1] = med[1];
+ samples[0] = med[0];
+
+ qsort (samples, 5, sizeof(int), compare);
+
+ // show the averages
+ pc.printf("\n%i %f %f",count,sensval,samples[2]);
+ }
+}
+ //eind
scope.set(0,emg_value_f32);
scope.set(1,filtered_emg_notch);
