How do I identify subsets of data and divide the data into the subsets

조회 수: 4 (최근 30일)
Bill P
Bill P 2018년 12월 13일
댓글: Chris Turnes 2019년 1월 8일
Right now I have code that takes data from two IMU's attached to each side of a knee joint and finds the angle in the knee while someone performs a squat. The Output is the angle on each plane between the two IMUs (the main one I am concerned with is the blue line which is the angle assuming the knee can only rotate on one axis). Plot attached.
I am wondering how I can identify and divide the data so I can analyze each "Repitition" of the exercise on its own. In the plot attached there would be three seperate repetitions I would want to look at.
joint_angle.jpg

답변 (2개)

Mark Sherstan
Mark Sherstan 2018년 12월 13일
편집: Mark Sherstan 2018년 12월 13일
Look at the function islocalmin and islocalmax. You can specify minimum prominence to filter out some of the noise at the bottom of your data to get just one minimum or one maximum for each of the trials. Your data looks fairly good so you might be able to just find the time each minimum happens and divide it by 2 to get that range and analyze accordingly.
If you post a .mat file with your data I could help to implment the functions.
  댓글 수: 2
Bill P
Bill P 2018년 12월 13일
Hi Mark, thanks for the response. I want to be able to capture and analyze if each repition takes a different length of time, or if there is a hiccup (someone faltering on the way up or down), an example being following (i took out the unnecessary other traces):
Joint Angle Test 5.jpg
Would the local min and max work in this scenario? .mat file of angle and time for this example attached
Mark Sherstan
Mark Sherstan 2018년 12월 14일
Here you go :) Let me know if you have any questions (code is commented).
% Load in data and clear out start and end noise manually
load('Joint Angle and Time.mat')
jointAngle(1:600) = 0;
jointAngle(3560:end) = 0;
% Locate only the minimums (start and end of a cycle)
jointAngle2 = jointAngle;
jointAngle2(jointAngle2>10) = NaN;
idx = islocalmin(jointAngle2,'FlatSelection','all','MinSeparation',100);
idx = find(idx);
% Seperate out the data
ii = 1;
for jj = 1:2:length(idx)-1
out.jointAngle{ii} = jointAngle(idx(jj):idx(jj+1));
out.time{ii} = time(idx(jj):idx(jj+1));
ii = ii + 1;
end
% Plot the results
figure(1)
hold on
plot(time,jointAngle)
plot(time(idx),jointAngle(idx),'*r')
legend('Data','Seperation Points')
hold off
figure(2)
for ii = 1:length(out.time)
subplot(2,2,ii)
plot(out.time{ii},out.jointAngle{ii})
title(num2str(ii),'FontSize',16)
end
1.png
2.png

댓글을 달려면 로그인하십시오.


Chris Turnes
Chris Turnes 2018년 12월 17일
Mark's answer is a great way of doing this. In addition, you might consider looking at the ischange function:
% Look for at most 9 changes, since there are 4 segments of interest and 5 other segments
tf = ischange(jointAngle, 'SamplePoints', time, 'MaxNumChanges', 9);
plot(time, jointAngle, time(tf), jointAngle(tf), '*r')
JointAngle.png
This doesn't give you exactly the same results, as it basically finds the middle points of the rising and falling edges. But if all you need is to analyze the widths relative to each other, then it might also work.
To make it more robust, you could instead use the Threshold option from ischange:
% Use the threshold factor to find changes instead
tf = ischange(jointAngle, 'SamplePoints', time, 'Threshold', 1e5);
It's a bit harder to intuitively guess that the value for Threshold should be, but if you find a good one that works, it will (hopefully) work across multiple traces.
  댓글 수: 4
Bill P
Bill P 2019년 1월 8일
The detections would need to be at the minima if possible
Chris Turnes
Chris Turnes 2019년 1월 8일
You can try telling ischange to look for piecewise linear changes rather than piecewise constant changes. This gets a bit closer, I think:
tf = ischange(jointAngle, 'linear', 'SamplePoints', time, 'Threshold', 1e4);
If that's not quite precise enough, then Mark's approach may be the better option for you. Or, perhaps you could mix the two; but I don't think there's anything built-in that makes this task particularly simple.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by