Numpy Root-Mean-Squared (RMS) smoothing of a signal

后端 未结 3 1692
一整个雨季
一整个雨季 2020-12-28 19:50

I have a signal of electromyographical data that I am supposed (scientific papers\' explicit recommendation) to smooth using RMS.

I have the following working code,

3条回答
  •  感动是毒
    2020-12-28 20:33

    Since this is not a linear transformation, I don't believe it is possible to use np.convolve().

    Here's a function which should do what you want. Note that the first element of the returned array is the rms of the first full window; i.e. for the array a in the example, the return array is the rms of the subwindows [1,2],[2,3],[3,4],[4,5] and does not include the partial windows [1] and [5].

    >>> def window_rms(a, window_size=2):
    >>>     return np.sqrt(sum([a[window_size-i-1:len(a)-i]**2 for i in range(window_size-1)])/window_size)
    >>> a = np.array([1,2,3,4,5])
    >>> window_rms(a)
    array([ 1.41421356,  2.44948974,  3.46410162,  4.47213595])
    

提交回复
热议问题