zinon
zinon

Reputation: 4664

How to get the correct peaks and troughs from an 1d-array

We are trying to find peaks and troughs from an 1d-array.

We are using the numpy.r_() and it finds every peak and trough from an array but we want only the peaks and troughs that correspond to relaxation and contraction points of diaphragmatic motion.

Is there any function that rejects the wrong min and max points?

See a bad example below:

enter image description here

Upvotes: 4

Views: 3841

Answers (1)

user6655984
user6655984

Reputation:

You have high-frequency, small-amplitude oscillations that are undesirable for peak finding purposes. Filter them out prior to searching for peaks. A simple filter to use is 1-dimensional Gaussian from scipy.ndimage. On the scale of your chart, it seems that

smooth_signal = ndimage.gaussian_filter1d(signal, 5)

should be about right (the window size should be large enough to suppress unwanted oscillation but small enough to not distort actual peaks). Then apply your peak finding algorithm to smooth_signal.

The signal processing module has more sophisticated filters, but those take some time to learn to use.

Upvotes: 4

Related Questions