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
Diff: LookupTables.cpp
- Revision:
- 0:8c128e047ec9
- Child:
- 1:099f1a4c5fc8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LookupTables.cpp Tue Mar 28 08:48:23 2017 +0000
@@ -0,0 +1,67 @@
+
+#include "LookupTables.h"
+
+////////////////// COSINE SINE LOOKUP TABLES
+
+// Returns the cosine value using the lut of a given value
+float lut_cos(float value){
+ // Cosine is symmetric so convert to absolute
+ if (value < 0)
+ value = -value;
+
+ // and subtract the "offset"
+ //float actualvalue = (float)(value % (2*M_PI));
+
+ while (value >= 2 * (float)M_PI){
+ value -= 2 * (float)M_PI;
+ }
+
+ // Calculate the value to a discrete value (1024*0.00613592 = 2 pi)
+ int discreteValue = (int)(value / 0.00613592);
+
+ return cosLookupTable_f[discreteValue];
+}
+// Returns the sine value using the lut for a given value
+float lut_sin(float value){
+ // Convert to cosine
+ value -= 0.5*(float)M_PI;
+ // Cosine is symmetric so convert to absolute
+ if (value < 0)
+ value = -value;
+
+ // subtract the "offset" of the original 0-2pi
+ //float actualvalue = (float)(value % (float)(2 * M_PI));
+
+ while (value >= (2 * (float)M_PI)){
+ value -= (2 * (float)M_PI);
+ }
+
+ // Calculate the value to a discrete value (1024*0.00613592 = 2 pi)
+ int discreteValue = (int)(value / 0.00613592);
+
+ return cosLookupTable_f[discreteValue];
+}
+
+// Returns the cosine value using the lut of a given value
+// WARNING, FAST VERSION ONLY WORKS WITH VALUES 0 - 2 PI
+float lut_cos_f(float value){
+ // Calculate the value to a discrete value (1024*0.00613592 = 2 pi)
+ int discreteValue = (int)(value / 0.00613592);
+
+ return cosLookupTable_f[discreteValue];
+}
+
+////////////////// END COSINE SINE LOOKUP TABLES
+
+////////////////// HANNING LOOKUP TABLE
+
+// Applies the hanning LUT to the supplied array of data
+void applyHanningTable(float* data, int datasize){
+ if (datasize == 1024){ // Only works for 10 bit data arrays
+ for (int i = 0; i < 1024; i++){
+ data[i] *= hanningTable_f[i];
+ }
+ }
+}
+
+////////////////// END HANNING LOOKUP TABLE
\ No newline at end of file