Search code examples
pythonarraysnumpygraphsignals

Counting the sudden change in the points Python


I would like to count how many times the graph suddenly decreases and comes back to normal. For example, here the graph suddenly decreases for 4 times.

enter image description here

Here, I only need to detect the detect sudden change(circled in red) and not the small changes(circled in black).

I actually tried with slope but it doesn't seem to work correctly

The above picture was only a small scale, the below picture shows the entire graph

enter image description here

It would be a great help for me if you answer my question. Thank you


Solution

  • I got answer to my own question. Initially, I reversed the array.

    array = numpy.max(array) - array
    

    By, reversing the array all my valley points are converted to peaks. Thus, it became easy to find peaks using scipy.signals module.

    find_peaks(array, prominence=(30 ,np.max(array)))
    

    This returned all the peak points, the length of peak points is required for me..

    Hope this question helped you.. Thank you..