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
Diff: main.cpp
- Revision:
- 7:b5d028a49c98
- Parent:
- 6:2a9b1cc25f1b
--- a/main.cpp Wed Oct 24 19:20:44 2018 +0000
+++ b/main.cpp Thu Oct 17 21:10:40 2019 +0000
@@ -9,6 +9,7 @@
float calcularRMS(int16_t *datos, int longitud);
float calcularRMS2(int16_t *datos, int longitud);
+float calcularRMS3(int16_t *datos, int longitud);
int main()
{
@@ -25,19 +26,25 @@
resultado=calcularRMS2(datos, 500);
timer.stop();
printf("****El valor Vrms2 es %f calculado en %d us ****\n",resultado,timer.read_us());
+
+ timer.reset();
+ timer.start();
+ resultado=calcularRMS3(datos, 500);
+ timer.stop();
+ printf("****El valor Vrms3 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))
+ float constante=0.1007080078125e-03; //3.3/2^15
for (int n=0; n<longitud; n++) {
producto=datos[n]*datos[n];
sumatorio+=producto;
}
- return sqrt((float)sumatorio)*constante;
+ return sqrt((float)sumatorio/longitud)*constante;
}
float calcularRMS2(int16_t *datos, int longitud)
@@ -48,3 +55,17 @@
return resultado*constante;
}
+
+float calcularRMS3(int16_t *datos, int longitud)
+{
+
+ int32_t producto;
+ float constante=0.1007080078125e-03; //3.3/2^15
+ int64_t sumatorio=datos[0]*datos[0];
+ for (int n=1; n<longitud; n++) {
+ producto=datos[n]*datos[n];
+ sumatorio+=producto;
+ }
+
+ return sqrt((float)sumatorio/longitud)*constante;
+}