ac_result_t ac_add_frame(jb_frame_t *frame){ euclidean3_t tmp; float result; if(ac.frame_count){ // This isn't the first frame... euclidean3_copy(&frame->acc, &tmp); euclidean3_sub(&tmp, &ac.last, &tmp); ac.activity_per_frame[ac.frame_count - 1] = euclidean3_measure(&tmp); } ac.frame_count += 1; if(ac.frame_count == NFRAMES - 1){ arm_power_f32(ac.activity_per_frame, NFRAMES - 1, &result); // Convert to average power result /= (NFRAMES - 1); ac_init(); if(result < activity_threshold){ return AC_RES_INACTIVE; } return AC_RES_ACTIVE; } euclidean3_copy(&frame->acc, &ac.last); return AC_RES_INCOMPLETE; }
float FloatArray::getPower(){ float result; /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_power_f32 (data, size, &result); #else result=0; float *pSrc = data; for(int n=0; n<size; n++){ result += pSrc[n]*pSrc[n]; } #endif return result; }