diff options
author | JanHenrik <janhenrik@janhenrik.org> | 2020-04-01 00:40:03 +0200 |
---|---|---|
committer | JanHenrik <janhenrik@janhenrik.org> | 2020-04-01 00:40:03 +0200 |
commit | f7de54fc6fa6b40dfa2dfbe4c2a8ee933affa126 (patch) | |
tree | 78465e38a01011dc9f17eb73416011310532017f /midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions | |
parent | 3ec13d81e70e52246545c720abe756ccf09fb231 (diff) | |
download | minikbd-f7de54fc6fa6b40dfa2dfbe4c2a8ee933affa126.tar.gz minikbd-f7de54fc6fa6b40dfa2dfbe4c2a8ee933affa126.tar.bz2 minikbd-f7de54fc6fa6b40dfa2dfbe4c2a8ee933affa126.zip |
added files
Diffstat (limited to 'midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions')
7 files changed, 501 insertions, 0 deletions
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c new file mode 100644 index 0000000..02b4127 --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c @@ -0,0 +1,85 @@ +#include "ref.h"
+
+void ref_max_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ float32_t max=-FLT_MAX;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (max < pSrc[i])
+ {
+ max = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = max;
+ *pIndex = ind;
+}
+
+void ref_max_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q31_t max=INT_MIN;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (max < pSrc[i])
+ {
+ max = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = max;
+ *pIndex = ind;
+}
+
+void ref_max_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q15_t max=SHRT_MIN;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (max < pSrc[i])
+ {
+ max = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = max;
+ *pIndex = ind;
+}
+
+void ref_max_q7(
+ q7_t * pSrc,
+ uint32_t blockSize,
+ q7_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q7_t max=SCHAR_MIN;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (max < pSrc[i])
+ {
+ max = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = max;
+ *pIndex = ind;
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c new file mode 100644 index 0000000..d4b4da4 --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c @@ -0,0 +1,61 @@ +#include "ref.h"
+
+void ref_mean_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult)
+{
+ uint32_t i;
+ float32_t sum=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ }
+ *pResult = sum / (float32_t)blockSize;
+}
+
+void ref_mean_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult)
+{
+ uint32_t i;
+ q63_t sum=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ }
+ *pResult = (q31_t) (sum / (int32_t) blockSize);
+}
+
+void ref_mean_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult)
+{
+ uint32_t i;
+ q31_t sum=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ }
+ *pResult = (q15_t) (sum / (int32_t) blockSize);
+}
+
+void ref_mean_q7(
+ q7_t * pSrc,
+ uint32_t blockSize,
+ q7_t * pResult)
+{
+ uint32_t i;
+ q31_t sum=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ }
+ *pResult = (q7_t) (sum / (int32_t) blockSize);
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c new file mode 100644 index 0000000..6072b1a --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c @@ -0,0 +1,85 @@ +#include "ref.h"
+
+void ref_min_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ float32_t min=FLT_MAX;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (min > pSrc[i])
+ {
+ min = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = min;
+ *pIndex = ind;
+}
+
+void ref_min_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q31_t min=INT_MAX;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (min > pSrc[i])
+ {
+ min = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = min;
+ *pIndex = ind;
+}
+
+void ref_min_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q15_t min=SHRT_MAX;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (min > pSrc[i])
+ {
+ min = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = min;
+ *pIndex = ind;
+}
+
+void ref_min_q7(
+ q7_t * pSrc,
+ uint32_t blockSize,
+ q7_t * pResult,
+ uint32_t * pIndex)
+{
+ uint32_t i, ind=0;
+ q7_t min=SCHAR_MAX;
+
+ for(i=0;i<blockSize;i++)
+ {
+ if (min > pSrc[i])
+ {
+ min = pSrc[i];
+ ind = i;
+ }
+ }
+ *pResult = min;
+ *pIndex = ind;
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c new file mode 100644 index 0000000..8202e04 --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c @@ -0,0 +1,61 @@ +#include "ref.h"
+
+void ref_power_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult)
+{
+ uint32_t i;
+ float32_t sumsq=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += pSrc[i] * pSrc[i];
+ }
+ *pResult = sumsq;
+}
+
+void ref_power_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q63_t * pResult)
+{
+ uint32_t i;
+ q63_t sumsq=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += ((q63_t)pSrc[i] * pSrc[i]) >> 14;
+ }
+ *pResult = sumsq;
+}
+
+void ref_power_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q63_t * pResult)
+{
+ uint32_t i;
+ q63_t sumsq=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += (q63_t)pSrc[i] * pSrc[i];
+ }
+ *pResult = sumsq;
+}
+
+void ref_power_q7(
+ q7_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult)
+{
+ uint32_t i;
+ q31_t sumsq=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += (q31_t)pSrc[i] * pSrc[i];
+ }
+ *pResult = sumsq;
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c new file mode 100644 index 0000000..d3ff5bf --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c @@ -0,0 +1,65 @@ +#include "ref.h"
+
+void ref_rms_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult)
+{
+ uint32_t i;
+ float32_t sumsq=0;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += pSrc[i] * pSrc[i];
+ }
+ *pResult = sqrtf(sumsq / (float32_t)blockSize);
+}
+
+void ref_rms_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult)
+{
+ uint32_t i;
+ q63_t sumsq=0;
+ q63_t tmp1;
+ q31_t tmp2;
+
+ float help_float;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += (q63_t)pSrc[i] * pSrc[i];
+ }
+ tmp1 = (sumsq / (q63_t)blockSize) >> 31;
+ tmp2 = ref_sat_q31(tmp1);
+
+ /* GCC M0 problem: __aeabi_f2iz(QNAN) returns not 0 */
+ help_float = (sqrtf((float)tmp2 / 2147483648.0f) * 2147483648.0f);
+ /* Checking for a NAN value in help_float */
+ if (((*((int *)(&help_float))) & 0x7FC00000) == 0x7FC00000) {
+ help_float = 0;
+ }
+ *pResult = (q31_t)(help_float);
+
+// *pResult = (q31_t)(sqrtf((float)tmp2 / 2147483648.0f) * 2147483648.0f);
+}
+
+void ref_rms_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult)
+{
+ uint32_t i;
+ q63_t sumsq=0;
+ q31_t tmp1;
+ q15_t tmp2;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sumsq += (q63_t)pSrc[i] * pSrc[i];
+ }
+ tmp1 = (sumsq / (q63_t)blockSize) >> 15;
+ tmp2 = ref_sat_q15(tmp1);
+ *pResult = (q15_t)(sqrtf((float)tmp2 / 32768.0f) * 32768.0f);
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c new file mode 100644 index 0000000..c0c1ba3 --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c @@ -0,0 +1,74 @@ +#include "ref.h"
+
+void ref_std_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult)
+{
+ uint32_t i;
+ float32_t sum=0, sumsq=0;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ sumsq += pSrc[i] * pSrc[i];
+ }
+ *pResult = sqrtf((sumsq - sum * sum / (float32_t)blockSize) / ((float32_t)blockSize - 1));
+}
+
+void ref_std_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult)
+{
+ uint32_t i;
+ q63_t sum=0, sumsq=0;
+ q31_t in;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ in = pSrc[i] >> 8;
+ sum += in;
+ sumsq += (q63_t)in * in;
+ }
+ sumsq /= (q63_t)(blockSize - 1);
+ sum = sum * sum / (q63_t)(blockSize * (blockSize - 1));
+ *pResult = (q31_t)(sqrtf((float)( (sumsq - sum) >> 15) / 2147483648.0f ) * 2147483648.0f);
+}
+
+void ref_std_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult)
+{
+ uint32_t i;
+ q31_t sum=0;
+ q63_t sumsq=0;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ sumsq += (q63_t)pSrc[i] * pSrc[i];
+ }
+ sumsq /= (q63_t)(blockSize - 1);
+ sum = (q31_t)((q63_t)sum * sum / (q63_t)(blockSize * (blockSize - 1)));
+ *pResult = (q15_t)(sqrtf((float)ref_sat_q15( (sumsq - sum) >> 15) / 32768.0f ) * 32768.0f);
+}
diff --git a/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c new file mode 100644 index 0000000..f5da3a6 --- /dev/null +++ b/midi-dials/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c @@ -0,0 +1,70 @@ +#include "ref.h"
+
+void ref_var_f32(
+ float32_t * pSrc,
+ uint32_t blockSize,
+ float32_t * pResult)
+{
+ uint32_t i;
+ float32_t sum=0, sumsq=0;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ sumsq += pSrc[i] * pSrc[i];
+ }
+ *pResult = (sumsq - sum * sum / (float32_t)blockSize) / ((float32_t)blockSize - 1);
+}
+
+void ref_var_q31(
+ q31_t * pSrc,
+ uint32_t blockSize,
+ q31_t * pResult)
+{
+ uint32_t i;
+ q63_t sum=0, sumsq=0;
+ q31_t in;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ in = pSrc[i] >> 8;
+ sum += in;
+ sumsq += (q63_t)in * in;
+ }
+ *pResult = (sumsq - sum * sum / (q31_t)blockSize) / ((q31_t)blockSize - 1) >> 15;
+}
+
+void ref_var_q15(
+ q15_t * pSrc,
+ uint32_t blockSize,
+ q15_t * pResult)
+{
+ uint32_t i;
+ q31_t sum=0;
+ q63_t sumsq=0;
+
+ if (blockSize == 1)
+ {
+ *pResult = 0;
+ return;
+ }
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrc[i];
+ sumsq += (q63_t)pSrc[i] * pSrc[i];
+ }
+ *pResult = (q31_t)((sumsq - (q63_t)sum * sum / (q63_t)blockSize) / ((q63_t)blockSize - 1)) >> 15;
+}
|