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_rms_f32.c 00009 * 00010 * Description: Root mean square value of an array of F32 type 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 00059 void arm_rms_f32( 00060 float32_t * pSrc, 00061 uint32_t blockSize, 00062 float32_t * pResult) 00063 { 00064 float32_t in; /* Tempoprary variable to store input value */ 00065 uint32_t blkCnt; /* loop counter */ 00066 float32_t in1, in2, in3, in4; /* Temporary input variables */ 00067 float32_t sum1= 0, sum2 = 0, sum3 = 0, sum4 = 0;/* Accumulators */ 00068 00069 /* loop Unrolling */ 00070 blkCnt = blockSize >> 3u; 00071 00072 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00073 ** a second loop below computes the remaining 1 to 7 samples. */ 00074 while(blkCnt > 0u) 00075 { 00076 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00077 /* Compute sum of the squares and then store the result in a temporary variable, sum */ 00078 /* read four samples from source buffer */ 00079 in1 = pSrc[0]; 00080 in2 = pSrc[1]; 00081 in3 = pSrc[2]; 00082 in4 = pSrc[3]; 00083 00084 /* calculate square and accumulate to accumulator */ 00085 sum1 += in1 * in1; 00086 sum2 += in2 * in2; 00087 sum3 += in3 * in3; 00088 sum4 += in4 * in4; 00089 00090 /* read four samples from source buffer */ 00091 in1 = pSrc[4]; 00092 in2 = pSrc[5]; 00093 in3 = pSrc[6]; 00094 in4 = pSrc[7]; 00095 00096 /* calculate square and accumulate to accumulator */ 00097 sum1 += in1 * in1; 00098 sum2 += in2 * in2; 00099 sum3 += in3 * in3; 00100 sum4 += in4 * in4; 00101 00102 /* update source buffer to process next samples */ 00103 pSrc += 8u; 00104 00105 /* Decrement the loop counter */ 00106 blkCnt--; 00107 } 00108 00109 /* add accumulators */ 00110 sum1 = sum1 + sum2 + sum3 + sum4; 00111 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00112 ** No loop unrolling is used. */ 00113 blkCnt = blockSize % 0x8u; 00114 00115 while(blkCnt > 0u) 00116 { 00117 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00118 /* Compute sum of the squares and then store the results in a temporary variable, sum */ 00119 in = *pSrc++; 00120 sum1 += in * in; 00121 00122 /* Decrement the loop counter */ 00123 blkCnt--; 00124 } 00125 00126 /* Compute Rms and store the result in the destination */ 00127 arm_sqrt_f32(sum1 / (float32_t) blockSize, pResult); 00128 } 00129