How do I identify subsets of data and divide the data into the subsets
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
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 个评论
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
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')
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 个评论
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 Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!