Carmen_y_Miguel / Mbed 2 deprecated ejercicioVrms2

Dependencies:   mbed CMSIS_DSP_5

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "datos.h"
00003 #include "arm_math.h" //utilizar funcion de q15 a float32 para optimizar la funcion a 22ums
00004 
00005 Timer timer;
00006 float resultado;
00007 float resultado2;
00008 int tiempo;
00009 
00010 float calcularRMS(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
00011 float calcularRMS2(int16_t *datos, int longitud); //definicion del tipo de variable que devuelve la funcion
00012 
00013 
00014 int main()
00015 {
00016 
00017     timer.reset();
00018     timer.start();
00019     resultado=calcularRMS(datos, 500);
00020     timer.stop();
00021     printf("****El valor Vrms es %f calculado en %d us ****\n\r",resultado,timer.read_us());
00022     
00023     timer.reset();
00024     timer.start();
00025     resultado2=calcularRMS2(datos, 500);
00026     timer.stop();
00027     printf("****El valor Vrms2 es %f calculado en %d us ****\n\r",resultado2,timer.read_us());
00028     
00029 }
00030 
00031 
00032 float calcularRMS(int16_t *datos, int longitud)  // definicion de los estamentos de la funcion
00033 {
00034     float32_t k=1.007080078125000e-04;
00035     int64_t producto=0;
00036     
00037     for (int n=0; n<longitud; n++) {
00038         producto+=datos[n]*datos[n];
00039     }
00040     return sqrt((float(producto)/longitud))*k;
00041     
00042 }
00043 
00044 
00045 float calcularRMS2(int16_t *datos, int longitud)  // definicion de los estamentos de la funcion
00046 {
00047     
00048     q15_t resultado2;
00049     float resultado2aux;
00050     arm_rms_q15((q15_t *)datos ,   longitud,   &resultado2);
00051     arm_q15_to_float(&resultado2,&resultado2aux,1);
00052     return resultado2aux*3.3f;
00053 }
00054 
00055