1

I want to get a measure for the 'restlessness' of a signal.

I thought that the standard deviation could be right.

(In the end, I want to have a moving window over my signal, where an indicator tells me how restless my signal is. But for the beginning I just analysed some toy data over a fixed and static amount of data.)

Unfortunately, if I take some generated signals like in the example below, I can see that quite different signals result in the same value for the standard deviation.

I could imagine that a fourier transformation or a power spectrum might deliver a better indication how unsteady my signal is, but my question is: are there any other (easier to use) indicators for my use case?

The example:

import numpy as np
import matplotlib

matplotlib.use('QT5Agg')
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 1000)
y1 = np.sin(x)
print("y1.std()=", y1.std())

y2 = np.sin(10 * x)
print("y2.std()=", y2.std())


plt.plot(x,y1, '-o', markersize=2, c='r')
plt.plot(x,y2, '-o', markersize=2, c='g')
plt.grid()

plt.show()

The output:

y1.std()= 0.7067531393633848
y2.std()= 0.7067531393633849

enter image description here

user7468395
  • 919
  • 5
  • 14

1 Answers1

1

It sounds like you want a combination of "How quickly does this change" and "how much does this change". At some level the distinction is arbitrary - obviously the lines in your data are identical, just at different scales. Please note that I'm no mathematician/data scientist, and while I've had to write code to do the same thing you're trying to do, none of my suggestions are likely to be anything more than an approximation, on some arbitrary scale.


That said:

You could perhaps try some combination of stdev, and the stdev of approximations of the first- and second- derivatives.

You could also look into kalman filters, and instead of using the filtered output, just measure how far the actual value is from the filtered one.

What I actually did when I had to solve a similar problem, was, every time I got a new point, I drew a line between the previous two points, and measured the distance from the new point to that line, and just kept a rolling average-queue of those distances. It felt hacky though, so I'd probably try one of the above first.


Also, I saw this in the 'Related questions' panel, and just want to durably link them: How to efficiently calculate a running standard deviation? (The main conclusion being Welford's algorithm)

HammerN'Songs
  • 182
  • 2
  • 13