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_std_f32.c 00009 * 00010 * Description: Standard deviation 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_std_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; /* Temporary intermediate variable */ 00072 float32_t meanOfSquares2 = 0.0f; /* Temporary intermediate variable */ 00073 float32_t meanOfSquares3 = 0.0f; /* Temporary intermediate variable */ 00074 float32_t mean1 = 0.0f; /* Temporary intermediate variable */ 00075 00076 00077 /*loop Unrolling */ 00078 blkCnt = blockSize >> 3u; 00079 00080 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00081 ** a second loop below computes the remaining 1 to 7 samples. */ 00082 while(blkCnt > 0u) 00083 { 00084 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00085 /* Compute Sum of squares of the input samples 00086 * and then store the result in a temporary variable, sum. */ 00087 /* read two inputs from source buffer */ 00088 in1 = pSrc[0]; 00089 in2 = pSrc[1]; 00090 00091 /* calculate sum of inputs */ 00092 mean += in1; 00093 /* calculate square of input and accumulate to accumulator */ 00094 meanOfSquares += in1 * in1; 00095 00096 /* read input from source buffer */ 00097 in3 = pSrc[2]; 00098 00099 /* calculate sum of inputs */ 00100 mean1 += in2; 00101 /* calculate square 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 square 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 square 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 square 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 square 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 square of input and accumulate to accumulator */ 00142 meanOfSquares2 += in3 * in3; 00143 00144 /* calculate sum of inputs */ 00145 mean1 += in4; 00146 /* calculate square 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 00159 /* add mean accumulators */ 00160 mean += mean1; 00161 00162 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00163 ** No loop unrolling is used. */ 00164 blkCnt = blockSize % 0x8u; 00165 00166 00167 while(blkCnt > 0u) 00168 { 00169 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00170 /* Compute Sum of squares of the input samples 00171 * and then store the result in a temporary variable, sum. */ 00172 in = *pSrc++; 00173 meanOfSquares += in * in; 00174 mean += in; 00175 00176 /* Decrement the loop counter */ 00177 blkCnt--; 00178 } 00179 00180 /* Compute Mean of squares of the input samples 00181 * and then store the result in a temporary variable, meanOfSquares. */ 00182 meanOfSquares = meanOfSquares / ((float32_t) blockSize - 1.0f); 00183 00184 /* Compute mean of all input values */ 00185 mean = mean / (float32_t) blockSize; 00186 00187 /* Compute square of mean */ 00188 squareOfMean = (mean * mean) * (((float32_t) blockSize) / 00189 ((float32_t) blockSize - 1.0f)); 00190 00191 /* Compute standard deviation and then store the result to the destination */ 00192 arm_sqrt_f32((meanOfSquares - squareOfMean), pResult); 00193 } 00194