Calibration routines adapted

* Implement custom mean and std functions
* Use standard deviation in calibration measurment instead of peak-peak noise.
This commit is contained in:
Mario Hüttel 2020-11-01 20:55:57 +01:00
parent 7aa0b62012
commit 1166477a6c

View File

@ -75,6 +75,71 @@ free_mem:
return NULL;
}
static float calculate_mean(float *values, uint32_t count)
{
uint32_t loop_cnt = (count + 7) / 8;
uint32_t remainder = count % 8;
float sum = 0;
switch (remainder) {
case 0: do { sum += *values++; /* FALLTHRU */
case 7: sum += *values++; /* FALLTHRU */
case 6: sum += *values++; /* FALLTHRU */
case 5: sum += *values++; /* FALLTHRU */
case 4: sum += *values++; /* FALLTHRU */
case 3: sum += *values++; /* FALLTHRU */
case 2: sum += *values++; /* FALLTHRU */
case 1: sum += *values++;
} while (--loop_cnt > 0);
}
return sum/(float)count;
}
static float calculate_standard_deviation(float *values, uint32_t count, float mean)
{
uint32_t loop_cnt = (count + 7) / 8;
uint32_t remainder = count % 8;
float sum = 0;
float res;
switch (remainder) {
case 0: do { sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 7: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 6: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 5: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 4: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 3: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 2: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
case 1: sum += (*values - mean) * (*values - mean);
values++;
/* FALLTHRU */
} while (--loop_cnt > 0);
}
sum /= (float)count;
/* Compute the square roor using the FPU.
* The constraint 't' tells GCC to use a floating point register
*/
__asm__ __volatile__("vsqrt.f32 %0, %1" : "=t"(res) : "t"(sum));
return res;
}
static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, volatile int *flag, float *mu, float *max_dev)
{
int ret_val = 0;
@ -99,10 +164,9 @@ static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, v
/* Convert the stream memory to Ohm readings */
adc_pt1000_convert_raw_value_array_to_resistance(NULL, mem_array, count);
/* Do not compute std-deviation. Too imprecise
* arm_std_f32(stream_mem, count, sigma);
*/
arm_mean_f32(mem_array, count, mu);
/* Do not compute std-deviation. Too imprecise */
*mu = calculate_mean(mem_array, count);
*max_dev = calculate_standard_deviation(mem_array, count, *mu);
/* Find min and max values of array */
for (i = 0U; i < count; i++) {
@ -111,7 +175,7 @@ static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, v
}
/* Compute maximum deviation range */
*max_dev = max_val - min_val;
//*max_dev = max_val - min_val;
ret_free_mem:
free(mem_array);