Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CMSIS_DSP_5
main.cpp
- Committer:
- javiervicente
- Date:
- 2018-10-24
- Revision:
- 6:2a9b1cc25f1b
- Parent:
- 2:69827542e976
- Child:
- 7:b5d028a49c98
File content as of revision 6:2a9b1cc25f1b:
#include "mbed.h"
#include "datos.h"
#include "arm_math.h"
Timer timer;
int tiempo;
float resultado;
float calcularRMS(int16_t *datos, int longitud);
float calcularRMS2(int16_t *datos, int longitud);
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();
resultado=calcularRMS2(datos, 500);
timer.stop();
printf("****El valor Vrms2 es %f calculado en %d us ****\n",resultado,timer.read_us());
}
float calcularRMS(int16_t *datos, int longitud)
{
int64_t sumatorio=0;
int32_t producto;
float constante=4.503799026946597e-06; //3.3/2^15/sqrt(length(datos))
for (int n=0; n<longitud; n++) {
producto=datos[n]*datos[n];
sumatorio+=producto;
}
return sqrt((float)sumatorio)*constante;
}
float calcularRMS2(int16_t *datos, int longitud)
{
float constante=1.007080078125000e-04; //3.3/(2^15)
q15_t resultado=0.0;
arm_rms_q15 ((q15_t *)(datos), longitud, &resultado);
return resultado*constante;
}