Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "arm_math.h"
00025
00060 void arm_var_q31(
00061 q31_t * pSrc,
00062 uint32_t blockSize,
00063 q63_t * pResult)
00064 {
00065 q63_t sum = 0, sumSquare = 0, sumSquare1 = 0;
00066 q31_t meanOfSquares, squareOfMean;
00067 q31_t mean;
00068 q31_t in;
00069 q31_t t;
00070 uint32_t blkCnt;
00071 q31_t in1, in2, in3, in4;
00072
00073
00074 blkCnt = blockSize >> 3u;
00075
00076
00077
00078 while(blkCnt > 0u)
00079 {
00080
00081
00082
00083
00084 in1 = pSrc[0];
00085 in2 = pSrc[1];
00086
00087
00088 sum += in1;
00089
00090 sumSquare += ((q63_t) (in1) * (in1));
00091 in3 = pSrc[2];
00092 sum += in2;
00093 sumSquare1 += ((q63_t) (in2) * (in2));
00094 in4 = pSrc[3];
00095 sum += in3;
00096 sumSquare += ((q63_t) (in3) * (in3));
00097 in1 = pSrc[4];
00098 sum += in4;
00099 sumSquare1 += ((q63_t) (in4) * (in4));
00100 in2 = pSrc[5];
00101 sum += in1;
00102 sumSquare += ((q63_t) (in1) * (in1));
00103 in3 = pSrc[6];
00104 sum += in2;
00105 sumSquare1 += ((q63_t) (in2) * (in2));
00106 in4 = pSrc[7];
00107 sum += in3;
00108 sumSquare += ((q63_t) (in3) * (in3));
00109 sum += in4;
00110 sumSquare1 += ((q63_t) (in4) * (in4));
00111
00112
00113 pSrc += 8u;
00114
00115
00116 blkCnt--;
00117 }
00118
00119
00120 sumSquare = sumSquare + sumSquare1;
00121
00122
00123
00124 blkCnt = blockSize % 0x8u;
00125
00126 while(blkCnt > 0u)
00127 {
00128
00129
00130
00131 in = *pSrc++;
00132 sumSquare += ((q63_t) (in) * (in));
00133 sum += in;
00134
00135
00136 blkCnt--;
00137 }
00138
00139 t = (q31_t) ((1.0f / (float32_t) (blockSize - 1u)) * 1073741824.0f);
00140
00141
00142
00143 sumSquare = (sumSquare >> 31);
00144 meanOfSquares = (q31_t) ((sumSquare * t) >> 30);
00145
00146
00147 t = (q31_t) ((1.0f / (blockSize * (blockSize - 1u))) * 2147483648.0f);
00148 mean = (q31_t) (sum);
00149
00150
00151 squareOfMean = (q31_t) (((q63_t) mean * mean) >> 31);
00152 squareOfMean = (q31_t) (((q63_t) squareOfMean * t) >> 31);
00153
00154
00155 *pResult = (q63_t) meanOfSquares - squareOfMean;
00156
00157 }
00158