Filter löschen
Filter löschen

Define an event in a signal

12 Ansichten (letzte 30 Tage)
Peter Darrouj
Peter Darrouj am 1 Mär. 2022
Beantwortet: Peter Darrouj am 4 Mär. 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 Kommentare
John D'Errico
John D'Errico am 1 Mär. 2022
Bearbeitet: John D'Errico am 1 Mär. 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
Walter Roberson am 1 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Peter Darrouj
Peter Darrouj am 4 Mär. 2022
I fixed my problem. If anybody wonders how: here is how> comments are in dutch so you have to translate it using google translate or something.
counter = 0; % counter telt aantal metingen. begint te tellen wanneer een waarde onder de threshhold komt.
AmountOfEvents = 0; % om te kijken hoeveel event je hebt
IsEvent = false; % boolean (true/false) begint bij false omdat er ofc geen event is.
MaxValue = 0; % om de maximale value te noteren binnen een event
MaxValueEvent = [];
peakthreshhold = 400;
% bij event wordt die true en wanneer event klaar is gaat die weer false.
for i = 1:1:length(sig) %begint een loop die loopt tot einde signaal.
if (sig(i) >= peakthreshhold) % als waarde boven of gelijk aan threshhold zijn begint dit
IsEvent = true; % boolean gaat op true
counter = 0; % counter = 0 omdat je erboven
if (sig (i) > MaxValue) % als MaxValue kleiner is dan de nieuwe value , dan verander die daarin
MaxValue = sig(i);
end
else
counter = counter + 1; % als je eronder gaat begint de counter te tellen voor elke meting dat
% je eronder bent
if (counter >= 2500 && IsEvent) % als de counter op 5k zit en boolean is true dan gaat if functie in
MaxValueEvent(end+1) = MaxValue;
MaxValue = 0;
AmountOfEvents = AmountOfEvents + 1; % telt het event
counter = 0; % counter gaat weer op 0 en begint opnieuw
IsEvent = false; % boolean moet weer false
end
end
end
AmountOfEvents % melding hoeveel events er in een signaal zitten
MaxValueEvent = MaxValueEvent';

Weitere Antworten (2)

John D'Errico
John D'Errico am 1 Mär. 2022
Bearbeitet: John D'Errico am 1 Mär. 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])
startind = 1×4
4 8 14 24
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])
endind = 1×4
6 9 20 24
How long is each block?
endind - startind + 1
ans = 1×4
3 2 7 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.
  1 Kommentar
Peter Darrouj
Peter Darrouj am 1 Mär. 2022
i dont want a GUI interface that can do everything. I just want to be able to see how many events are in my signal and what the corresponding maximum value is within an event. And i get what u mean with ur tips and i have thought about this but the thing is that (because its a wave function) you will have many 0's (translating it to 0 and 1) within an event. So an event ONLY ends when X number 0 's are shown consecutively. if i make everything 0 and 1's based on a threshhold, will i be able to extract the maximum value within an event? beause if not then this option fades away in the long run.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 1 Mär. 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 Kommentare
Peter Darrouj
Peter Darrouj am 1 Mär. 2022
bwearafilt? i cant find it in the helpcenter
Walter Roberson
Walter Roberson am 1 Mär. 2022
mask = sig > peakthreshhold;
small_removed = bwareafilt(mask, [5000, inf]);
info = regionprops(small_removed, 'boundingbox');
Needs the Image Processing Toolbox.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by