I want to filter a really noisy signal,so to obtain the number of peaks that cross a certain threshold. This is the matlab code I used:
thresh = 3; % Specify threshold
x = VarName1;
% Essentially need to pick out values which exceed threshold with the condition that the previous value
% needs to be below the threshold
idxl = x>=thresh;
idxl(1) = 0;
idx = find(idxl);
yest = x(idx-1)<thresh;
idx(yest) % Final output
But the value that I get is too high, and in fact when I locate in the plot the peak it identifies also the neighboring values that cross the threshold as you can see in the picture attached. But I want to count one spike for each time it crossed the threshold. Do you have any idea how can I do that? image_matlab