0

I am quite new to programming and Python. I am working on a project in which I built an Auditory filterbank with two banks of Gammatone filters. Now I ended up with a 39x10x8545 matrix. I want to calculate the average of rms energy across the time axis (over the 8545) to reduce the dimensionality of the signal. Can anyone suggest me a better method to do it efficiently in Python because I cannot afford much memory due to the audio signal being very large. Thanks in advance.

Nikki_Champ
  • 1,047
  • 1
  • 9
  • 13

2 Answers2

1

The RMS of is signal is the root mean squared, which is not the same as the mean. So you need to perform the RMS calculation.

math.sqrt(numpy.mean(x*x))

There are several other pages on this site that discuss this in further: here, here, here

Community
  • 1
  • 1
  • Hi Dave... Thanks for the answer but as I told, I have to find a mean across the 3rd axis in 3D array.. I will give it a try anyway. – Nikki_Champ Aug 15 '14 at 14:12
  • Sure, well in python you can select the first row of a matrix with x[1,:], if its a np array, so this could be extended to whatever dimension of matrix you have. How are you building your array, as I believe the standard python array module does not support multidimensionality. – Dave Moffat Aug 15 '14 at 14:24
  • It does, I had a 39x10x8495 matrix as I said. I just used the equation you gave me to find the RMS of all the 8495 elements and then put them into a 39x10. It works, thanks to you. – Nikki_Champ Aug 16 '14 at 08:58
0

I would like to answer this question myself based on Djmoffat's answer. I tried his answer but found that the numpy.pow() gave me very slow results. So I tried using

math.sqrt(numpy.mean(x**2)) 

This gave me faster results. I understand that math.pow() is slow as it has to consider many other things like fractional powers and other things clearly discussed here. The context is important as I am sure I will have just the integer powers and more precisely '2'.

Community
  • 1
  • 1
Nikki_Champ
  • 1,047
  • 1
  • 9
  • 13