as

Dependencies:   mbed CMSIS_DSP_5

Revision:
6:38073f406fc8
Parent:
5:0cee30954cdc
Child:
7:5a4df5ab9495
--- a/main.cpp	Fri Oct 19 11:59:19 2018 +0000
+++ b/main.cpp	Mon Oct 22 16:36:38 2018 +0000
@@ -1,33 +1,41 @@
 #include "mbed.h"
 #include "datos.h"
+#include "arm_math.h" //utilizar funcion de q15 a float32 para optimizar la funcion a 22ums
 
 Timer timer;
 float resultado;
 int tiempo;
 
-float calcularRMS(int16_t *datos, int longitud);
-{
-    size_t longitud=len(datos)
-    int16_t sumatorio=0
-    {
-    for (n=0;n<longitud;n++)
-    int16_t producto=datos(n)*datos(n)
-    sumatorio=sumatorio+producto
-    }
-}
+float calcularRMS(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
+float calcularRMS2(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
+
 int main()
 {
- 
+
     timer.reset();
     timer.start();
     resultado=calcularRMS(datos, 500);
     timer.stop();
     printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
+    
+        timer.reset();
+    timer.start();
+    resultado2=calcularRMS2(datos, 500);
+    timer.stop();
+    printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
 
 }
 
-float calcularRMS(int16_t *datos, int longitud)
+float calcularRMS(int16_t *datos, int longitud)  // definicion de los estamentos de la funcion
 {
-    return 0.0;
+    float k=1.007080078125000e-04;
+    int64_t sumatorio=0;
+    int32_t producto;
+    
+    for (int n=0; n<longitud; n++) {
+        producto=datos[n]*datos[n];
+        sumatorio=sumatorio+producto;
+    }
+    return sqrt(((float)sumatorio)/longitud)*k;
 }