Find the Threshold Threshold value in Matlab timelist data, then ignore subsequent crosses for 60 seconds before finding the next Threshold Cross
It's a little difficult to explain. I have a time series of data formatted like this: https://docs.google.com/spreadsheets/d/1B8mN0uD-t4kQr2U20gS713ZFHN6IgGB7OMR3-pqJjrw/edit?usp=sharing
This data represents voltage records at 0.01 s intervals. When built it looks like this:
Basically, I want to find the time at which the first peak occurs in each very narrow pair (i.e. at ~ .1, .75, 1.6, etc.).
The time values ββare in a separate array, but the index values ββ(row numbers) match between the two sets.
Any ideas on how to do this?
My initial attempt was something like this from the MATLAB manual
function [edges2] = risingEdge2(time, data) threshold = 0.4; offsetData = [data(2:end); NaN]; edges2 = find(data < threshold & offsetData > threshold); end
I couldn't find a good way to ignore for n seconds after the first peak ... I also get a lot more peaks than expected ... possibly due to noisy data.
source to share
For data data, the following approach seems to work.
%// Define parameters
window_size = 200;
stepsize = 0.4; %// to be used for quantizing data into three levels - 0, 0.4, 0.8
%// Perform a sliding max to get rid of the dips within the spikes
slmax_data = nlfilter(data,[window_size 1],@max);
%// Quantize sliding max data to three levels as the plot seem to suggest
quantized_slmax_data = round((slmax_data-min(slmax_data))./stepsize);
If you zoom in above, you will see ridges around the high peaks -
%// Get sliding mode to get rid of the short ledges around the high peaks
slmax_mode_data = nlfilter(quantized_slmax_data,[window_size 1],@mode);
%// Finally, find the indices where the mode data jump from 0 to 1 only, which
%// correspond to the start of spikes
index = find(diff(slmax_mode_data)==1)+window_size/2;
Output -
index = 682 8048 16487 24164 31797
source to share
Here - find all the growing edges, then find those that are very close to each other and take the first one.
rising_edges = find(diff(data > .3) > 0);
first_of_paired_edges = find(diff(time(rising_edges)) < 500);
first_rising_edge_times = time(rising_edges(first_of_paired_edges));
Then you can slide the edge to a peak.
first_peak_times = time(arrayfun( @(n) n+find(diff(data(n+[0:1000]) < 0, 1, 'first'), rising_edges(first_of_paired_edges));
source to share