I have the following plot (which is from a WAV file):
https://docs.google.com/file/d/0B0HeCXXvk2r5SzNpM0dvSjJ1RWM
I'd like to measure the time (the x axis) between the start of the two noisy blocks (between the 2 points where y starts being > 0.02).
I'm using FreeMat so I have no access to Matlab toolboxes.
How can i go about doing this? Thanks!
Assuming you have a vector x
with your x-values and one with your y
values, use find to find the indices of the corresponding entries in x
where the condition y > 0.2
is met.
Eg:
idx_start = find(y > 0.2, 1, 'first')
idx_end = find(y > 0.2, 1, 'last')
And then calculate the time of it:
deltaT = x(idx_end)-x(idx_start)
EDIT :: Okay I had a little missunderstanding in my answer. As I haven't got too much background information about your process and how the data may look like in another case, I'm proposing you two ways of doing it:
A) You could simply do do something like this:
idx_start = find(y > 0.2, 1, 'first')
idx_end = find(y(ceil(length(y)/2)) > 0.2, 1, 'last')
Depending on how your data looks like, ie if the second peak is always in the second half or not.
B) You could first convert every single peak into a logical vector, like this:
idx = y > 0.2
which might look like something like this:
[0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0]
And then you could search for the occurences of the pattern [0 1] in it which will yield the transition from the low to a high peak in the signal:
idx_trans = findstr([0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0],[0 1])
deltaT = x(idx_trans(1)+1)-x(idx_trans(2)+1)
which will work when there are two peaks like this and NO noise peaking over 0.2. I guess findstr also exists in freemat, if not, I found a ported code: http://www2.hawaii.edu/~ramonf/FreeMat/findstr.m
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.