00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R DSP Library 00008 * Title: arm_var_f32.c 00009 * 00010 * Description: Variance of the elements of a floating-point vector. 00011 * 00012 * Target Processor: Cortex-R4/R5 00013 * 00014 * Version 1.0.0 2011/03/08 00015 * Alpha release. 00016 * 00017 * Version 1.0.1 2011/09/30 00018 * Beta release. 00019 * 00020 * Version 2.0.0 2011/12/15 00021 * Final release. 00022 * 00023 * ---------------------------------------------------------------------------- */ 00024 #include "arm_math.h" 00025 00063 void arm_var_f32( 00064 float32_t * pSrc, 00065 uint32_t blockSize, 00066 float32_t * pResult) 00067 { 00068 float32_t meanOfSquares = 0.0f, mean = 0.0f, in, squareOfMean; 00069 uint32_t blkCnt; /* loop counter */ 00070 float32_t in1, in2, in3, in4; /* Temporary input variables */ 00071 float32_t meanOfSquares1 = 0.0f; 00072 float32_t meanOfSquares2 = 0.0f; 00073 float32_t meanOfSquares3 = 0.0f; 00074 float32_t mean1 = 0.0f; 00075 00076 /*loop Unrolling */ 00077 blkCnt = blockSize >> 3u; 00078 00079 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00080 ** a second loop below computes the remaining 1 to 7 samples. */ 00081 while(blkCnt > 0u) 00082 { 00083 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00084 /* Compute Sum of squares of the input samples 00085 * and then store the result in a temporary variable, sum. */ 00086 /* read input from source buffer */ 00087 in1 = pSrc[0]; 00088 in2 = pSrc[1]; 00089 00090 /* calculate sum of inputs */ 00091 mean += in1; 00092 /* calculate power of input and accumulate to accumulator */ 00093 meanOfSquares += in1 * in1; 00094 00095 /* read input from source buffer */ 00096 in3 = pSrc[2]; 00097 00098 /* calculate sum of inputs */ 00099 mean1 += in2; 00100 00101 /* calculate power of input and accumulate to accumulator */ 00102 meanOfSquares1 += in2 * in2; 00103 00104 /* read input from source buffer */ 00105 in4 = pSrc[3]; 00106 00107 /* calculate sum of inputs */ 00108 mean += in3; 00109 /* calculate power of input and accumulate to accumulator */ 00110 meanOfSquares2 += in3 * in3; 00111 00112 /* read input from source buffer */ 00113 in1 = pSrc[4]; 00114 00115 /* calculate sum of inputs */ 00116 mean1 += in4; 00117 /* calculate power of input and accumulate to accumulator */ 00118 meanOfSquares3 += in4 * in4; 00119 00120 /* read input from source buffer */ 00121 in2 = pSrc[5]; 00122 00123 /* calculate sum of inputs */ 00124 mean += in1; 00125 /* calculate power of input and accumulate to accumulator */ 00126 meanOfSquares += in1 * in1; 00127 00128 /* read input from source buffer */ 00129 in3 = pSrc[6]; 00130 00131 /* calculate sum of inputs */ 00132 mean1 += in2; 00133 /* calculate power of input and accumulate to accumulator */ 00134 meanOfSquares1 += in2 * in2; 00135 00136 /* read input from source buffer */ 00137 in4 = pSrc[7]; 00138 00139 /* calculate sum of inputs */ 00140 mean += in3; 00141 /* calculate power of input and accumulate to accumulator */ 00142 meanOfSquares2 += in3 * in3; 00143 00144 /* calculate sum of inputs */ 00145 mean1 += in4; 00146 /* calculate power of input and accumulate to accumulator */ 00147 meanOfSquares3 += in4 * in4; 00148 00149 /* update source buffer to process next samples */ 00150 pSrc += 8u; 00151 00152 /* Decrement the loop counter */ 00153 blkCnt--; 00154 } 00155 00156 /* add mean of square accumulators */ 00157 meanOfSquares = meanOfSquares + meanOfSquares1 + meanOfSquares2 + meanOfSquares3; 00158 /*add mean accumulators */ 00159 mean += mean1; 00160 00161 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00162 ** No loop unrolling is used. */ 00163 blkCnt = blockSize % 0x8u; 00164 00165 while(blkCnt > 0u) 00166 { 00167 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00168 /* Compute Sum of squares of the input samples 00169 * and then store the result in a temporary variable, sum. */ 00170 in = *pSrc++; 00171 meanOfSquares += in * in; 00172 mean += in; 00173 00174 /* Decrement the loop counter */ 00175 blkCnt--; 00176 } 00177 00178 /* Compute Mean of squares of the input samples 00179 * and then store the result in a temporary variable, meanOfSquares. */ 00180 meanOfSquares = meanOfSquares / ((float32_t) blockSize - 1.0f); 00181 00182 /* Compute mean of all input values */ 00183 mean = mean / (float32_t) blockSize; 00184 00185 /* Compute square of mean */ 00186 squareOfMean = (mean * mean) * (((float32_t) blockSize) / 00187 ((float32_t) blockSize - 1.0f)); 00188 00189 /* Compute variance and then store the result to the destination */ 00190 *pResult = meanOfSquares - squareOfMean; 00191 00192 } 00193