Python detects alternate peaks

I have the following signal data:

schema

The signal is in RED , the average rolling value is in GRAY .

I would like to find a way to identify indices where there are consecutive positive and negative peaks around the average value inside the value.

For example, for the 0.08 mark, he will find 22, 35, 36, the second mark ...

I do not know how to detect these peaks. Has anyone already had this use case?

+5
source share
1 answer

Say you have two lists of x and y values. And you also have a list of values ​​for the moving average, but maybe this is not necessary. If you want to identify bursts, you can subtract the previous y series value to get the size of the difference between adjacent values:

 spikes = [0.0] + [abs(y[i]-y[i-1]) for i in range(1, len(y))] 

enter image description here

Then the peaks of interest to you have a value greater than 0.16 (0.08 above average, 0.08 below). You can find them like this:

 threshold = 0.08 spike_locations = [x[i] for i in range(len(spikes)) if spikes[i] > 2 * threshold] [22.0, 35.0, 36.0] 
0
source

Source: https://habr.com/ru/post/1261566/


All Articles