as

Dependencies:   mbed CMSIS_DSP_5

Committer:
MIGUI
Date:
Fri Oct 26 11:47:52 2018 +0000
Revision:
10:587dbc2c220a
Parent:
9:7ad36ab7f657
optimizado final;

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