1.4.2.95 DSP_VectorSumSquares32 Function
Computes the sum of squares of a vector, and scales the output by a binary factor.
Description
int32_t DSP_VectorSumSquares32(int32_t *indata, int N, int scale);
Calculates the sum of the squares of each element of an input vector, and scales the output. The function will saturate if it exceeds maximum or minimum values. Scaling is done by binary shifting, after calculation of the results. All calculations are done in Q31 fractional format.
return = 1/(2^scale) * sum(indata^2)
Preconditions
The pointers outdata and indata must be aligned on 4-byte boundaries. N must be greater than or equal to four and multiple of four.
Parameters
indata pointer to input array of 16-bit elements (int32_t)
scale number of bits to shift return right (int)
N number of samples (int)
Returns
int32_t - scaled output of calculation, Q15 format
Remarks
This must be assembled with .set microMIPS.
Example
int32_t inBufMultA[8]={0x7FFFFFFF, 0x80000000, 0x73333333, 0x66666666, 0x19999999, 0x40000000, 0x00000000, 0xB3333334}; _// 1, -1, 0.9, 0.8, 0.2, 0.5, 1, -0.6_ int Num = 8; int scaleVal = 3; int32_t outScalar; outScalar = DSP_VectorSumSquares32(inBufMultA, Num, scaleVal); _// outScalar = 1/(2\^scaleVal)* sum(inBufMultA[i]\^2) =_ _// (1/8) * (1 + 1 + 0.81 + 0.64 + 0.04 + 0.25 + 1 + 0.36) = 0.125 * 5.1 = 0.6375_ _// = (int32_t)0x51999999_
C
int32_t DSP_VectorSumSquares32 (int32_t * indata , int N , int scale );