mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-23 21:29:17 +00:00
[feat][nmsis] add nmsis component and nn,dsp demo
This commit is contained in:
parent
b2aada479b
commit
5d1126d0f0
989 changed files with 286224 additions and 0 deletions
167
examples/dsp/StatisticsFunctions_part1/absmax.c
Normal file
167
examples/dsp/StatisticsFunctions_part1/absmax.c
Normal file
|
@ -0,0 +1,167 @@
|
|||
#include "ref.h"
|
||||
|
||||
void ref_absmax_f32(
|
||||
const float32_t * pSrc,
|
||||
uint32_t blockSize,
|
||||
float32_t * pResult,
|
||||
uint32_t * pIndex)
|
||||
{
|
||||
float32_t maxVal, out; /* Temporary variables to store the output value. */
|
||||
uint32_t blkCnt, outIndex; /* Loop counter */
|
||||
|
||||
/* Initialise index value to zero. */
|
||||
outIndex = 0U;
|
||||
|
||||
/* Load first input value that act as reference value for comparision */
|
||||
out = fabsf(*pSrc++);
|
||||
|
||||
/* Initialize blkCnt with number of samples */
|
||||
blkCnt = (blockSize - 1U);
|
||||
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* Initialize maxVal to the next consecutive values one by one */
|
||||
maxVal = fabsf(*pSrc++);
|
||||
|
||||
/* compare for the maximum value */
|
||||
if (out < maxVal)
|
||||
{
|
||||
/* Update the maximum value and it's index */
|
||||
out = maxVal;
|
||||
outIndex = blockSize - blkCnt;
|
||||
}
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
/* Store the maximum value and it's index into destination pointers */
|
||||
*pResult = out;
|
||||
*pIndex = outIndex;
|
||||
}
|
||||
|
||||
void ref_absmax_q7(
|
||||
const q7_t * pSrc,
|
||||
uint32_t blockSize,
|
||||
q7_t * pResult,
|
||||
uint32_t * pIndex)
|
||||
{
|
||||
q7_t maxVal, out; /* Temporary variables to store the output value. */
|
||||
uint32_t blkCnt, outIndex; /* Loop counter */
|
||||
|
||||
|
||||
/* Initialise index value to zero. */
|
||||
outIndex = 0U;
|
||||
/* Load first input value that act as reference value for comparision */
|
||||
out = (*pSrc > 0) ? *pSrc : ((*pSrc == (q7_t) 0x80) ? (q7_t) 0x7f : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* Initialize blkCnt with number of samples */
|
||||
blkCnt = (blockSize - 1U);
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* Initialize maxVal to the next consecutive values one by one */
|
||||
maxVal = (*pSrc > 0) ? *pSrc : ((*pSrc == (q7_t) 0x80) ? (q7_t) 0x7f : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* compare for the maximum value */
|
||||
if (out < maxVal)
|
||||
{
|
||||
/* Update the maximum value and it's index */
|
||||
out = maxVal;
|
||||
outIndex = blockSize - blkCnt;
|
||||
}
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
/* Store the maximum value and it's index into destination pointers */
|
||||
*pResult = out;
|
||||
*pIndex = outIndex;
|
||||
}
|
||||
|
||||
void ref_absmax_q15(
|
||||
const q15_t * pSrc,
|
||||
uint32_t blockSize,
|
||||
q15_t * pResult,
|
||||
uint32_t * pIndex)
|
||||
{
|
||||
q15_t maxVal, out; /* Temporary variables to store the output value. */
|
||||
uint32_t blkCnt, outIndex; /* Loop counter */
|
||||
|
||||
/* Initialise index value to zero. */
|
||||
outIndex = 0U;
|
||||
/* Load first input value that act as reference value for comparision */
|
||||
out = (*pSrc > 0) ? *pSrc : ((*pSrc == (q15_t) 0x8000) ? 0x7fff : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* Initialize blkCnt with number of samples */
|
||||
blkCnt = (blockSize - 1U);
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* Initialize maxVal to the next consecutive values one by one */
|
||||
maxVal = (*pSrc > 0) ? *pSrc : ((*pSrc == (q15_t) 0x8000) ? 0x7fff : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* compare for the maximum value */
|
||||
if (out < maxVal)
|
||||
{
|
||||
/* Update the maximum value and it's index */
|
||||
out = maxVal;
|
||||
outIndex = blockSize - blkCnt;
|
||||
}
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
/* Store the maximum value and it's index into destination pointers */
|
||||
*pResult = out;
|
||||
*pIndex = outIndex;
|
||||
}
|
||||
|
||||
void ref_absmax_q31(
|
||||
const q31_t * pSrc,
|
||||
uint32_t blockSize,
|
||||
q31_t * pResult,
|
||||
uint32_t * pIndex)
|
||||
{
|
||||
q31_t maxVal, out; /* Temporary variables to store the output value. */
|
||||
uint32_t blkCnt, outIndex; /* Loop counter */
|
||||
|
||||
|
||||
/* Initialise index value to zero. */
|
||||
outIndex = 0U;
|
||||
/* Load first input value that act as reference value for comparision */
|
||||
out = (*pSrc > 0) ? *pSrc : ((*pSrc == INT32_MIN) ? INT32_MAX : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* Initialize blkCnt with number of samples */
|
||||
blkCnt = (blockSize - 1U);
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* Initialize maxVal to the next consecutive values one by one */
|
||||
maxVal = (*pSrc > 0) ? *pSrc : ((*pSrc == INT32_MIN) ? INT32_MAX : -*pSrc);
|
||||
pSrc++;
|
||||
|
||||
/* compare for the maximum value */
|
||||
if (out < maxVal)
|
||||
{
|
||||
/* Update the maximum value and it's index */
|
||||
out = maxVal;
|
||||
outIndex = blockSize - blkCnt;
|
||||
}
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
/* Store the maximum value and it's index into destination pointers */
|
||||
*pResult = out;
|
||||
*pIndex = outIndex;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue