Can you suggest a module function from numpy/scipy that can find local maxima/minima in a text file? I was trying to use the nearest neighbours approach, but the data fluctuations cause false identification. Is it possible to use the neighbour's approach but use 20 data points as the sample_len.
Asked
Active
Viewed 225 times
0
-
The local minima of a reading that is has been saved in a text file each reading device has its own column – nyrangers705 Apr 26 '20 at 22:39
-
The recordings have a local min before a spike but then they fall back or bellow that min so I can’t just use a normal min() function – nyrangers705 Apr 26 '20 at 22:45
-
Does this answer your question? [Finding local maxima/minima with Numpy in a 1D numpy array](https://stackoverflow.com/questions/4624970/finding-local-maxima-minima-with-numpy-in-a-1d-numpy-array) – John Coleman Apr 26 '20 at 22:49
-
No that’s what I was looking at but it doesn’t work because there to many false identifications of Minima – nyrangers705 Apr 26 '20 at 22:50
-
There were multiple answers, did all of them fail? If so, perhaps you could edit the question so as to differentiate this from that since from my perspective this seems like a duplicate question, albeit one for which you are unhappy with the existing answers. – John Coleman Apr 26 '20 at 22:53
-
None of them work because they all use one point to determine if the neighbor is larger or smaller, I am looking to use a sample size of 20 points to determine if that larger or smaller then the next 20 points – nyrangers705 Apr 26 '20 at 22:55
-
Also, [this answer](https://stackoverflow.com/a/40765769/4996248) to that question recommends a signal-processing function that smooths the vector in a tweakable way. It seems specifically designed to deal with noise (which seems to be your issue). – John Coleman Apr 26 '20 at 23:12
-
You applied *neighbour approach* with 20 samples on either side to do the averaging/smoothing ? it depends on your signal if you want to use 20. For some signals,smaller or larger value is to be used. If you have many spikes, long averaging will just filter out spikes and cause your algorithm to miss subsequent spikes. Averaging methods work best when you have a slowly changing signal with noise. With spikes, you add an amplitude threshold, and use averaging with a much shorter window (e.g. try 3 or 4). When you have a slow signal with noise, use a longer window. – Goodies Apr 27 '20 at 00:02
1 Answers
0
scipy.signal.argrelmax
looks for relative maxima in an array (there is also argrelmin
for minima). It has the order
keyword argument which allows you to compare eg. 20 neighbours.

Paddy Harrison
- 1,808
- 1
- 8
- 21