|
|
|
@ -32,52 +32,6 @@
|
|
|
|
@ingroup groupFilters
|
|
|
|
@ingroup groupFilters
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
@defgroup Corr Correlation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Correlation is a mathematical operation that is similar to convolution.
|
|
|
|
|
|
|
|
As with convolution, correlation uses two signals to produce a third signal.
|
|
|
|
|
|
|
|
The underlying algorithms in correlation and convolution are identical except that one of the inputs is flipped in convolution.
|
|
|
|
|
|
|
|
Correlation is commonly used to measure the similarity between two signals.
|
|
|
|
|
|
|
|
It has applications in pattern recognition, cryptanalysis, and searching.
|
|
|
|
|
|
|
|
The CMSIS library provides correlation functions for Q7, Q15, Q31 and floating-point data types.
|
|
|
|
|
|
|
|
Fast versions of the Q15 and Q31 functions are also provided.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@par Algorithm
|
|
|
|
|
|
|
|
Let <code>a[n]</code> and <code>b[n]</code> be sequences of length <code>srcALen</code> and <code>srcBLen</code> samples respectively.
|
|
|
|
|
|
|
|
The convolution of the two signals is denoted by
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
c[n] = a[n] * b[n]
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
In correlation, one of the signals is flipped in time
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
c[n] = a[n] * b[-n]
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
@par
|
|
|
|
|
|
|
|
and this is mathematically defined as
|
|
|
|
|
|
|
|
\image html CorrelateEquation.gif
|
|
|
|
|
|
|
|
@par
|
|
|
|
|
|
|
|
The <code>pSrcA</code> points to the first input vector of length <code>srcALen</code> and <code>pSrcB</code> points to the second input vector of length <code>srcBLen</code>.
|
|
|
|
|
|
|
|
The result <code>c[n]</code> is of length <code>2 * max(srcALen, srcBLen) - 1</code> and is defined over the interval <code>n=0, 1, 2, ..., (2 * max(srcALen, srcBLen) - 2)</code>.
|
|
|
|
|
|
|
|
The output result is written to <code>pDst</code> and the calling function must allocate <code>2 * max(srcALen, srcBLen) - 1</code> words for the result.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@note
|
|
|
|
|
|
|
|
The <code>pDst</code> should be initialized to all zeros before being used.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@par Fixed-Point Behavior
|
|
|
|
|
|
|
|
Correlation requires summing up a large number of intermediate products.
|
|
|
|
|
|
|
|
As such, the Q7, Q15, and Q31 functions run a risk of overflow and saturation.
|
|
|
|
|
|
|
|
Refer to the function specific documentation below for further details of the particular algorithm used.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@par Fast Versions
|
|
|
|
|
|
|
|
Fast versions are supported for Q31 and Q15. Cycles for Fast versions are less compared to Q31 and Q15 of correlate and the design requires
|
|
|
|
|
|
|
|
the input signals should be scaled down to avoid intermediate overflows.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@par Opt Versions
|
|
|
|
|
|
|
|
Opt versions are supported for Q15 and Q7. Design uses internal scratch buffer for getting good optimisation.
|
|
|
|
|
|
|
|
These versions are optimised in cycles and consumes more memory (Scratch memory) compared to Q15 and Q7 versions of correlate
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@addtogroup Corr
|
|
|
|
@addtogroup Corr
|
|
|
|
@{
|
|
|
|
@{
|
|
|
|
@ -209,7 +163,7 @@ void arm_correlate_f64(
|
|
|
|
while (blockSize1 > 0U)
|
|
|
|
while (blockSize1 > 0U)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
sum = 0.0f;
|
|
|
|
sum = 0.;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize k with number of samples */
|
|
|
|
/* Initialize k with number of samples */
|
|
|
|
k = count;
|
|
|
|
k = count;
|
|
|
|
@ -274,7 +228,7 @@ void arm_correlate_f64(
|
|
|
|
while (blkCnt > 0U)
|
|
|
|
while (blkCnt > 0U)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
sum = 0.0f;
|
|
|
|
sum = 0.;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize blkCnt with number of samples */
|
|
|
|
/* Initialize blkCnt with number of samples */
|
|
|
|
k = srcBLen;
|
|
|
|
k = srcBLen;
|
|
|
|
@ -314,7 +268,7 @@ void arm_correlate_f64(
|
|
|
|
while (blkCnt > 0U)
|
|
|
|
while (blkCnt > 0U)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
sum = 0.0f;
|
|
|
|
sum = 0.;
|
|
|
|
|
|
|
|
|
|
|
|
/* Loop over srcBLen */
|
|
|
|
/* Loop over srcBLen */
|
|
|
|
k = srcBLen;
|
|
|
|
k = srcBLen;
|
|
|
|
@ -375,7 +329,7 @@ void arm_correlate_f64(
|
|
|
|
while (blockSize3 > 0U)
|
|
|
|
while (blockSize3 > 0U)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
/* Accumulator is made zero for every iteration */
|
|
|
|
sum = 0.0f;
|
|
|
|
sum = 0.;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize blkCnt with number of samples */
|
|
|
|
/* Initialize blkCnt with number of samples */
|
|
|
|
k = count;
|
|
|
|
k = count;
|
|
|
|
|