# efficient way to calc RMS of 24bit samples

Question asked by pfeifferc on Nov 5, 2009
Latest reply on Dec 3, 2009 by AndreasL

Hi !

I'm looking for an efficient way to calc the RMS of a series of n-samples(24bit) with my BF537.

if have troubles to calc the sum of x^2 and store it because i need at least 64bit-and more if i have an large buffer of samples.

Is there any efficient method known?

is it better to do it by Xrms^2=mean(x)^2+stdDeviation^2 - cost me to loops?

regards chris

i have observed that define a var as unsigned long long (for u64) dont produce the wanted code to multiply two 32bit vars

or is the u64-value in debug window(locals) not correctly displayed ??

unsigned long long measureCH2=0;

int currInSample[4];

measureCH2 += currInSample[1]*currInSample[1];   /* get the square value */

produces:
[FFA01504] R2 *= R2 ;
[FFA01506] R5 = R2 >>> 31 ;
[FFA0150A] R3 = [ FP + -140 ] ;
[FFA0150E] R6 = [ FP + -136 ] ;
[FFA01512] R2 = R2 + R3 ( NS ) ;
[FFA01516] CC = AC0 ;
[FFA01518] R3 = CC ;
[FFA0151A] R6 = R5 + R6 ( NS ) ;
[FFA0151E] R3 = R6 + R3 ( NS ) ;
[FFA01522] [ FP + -140 ] = R2 ;
[FFA01526] [ FP + -136 ] = R3 ;