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:
- 6:2a9b1cc25f1b
- Parent:
- 2:69827542e976
- Child:
- 7:b5d028a49c98
--- a/main.cpp Wed Oct 17 17:00:32 2018 +0000 +++ b/main.cpp Wed Oct 24 19:20:44 2018 +0000 @@ -1,11 +1,14 @@ #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() { @@ -14,12 +17,34 @@ timer.start(); resultado=calcularRMS(datos, 500); timer.stop(); - printf("****El valor Vrms es %f ****\n",resultado); + 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) { - return 0.0; + 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; +} +