hOLA AGATHE

Dependencies:   mbed CMSIS_DSP_5

Committer:
javiervicente
Date:
Thu Oct 17 21:10:40 2019 +0000
Revision:
7:b5d028a49c98
Parent:
6:2a9b1cc25f1b
pruebas

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 7:b5d028a49c98 12 float calcularRMS3(int16_t *datos, int longitud);
javiervicente 0:0d5a524c7d25 13
javiervicente 0:0d5a524c7d25 14 int main()
javiervicente 0:0d5a524c7d25 15 {
javiervicente 1:bdbd76df2103 16
javiervicente 1:bdbd76df2103 17 timer.reset();
javiervicente 0:0d5a524c7d25 18 timer.start();
javiervicente 2:69827542e976 19 resultado=calcularRMS(datos, 500);
javiervicente 0:0d5a524c7d25 20 timer.stop();
javiervicente 6:2a9b1cc25f1b 21 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 6:2a9b1cc25f1b 22
javiervicente 1:bdbd76df2103 23
javiervicente 6:2a9b1cc25f1b 24 timer.reset();
javiervicente 6:2a9b1cc25f1b 25 timer.start();
javiervicente 6:2a9b1cc25f1b 26 resultado=calcularRMS2(datos, 500);
javiervicente 6:2a9b1cc25f1b 27 timer.stop();
javiervicente 6:2a9b1cc25f1b 28 printf("****El valor Vrms2 es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 7:b5d028a49c98 29
javiervicente 7:b5d028a49c98 30 timer.reset();
javiervicente 7:b5d028a49c98 31 timer.start();
javiervicente 7:b5d028a49c98 32 resultado=calcularRMS3(datos, 500);
javiervicente 7:b5d028a49c98 33 timer.stop();
javiervicente 7:b5d028a49c98 34 printf("****El valor Vrms3 es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 1:bdbd76df2103 35 }
javiervicente 1:bdbd76df2103 36
javiervicente 2:69827542e976 37 float calcularRMS(int16_t *datos, int longitud)
javiervicente 1:bdbd76df2103 38 {
javiervicente 6:2a9b1cc25f1b 39 int64_t sumatorio=0;
javiervicente 6:2a9b1cc25f1b 40 int32_t producto;
javiervicente 7:b5d028a49c98 41 float constante=0.1007080078125e-03; //3.3/2^15
javiervicente 6:2a9b1cc25f1b 42 for (int n=0; n<longitud; n++) {
javiervicente 6:2a9b1cc25f1b 43 producto=datos[n]*datos[n];
javiervicente 6:2a9b1cc25f1b 44 sumatorio+=producto;
javiervicente 6:2a9b1cc25f1b 45 }
javiervicente 6:2a9b1cc25f1b 46
javiervicente 7:b5d028a49c98 47 return sqrt((float)sumatorio/longitud)*constante;
javiervicente 1:bdbd76df2103 48 }
javiervicente 1:bdbd76df2103 49
javiervicente 6:2a9b1cc25f1b 50 float calcularRMS2(int16_t *datos, int longitud)
javiervicente 6:2a9b1cc25f1b 51 {
javiervicente 6:2a9b1cc25f1b 52 float constante=1.007080078125000e-04; //3.3/(2^15)
javiervicente 6:2a9b1cc25f1b 53 q15_t resultado=0.0;
javiervicente 6:2a9b1cc25f1b 54 arm_rms_q15 ((q15_t *)(datos), longitud, &resultado);
javiervicente 6:2a9b1cc25f1b 55 return resultado*constante;
javiervicente 6:2a9b1cc25f1b 56 }
javiervicente 6:2a9b1cc25f1b 57
javiervicente 7:b5d028a49c98 58
javiervicente 7:b5d028a49c98 59 float calcularRMS3(int16_t *datos, int longitud)
javiervicente 7:b5d028a49c98 60 {
javiervicente 7:b5d028a49c98 61
javiervicente 7:b5d028a49c98 62 int32_t producto;
javiervicente 7:b5d028a49c98 63 float constante=0.1007080078125e-03; //3.3/2^15
javiervicente 7:b5d028a49c98 64 int64_t sumatorio=datos[0]*datos[0];
javiervicente 7:b5d028a49c98 65 for (int n=1; n<longitud; n++) {
javiervicente 7:b5d028a49c98 66 producto=datos[n]*datos[n];
javiervicente 7:b5d028a49c98 67 sumatorio+=producto;
javiervicente 7:b5d028a49c98 68 }
javiervicente 7:b5d028a49c98 69
javiervicente 7:b5d028a49c98 70 return sqrt((float)sumatorio/longitud)*constante;
javiervicente 7:b5d028a49c98 71 }