python - matplotlib argrelmax doesn't find all maxes -


i have project i'm sampling analog data , attempting analyze matplotlib. currently, analog data source potentiometer hooked microcontroller, that's not relevant issue. here's code

arrayfront = runningmean(array(datafront), 15) arrayrear = runningmean(array(datarear), 15) x = linspace(0, len(arrayfront), len(arrayfront))  # generate x axis y = linspace(0, len(arrayrear), len(arrayrear))  # generate x axis min_vals_front = scipy.signal.argrelmin(arrayfront, order=2)[0]  # min min_vals_rear = scipy.signal.argrelmin(arrayrear, order=2)[0]  # min max_vals_front = scipy.signal.argrelmax(arrayfront, order=2)[0]  # max max_vals_rear = scipy.signal.argrelmax(arrayrear, order=2)[0]  # max maxvalfront = max(arrayfront[max_vals_front]) maxvalrear = max(arrayrear[max_vals_rear]) minvalfront = min(arrayfront[min_vals_front]) minvalrear = min(arrayrear[min_vals_rear]) plot(x, arrayfront, label="front pressures") plot(y, arrayrear, label="rear pressures") plot(x[min_vals_front], arrayfront[min_vals_front], "x") plot(x[max_vals_front], arrayfront[max_vals_front], "o") plot(y[min_vals_rear], arrayrear[min_vals_rear], "x") plot(y[max_vals_rear], arrayrear[max_vals_rear], "o") xlim(-25, len(arrayfront) + 25) ylim(-1000, 7000) legend(loc='upper left') show() 

datafront , datarear python lists hold sampled data 2 potentiometers. runningmean function calls:

convolve(x, ones((n,)) / n, mode='valid') 

the problem argrelmax (and min) functions don't find maxes , mins. doesn't find max or mins, , causes me problems in block of code

maxvalfront = max(arrayfront[max_vals_front]) maxvalrear = max(arrayrear[max_vals_rear]) minvalfront = min(arrayfront[min_vals_front]) minvalrear = min(arrayrear[min_vals_rear]) 

because [min_vals_(blank)] variables empty. have idea happening here, , can fix problem? in advance.

here's 1 of graphs of data not maxes , mins found:

enter image description here

signal.argrelmin thin wrapper around signal.argrelextrema comparator=np.less. np.less(a, b) returns truth value of a < b element-wise. notice np.less requires a strictly less than b true.

your data has same minimum value @ lot of neighboring locations. @ local minima, inequality between local minimum , neighbors not satisfy strictly less than relationship; instead satisfies strictly less or equal relationship.

therefore, find these extrema use signal.argrelmin comparator=np.less_equal. example, using snippet data:

import numpy np scipy import signal  arrayrear = np.array([-624.59309896, -624.59309896, -624.59309896,                       -625., -625., -625.,])  print(signal.argrelmin(arrayrear, order=2)[0]) # []  print(signal.argrelextrema(arrayrear, np.less_equal)[0]) # [0 1 3 4 5]  print(signal.argrelextrema(arrayrear, np.less_equal, order=2)[0]) # [0 3 4 5] 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -