Peaks over threshold counting events
11 次查看(过去 30 天)
显示 更早的评论
Hi, I have a dataset with values with a time step of 3h. I need to find the values over a threshold i.e 7. When the value goes over 7 for some time and then down the threshold again counts as 1 event. I would like to count the number of events over that threshold for the whole data set. Attached the data: first column with the values, second column with the time.
Thanks
0 个评论
采纳的回答
Arturo Moncada-Torres
2017-9-25
Based on your requirements, I would do the following:
data = Hs_hr(:,1);
thr = 7;
% Set data smaller than threshold to 0.
data(data<thr) = 0;
% Find peaks.
[pks,locs] = findpeaks(data);
fprintf('Number of peaks found: %d', length(pks));
% Plot.
figure();
hold('on');
plot(data);
plot(locs,pks,'ro');
hold('off');
If you further wish to tune the peak detection, I recommend you read the documentation of the findpeaks function .
0 个评论
更多回答(2 个)
Guillaume
2017-9-25
If I understood correctly,
overthreshold = yourvalues > yourthreshold;
overstarts = strfind([0; overthreshold]; [0; 1]); %find starts of sequences above threshold
overends = strfind([overthreshold; 0], [1; 0]) + 1; %find ends of sequences
overlength = overends - overstarts;
eventcount = sum(overlength > yourminimumlength);
0 个评论
Andrei Bobrov
2017-9-25
编辑:Andrei Bobrov
2017-9-25
nnz(diff([0;Hs_hr(:,1)>7]));
or
nnz(filter([1,-1],1,(Hs_hr(:,1)>7)*2-1) == 2)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!