python - Detecting regions in (x, y) data -


i need able detect regions of list of (x, y) data based on features of data. example data shown in first image. right now, need able find region between black marks (sorry poor quality, imgur's editor isn't accurate). unfortunately, problem complicated being different lengths , shapes each time data collected, seen in second image. sharp drop ~98 ~85 consistent, , 2 dip/two peak feature between ~1e-9 , ~1.5e-9 should consistent.

my question is, best approach detecting events in signal, based on features of signal? if can sliced 3 regions marked (beginning first mark, first second mark, second mark end), believe can extend method handle more complex situations.

i've solved similar problems before, 1 unique in amount of variation occurs 1 set of data another. last time wrote hand-crafted algorithm find local extrema , use locate edge, feel it's rather ugly , inefficient solution can't reused.

i'm using python 2.7.5, ideally should language agnostic solution can implement in other environments vb.net.

img1

img2

just based on 2 examples posted, have couple of different suggestions: thresholding or template matching.

thresholds

because mentioned vertical drop in signal relatively constant, first event you're detecting, seems use thresholding method, place event @ first occurrence of signal crossing threshold of interest. instance, place first event (in python, , assuming measurement data live in sequence of tuples containing x-y pairs) :

def detect_onset_event(measurements):     armed = false     offset, (timestamp, value) in enumerate(measurements):         if value > 90:             armed = true         if armed , value < 85:             return offset     return -1  # failure condition, might want raise valueerror() 

so here trigger @ first sample offset drops below 85 after signal has gone above 90.

you similar second event, looks signal levels significant event might little less clear-cut. depends on application , measurement data. example of makes thresholding approaches not great -- can brittle , rely on hard-coded values. if measurements quite regular, can work well, little coding effort.

templates

in method, can create template each signal event of interest, , convolve templates on signal identify similar regions of signal.

import numpy  def detect_twopeak_event(measurements, template):     data = numpy.asarray(measurements) # convert numpy array     activations = numpy.convolve(         data[:, 1],  # convolve on "value" elements         template)     return activations.argmax() 

here you'll need create list of sample measurements constitute event you're trying detect -- example, might extract measurements two-peak area of example signal use template. convolving template on measurement data, you'll metric how similar measurements template. can return index of best match (as in code above) or pass these similarity estimates other process pick "best."

there many ways create templates, think 1 of promising approaches use average of bunch of neighborhoods labeled training events. is, suppose have database of signals paired sample offset given event happens. create template averaging windowed region around these labeled events :

def create_mean_template(signals, offsets, radius=20):     w = numpy.hanning(2 * radius)     return numpy.mean(         [s[o-radius:o+radius] * w s, o in zip(signals, offsets)],         axis=0) 

this has been used in many signal processing domains face recognition (e.g., can create template eye averaging pixels around bunch of labeled eyes).

one place template approach start fail if signal has lot of areas template, these areas don't correspond events want detect. it's tricky deal this, template method works best if there's distinctive signal pattern happens near event.

another way template method fail if measurement data contain, say, two-peak area that's interesting occurs @ different frequency samples use template. in case, might able make templates more robust slight frequency changes working in time-frequency domain rather time-amplitude domain. there, instead of making 1d templates correspond temporal pattern of amplitude changes you're interested in, can run windowed fft on measurements , come kd templates correspond k-dimensional frequency changes on small region surrounding event you're interested in.

hope of these suggestions helpful !


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -