Matlab: Count values if signal changed for 0.1 in the last 2 seconds -


i have continuous signal rising , falling. found peaks- maxima values , locations.

i wondering how write code count in case signal changed in kind of rule: amplitude exceeded 0.1 , peak occurred less 2 seconds after beginning of increase.

thanks lot.

a general answer be: loop through peak vector , check appropriate part of value vector smallest element:

for = 1:len(peaks)     peak = peaks(i,:)     peak_value = peak[1]     peak_time = peak[2]     cut_values = values(max(1,(peak_time-2)*f):peak_time*f)     if min(cut_values) < peak_value - 0.1             peak_count += 1 % or 

edit - adding explanation:

peaks matrix (nx2) of peak values , times

values signal vector

f sampling frequency (hz), considered uniform

edited again accomodate peaks before 2s.

matlab's 1-indexing bit tricky here: sample 1 @ time 0, sample 2 @ time f. correct thing signal starts @ 0 time is:

    cut_values = values(max(0,(peak_time-2)*f)+1:peak_time*f+1) 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -