as

Dependencies:   mbed CMSIS_DSP_5

Committer:
MIGUI
Date:
Fri Oct 26 11:25:45 2018 +0000
Revision:
8:e51ee87bb437
Parent:
7:5a4df5ab9495
Child:
9:7ad36ab7f657
optimizando...;

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 8:e51ee87bb437 10 float calcularRMS2(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
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 8:e51ee87bb437 22 timer.reset();
MIGUI 8:e51ee87bb437 23 timer.start();
MIGUI 8:e51ee87bb437 24 resultado=calcularRMS2(datos, 500);
MIGUI 8:e51ee87bb437 25 timer.stop();
MIGUI 8:e51ee87bb437 26 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
MIGUI 8:e51ee87bb437 27
MIGUI 7:5a4df5ab9495 28 }
javiervicente 1:bdbd76df2103 29
javiervicente 1:bdbd76df2103 30
MIGUI 6:38073f406fc8 31 float calcularRMS(int16_t *datos, int longitud) // definicion de los estamentos de la funcion
javiervicente 1:bdbd76df2103 32 {
MIGUI 7:5a4df5ab9495 33 float32_t k=1.007080078125000e-04;
MIGUI 7:5a4df5ab9495 34 int64_t producto=0;
MIGUI 6:38073f406fc8 35
MIGUI 6:38073f406fc8 36 for (int n=0; n<longitud; n++) {
MIGUI 7:5a4df5ab9495 37 producto+=datos[n]*datos[n];
MIGUI 6:38073f406fc8 38 }
MIGUI 7:5a4df5ab9495 39 return sqrt((float(producto)/longitud))*k;
MIGUI 7:5a4df5ab9495 40
javiervicente 1:bdbd76df2103 41 }
MIGUI 8:e51ee87bb437 42
MIGUI 8:e51ee87bb437 43
MIGUI 8:e51ee87bb437 44 float calcularRMS2(int16_t *datos, int longitud) // definicion de los estamentos de la funcion
MIGUI 8:e51ee87bb437 45 {
MIGUI 8:e51ee87bb437 46 q15_t resultado;
MIGUI 8:e51ee87bb437 47 arm_rms_q15((q15_t *)datos , longitud, &resultado);
MIGUI 8:e51ee87bb437 48 float32_t aux;
MIGUI 8:e51ee87bb437 49 return arm_q15_to_float((q15_t)arm_rms_q15,&aux,longitud);
MIGUI 8:e51ee87bb437 50 }
MIGUI 8:e51ee87bb437 51
MIGUI 8:e51ee87bb437 52