Data Extraction over threshold
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Say I have a 2000 x 4 matrix, where column 1 is a time stamp, starting at 0 and going up to 200 in steps of 0.1. In the other columns (2-4) is data for different variables. What I'm looking to do is extract data from the matrix when one variable (column 3) is over a certain threshold, I also want to extract the previous and next 100 samples from when the value goes back below the threshold again. Here's my code so far:
X = rand(100,3);
T = [0.1:0.1:10]'; % Creating a time stamp
Data = [T, X];
% Find Over Threshold of 0.8
overThresh = X(:,3) > 0.8;
SE = strel('arbitrary', ones(100,1));
extractVector=imdilate(overThresh,SE);
Event = Data(extractVector,:); %this gives a matrix with all the events together
% Using time stamp to separate events
for i = 2:length(Event)
if Event(i,1) > 2 * Event(i-1,1)
Event1 = Low_Event(1:i-1,:);
Event2 = Low_Event(i:end,:);
end
end
From the code above I'm able to collect all the events that occur and even able to separate if there is 2 events occurring. However how would I be able to separate if there is more than 2 events occurring? Plus how would I be able to name them dynamically, such as Event 1, Event 2, Event 3 etc.
The steps I'm looking my code to carry out is: 1. Detect the violation of a threshold (called an event) 2. Extract 100 samples before and after event (the end of the event being when the samples drop below the threshold again) 3. Store individual event, Event 1...
I think the best way to do this is to use the time stamp, and this is what I've done in my above piece of code. Any help would be greatly appreciated.
Edit: Ok so I done some more work on this and my code now looks like this. I'm now able to extract the 1st event. However I need to restart the for loop, to make it run again for the new Event array I created (taking Event1 away from event). Here's my code now:
X = rand(100,3);
T = [0.1:0.1:10]'; % Creating a time stamp
Data = [T, X];
% Find Over Threshold of 0.8
overThresh = X(:,3) > 0.8;
SE = strel('arbitrary', ones(100,1));
extractVector=imdilate(overThresh,SE);
Event = Data(extractVector,:); %this gives a matrix with all the events together
% Using time stamp to separate events
cc = 1; %Allows dynamic variables to be created
x = 0;
while ~x
x = 1;
for m = 2:length(Event)
if length(Event) > 0
if Event(m,1) > 2 * Event(m-1,1)
genvarname('Event', num2str(cc));
eval(['Event', num2str(cc) ' = Event(1:m-1,:);']);
Event = Event(m:end,:);
x = 0;
break
end
end
end
end
If anybody know a way to get the for loop to run again for the new Event variable please let me know
1 comentario
John BG
el 2 de Jun. de 2016
Why do you put time and signal on the same row?
Data = [T, X]
would it be possible for you to rewrite with either
Data =[T' X']
or
Data = [X;T]
or
Data = [T;X]
John
Respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!