hOLA AGATHE

Dependencies:   mbed CMSIS_DSP_5

Committer:
javiervicente
Date:
Wed Oct 24 19:20:44 2018 +0000
Revision:
6:2a9b1cc25f1b
Parent:
2:69827542e976
Child:
7:b5d028a49c98
satoI datosV

Who changed what in which revision?

UserRevisionLine numberNew contents of line
javiervicente 0:0d5a524c7d25 1 #include "mbed.h"
javiervicente 0:0d5a524c7d25 2 #include "datos.h"
javiervicente 6:2a9b1cc25f1b 3 #include "arm_math.h"
javiervicente 0:0d5a524c7d25 4
javiervicente 0:0d5a524c7d25 5 Timer timer;
javiervicente 6:2a9b1cc25f1b 6 int tiempo;
javiervicente 6:2a9b1cc25f1b 7
javiervicente 2:69827542e976 8 float resultado;
javiervicente 1:bdbd76df2103 9
javiervicente 2:69827542e976 10 float calcularRMS(int16_t *datos, int longitud);
javiervicente 6:2a9b1cc25f1b 11 float calcularRMS2(int16_t *datos, int longitud);
javiervicente 0:0d5a524c7d25 12
javiervicente 0:0d5a524c7d25 13 int main()
javiervicente 0:0d5a524c7d25 14 {
javiervicente 1:bdbd76df2103 15
javiervicente 1:bdbd76df2103 16 timer.reset();
javiervicente 0:0d5a524c7d25 17 timer.start();
javiervicente 2:69827542e976 18 resultado=calcularRMS(datos, 500);
javiervicente 0:0d5a524c7d25 19 timer.stop();
javiervicente 6:2a9b1cc25f1b 20 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 6:2a9b1cc25f1b 21
javiervicente 1:bdbd76df2103 22
javiervicente 6:2a9b1cc25f1b 23 timer.reset();
javiervicente 6:2a9b1cc25f1b 24 timer.start();
javiervicente 6:2a9b1cc25f1b 25 resultado=calcularRMS2(datos, 500);
javiervicente 6:2a9b1cc25f1b 26 timer.stop();
javiervicente 6:2a9b1cc25f1b 27 printf("****El valor Vrms2 es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 1:bdbd76df2103 28 }
javiervicente 1:bdbd76df2103 29
javiervicente 2:69827542e976 30 float calcularRMS(int16_t *datos, int longitud)
javiervicente 1:bdbd76df2103 31 {
javiervicente 6:2a9b1cc25f1b 32 int64_t sumatorio=0;
javiervicente 6:2a9b1cc25f1b 33 int32_t producto;
javiervicente 6:2a9b1cc25f1b 34 float constante=4.503799026946597e-06; //3.3/2^15/sqrt(length(datos))
javiervicente 6:2a9b1cc25f1b 35 for (int n=0; n<longitud; n++) {
javiervicente 6:2a9b1cc25f1b 36 producto=datos[n]*datos[n];
javiervicente 6:2a9b1cc25f1b 37 sumatorio+=producto;
javiervicente 6:2a9b1cc25f1b 38 }
javiervicente 6:2a9b1cc25f1b 39
javiervicente 6:2a9b1cc25f1b 40 return sqrt((float)sumatorio)*constante;
javiervicente 1:bdbd76df2103 41 }
javiervicente 1:bdbd76df2103 42
javiervicente 6:2a9b1cc25f1b 43 float calcularRMS2(int16_t *datos, int longitud)
javiervicente 6:2a9b1cc25f1b 44 {
javiervicente 6:2a9b1cc25f1b 45 float constante=1.007080078125000e-04; //3.3/(2^15)
javiervicente 6:2a9b1cc25f1b 46 q15_t resultado=0.0;
javiervicente 6:2a9b1cc25f1b 47 arm_rms_q15 ((q15_t *)(datos), longitud, &resultado);
javiervicente 6:2a9b1cc25f1b 48 return resultado*constante;
javiervicente 6:2a9b1cc25f1b 49 }
javiervicente 6:2a9b1cc25f1b 50