1.4.2.97 DSP_VectorVariance Function
Computes the variance of N elements of inVector.
Description
int32_t DSP_VectorVariance(int32_t *inVector, int N);
Calculates the variance on the first N elements of inVector and returns the 32-bit scalar result. The variance is a measure of the delta from mean values, and the mean value of the vector is computed in the process. The function has the form - var = sum((x(i) - M(N))^2) / (N-1) where N is the number of vector elements x(i) is a single element in the vector M(N) is the mean of the N elements of the vector.
Input values of the vector and output scalar value is Q31 fractional format. This format has data that ranges from -1 to 1, and has internal saturation limits of those same values. Some care has been taken to reduce the impact of saturation by adding processing steps to effectively complete the processing in blocks. However, in some extreme cases of data variance it is still possible to reach the saturation limits.
Preconditions
The pointers inVector must be aligned on 4-byte boundaries. N must be greater than or equal to four and a multiple of four.
Parameters
inVector pointer to source array of elements (int32_t)
N number of samples (int)
Returns
int32_t - Variance of N selected elements
Remarks
The input vector elements number, N, must be at least 4 and a multiple of 4. This function is optimized with microMIPS and M14KCe ASE DSP instructions.
Example
int varN = 8; int32_t inVarVec[8] = {0xE6666667, 0x40000000,0x40000000,0x0CCCCCCC, 0x00000000,0x59999999,0x20000000,0xC0000000}; _// -0.2, 0.5, 0.5, 0.1, 0, 0.7, 0.25, -0.5_ int32_t outVar = 0; outVar = DSP_VectorVariance(inVarVec, varN); _// outVar == 0x1490D2A6, = 0.1606696_
C
int32_t DSP_VectorVariance (int32_t * inVector , int N );