as

Dependencies:   mbed CMSIS_DSP_5

Committer:
MIGUI
Date:
Fri Oct 26 10:26:55 2018 +0000
Revision:
7:5a4df5ab9495
Parent:
6:38073f406fc8
Child:
8:e51ee87bb437
velocidad de calculo mejorada

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 7:5a4df5ab9495 10
MIGUI 7:5a4df5ab9495 11
MIGUI 6:38073f406fc8 12
javiervicente 0:0d5a524c7d25 13 int main()
javiervicente 0:0d5a524c7d25 14 {
MIGUI 6:38073f406fc8 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 3:44b632ea58aa 20 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
MIGUI 6:38073f406fc8 21
MIGUI 7:5a4df5ab9495 22 }
javiervicente 1:bdbd76df2103 23
javiervicente 1:bdbd76df2103 24
MIGUI 6:38073f406fc8 25 float calcularRMS(int16_t *datos, int longitud) // definicion de los estamentos de la funcion
javiervicente 1:bdbd76df2103 26 {
MIGUI 7:5a4df5ab9495 27 float32_t k=1.007080078125000e-04;
MIGUI 7:5a4df5ab9495 28 int64_t producto=0;
MIGUI 6:38073f406fc8 29
MIGUI 6:38073f406fc8 30 for (int n=0; n<longitud; n++) {
MIGUI 7:5a4df5ab9495 31 producto+=datos[n]*datos[n];
MIGUI 6:38073f406fc8 32 }
MIGUI 7:5a4df5ab9495 33 return sqrt((float(producto)/longitud))*k;
MIGUI 7:5a4df5ab9495 34
javiervicente 1:bdbd76df2103 35 }