as

Dependencies:   mbed CMSIS_DSP_5

Committer:
MIGUI
Date:
Mon Oct 22 16:36:38 2018 +0000
Revision:
6:38073f406fc8
Parent:
5:0cee30954cdc
Child:
7:5a4df5ab9495
funci?n terminada

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"
MIGUI 6:38073f406fc8 3 #include "arm_math.h" //utilizar funcion de q15 a float32 para optimizar la funcion a 22ums
javiervicente 0:0d5a524c7d25 4
javiervicente 0:0d5a524c7d25 5 Timer timer;
javiervicente 2:69827542e976 6 float resultado;
javiervicente 3:44b632ea58aa 7 int tiempo;
javiervicente 1:bdbd76df2103 8
MIGUI 6:38073f406fc8 9 float calcularRMS(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
MIGUI 6:38073f406fc8 10 float calcularRMS2(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
MIGUI 6:38073f406fc8 11
javiervicente 0:0d5a524c7d25 12 int main()
javiervicente 0:0d5a524c7d25 13 {
MIGUI 6:38073f406fc8 14
javiervicente 1:bdbd76df2103 15 timer.reset();
javiervicente 0:0d5a524c7d25 16 timer.start();
javiervicente 2:69827542e976 17 resultado=calcularRMS(datos, 500);
javiervicente 0:0d5a524c7d25 18 timer.stop();
javiervicente 3:44b632ea58aa 19 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
MIGUI 6:38073f406fc8 20
MIGUI 6:38073f406fc8 21 timer.reset();
MIGUI 6:38073f406fc8 22 timer.start();
MIGUI 6:38073f406fc8 23 resultado2=calcularRMS2(datos, 500);
MIGUI 6:38073f406fc8 24 timer.stop();
MIGUI 6:38073f406fc8 25 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
javiervicente 1:bdbd76df2103 26
javiervicente 1:bdbd76df2103 27 }
javiervicente 1:bdbd76df2103 28
MIGUI 6:38073f406fc8 29 float calcularRMS(int16_t *datos, int longitud) // definicion de los estamentos de la funcion
javiervicente 1:bdbd76df2103 30 {
MIGUI 6:38073f406fc8 31 float k=1.007080078125000e-04;
MIGUI 6:38073f406fc8 32 int64_t sumatorio=0;
MIGUI 6:38073f406fc8 33 int32_t producto;
MIGUI 6:38073f406fc8 34
MIGUI 6:38073f406fc8 35 for (int n=0; n<longitud; n++) {
MIGUI 6:38073f406fc8 36 producto=datos[n]*datos[n];
MIGUI 6:38073f406fc8 37 sumatorio=sumatorio+producto;
MIGUI 6:38073f406fc8 38 }
MIGUI 6:38073f406fc8 39 return sqrt(((float)sumatorio)/longitud)*k;
javiervicente 1:bdbd76df2103 40 }
javiervicente 1:bdbd76df2103 41