title: Numpy Root-Mean-Squared (RMS) smoothing of a signal
body: <p>I have a signal of electromyographical data that I am supposed (scientific papers' explicit recommendation) to smooth using RMS.</p>
  
  <p>I have the following working code, producing the desired output, but it is way slower than I think it's possible.</p>
  
  <pre><code>#!/usr/bin/python
  import numpy
  def rms(interval, halfwindow):
      """ performs the moving-window smoothing of a signal using RMS """
      n = len(interval)
      rms_signal = numpy.zeros(n)
      for i in range(n):
          small_index = max(0, i - halfwindow)  # intended to avoid boundary effect
          big_index = min(n, i + halfwindow)    # intended to avoid boundary effect
          window_samples = interval[small_index:big_index]
  
          # here is the RMS of the window, being attributed to rms_signal 'i'th sample:
          rms_signal[i] = sqrt(sum([s**2 for s in window_samples])/len(window_samples))
  
      return rms_signal
  </code></pre>
  
  <p>I have seen some <code>deque</code> and <code>itertools</code> suggestions regarding optimization of moving window loops, and also <code>convolve</code> from numpy, but I couldn't figure it out how to accomplish what I want using them.</p>
  
  <p>Also, I do not care to avoid boundary problems anymore, because I end up having large arrays and relatively small sliding windows.</p>
  
  <p>Thanks for reading</p>