Define an event in a signal
19 views (last 30 days)
Show older comments
Peter Darrouj
on 1 Mar 2022
Answered: Peter Darrouj
on 4 Mar 2022
I would like to define an event in an acoustic emission signal. I want to do this by saying that an event start when a value goes of a certain threshhold and an event stops when a value goes under the threshhold for x values in a row.
%% define event
for i = 1:1:length(sig)
if (sig(i) >= peakthreshhold)
disp("start of event");
% disp(t(i))
% while j = 5000
% if (sig(i) < peakthreshhold)
%
%
% end
% end
else
for j = 1:1:5000
end
end
i have been trying many things to get this in script but basically i dont understand how to achieve this.
So basically my event starts when value goes over the peakthreshhold and i want it to stop when 5000 values in a row do not go over the threshhold (5000 stands for 0,1 s in my signal bcs fs=50kHz). I want to define this event and at the end i want to be able to click length(event) and show me how many events are in my signal and also give me the max value per event.
2 Comments
John D'Errico
on 1 Mar 2022
Edited: John D'Errico
on 1 Mar 2022
@Peter Darrouj - Please don't post an answer just to show the code you have currently written. Moved from an answer:
i know have this:
counter = 0;
for i = 1:1:length(sig)
if (sig(i) >= peakthreshhold)
disp("start of event");
disp(t(i))
else
counter = counter + 1;
if (counter >= 5000)
disp("kleiner dan voor 5000 metingen")
disp(t(i))
counter = 0;
end
end
end
still cant distinguish event from one another and extract the amplitude but i guess its something
Walter Roberson
on 1 Mar 2022
counter = counter + 1;
if (counter >= 5000)
disp("kleiner dan voor 5000 metingen")
disp(t(i))
counter = 0;
end
Suppose you had a group that was 10000 long, then you would detect that as two 5000's in a row.
counter = 0;
for i = 1:1:length(sig)
The only situation in which you reset to 0 is if you find a group of 5000. So suppose you had data that was alternating above and below with every sample, then no "run" would be more than 1, but you would be increasing the counter each time you found an "above" so at the 5000'th chunk you would declare that you had found a run.
Accepted Answer
More Answers (2)
John D'Errico
on 1 Mar 2022
Edited: John D'Errico
on 1 Mar 2022
So, are you asking someone to teach you how to write a gui interface that will do all of this? That is a big request, and it will probably never be answered to your desires. Answers is not a forum where we write code for people on specs.
Locating an event is pretty easy. I'd call it locating the events, because you are not defining anything. But you could do that by simply using that loop, testing when the necessary conditions are satisfied.
Simpler even than using a loop, is to just create a new time series, that is 1 when the signal is above the threshold, and 0 when below. That takes one line of code to produce. Now just find all blocks of time when this secondary series is entirely 1. Discard those blocks which are of duration less then the required length. Check to see if the signal is zero for a sufficient time after that, etc.
In order to do that, you will need to learn how to identify a block of 1's in a series. That part is pretty easy. Tools like strfind will help. You will see that strfind can locate what you want, and that it works on boolean strings. For example:
STR = [0 0 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0];
startind = strfind([0,STR],[0 1])
Do you see that gives you the start point of each segment in the boolean string where it is 1? How would you find the end points?
endind = strfind([STR,0],[1 0])
How long is each block?
endind - startind + 1
You can now discard those blocks that are too short pretty easily. And knowing where the string of 1's ends, you can easily test to see if it stays below the threshold for a sufficient length of time.
But writing a complete interface takes more effort, because now you need to program mouse click interactions, etc. So DON'T DO THAT, not yet.
First, solve the simple problem. Can you locate the events of interest? Break any large problem into small ones that you can handle. So find the events. Write a code that given a time series, and a threshold, etc., will return a list of events, and their start and end times. Make sure that code works properly.
Only when that part is done, will you worry the least bit about mouse clicks. Never bite off too large of a problem for you to handle.
Walter Roberson
on 1 Mar 2022
mask = sig > peakthreshhold;
small_removed = bwearafilt(mask, [5000, inf]);
info = regionprops(small_removed, 'boundingbox');
Now info is a struct array with information about where each group starts and how big it is.
2 Comments
Walter Roberson
on 1 Mar 2022
mask = sig > peakthreshhold;
small_removed = bwareafilt(mask, [5000, inf]);
info = regionprops(small_removed, 'boundingbox');
Needs the Image Processing Toolbox.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!