diff options
author | joshua <joshua@joshuayun.com> | 2023-12-30 23:54:31 -0500 |
---|---|---|
committer | joshua <joshua@joshuayun.com> | 2023-12-30 23:54:31 -0500 |
commit | 86608c6770cf08c138a2bdab5855072f64be09ef (patch) | |
tree | 494a61b3ef37e76f9235a0d10f5c93d97290a35f /Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions | |
download | sdr-software-86608c6770cf08c138a2bdab5855072f64be09ef.tar.gz |
Diffstat (limited to 'Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions')
8 files changed, 509 insertions, 0 deletions
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/StatisticsFunctions.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/StatisticsFunctions.c new file mode 100644 index 0000000..6791b3e --- /dev/null +++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/StatisticsFunctions.c @@ -0,0 +1,8 @@ +
+#include "max.c"
+#include "mean.c"
+#include "min.c"
+#include "power.c"
+#include "rms.c"
+#include "std.c"
+#include "var.c"
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c new file mode 100644 index 0000000..02b4127 --- /dev/null +++ b/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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c new file mode 100644 index 0000000..d4b4da4 --- /dev/null +++ b/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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c new file mode 100644 index 0000000..6072b1a --- /dev/null +++ b/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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c new file mode 100644 index 0000000..8202e04 --- /dev/null +++ b/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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c new file mode 100644 index 0000000..94943a9 --- /dev/null +++ b/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;
+ uint64_t sumsq = 0; /* accumulator (can get never negative. changed type from q63 to uint64 */
+ 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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c new file mode 100644 index 0000000..c0c1ba3 --- /dev/null +++ b/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/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c new file mode 100644 index 0000000..f5da3a6 --- /dev/null +++ b/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;
+}
|