How do i separate running data?

Hey,
i have measured running on a treadmill with an integrated pressure sensor and i get an output from both the left and right foot. The thing is, i only want to use the data from the right foot, so i need a way to discard the data from the left foot and keep the right (like replacing all left foot data with 0). I'm quite new to matlab, so i have absolutely no idea how to do it. I have an idea with setting a threshold to 20 newton, and then using a counter to distinguish whenever i'm getting to the start of a new data series (it gets to zero after every step). The test protocol is made so that the first step is always the right, so figuring out which data peak is which foot, is not the problem. If this made no sense at all, please say so, and i will try to elaborate.
I've added the data file, for you to mess around with, if that is any help.
Thank you :)

 Accepted Answer

sloppydisk
sloppydisk on 7 May 2018
Edited: sloppydisk on 7 May 2018
This is actually a really fun job for a new user. Please look into logical indexing https://nl.mathworks.com/help/matlab/math/matrix-indexing.html#bq7eg38 . I actually separated your data, but it was so fun to do I wouldn't want to ruin it for you by spoiling the answer. Your data is very nice, because it's already noise-free so it should be quite doable. If you can't manage just message me and I'll send you my code.
Hint: use something like
starts = find(data(2:end)>0 & data(1:end-1)==0) + 1;
to find the start positions.

7 Comments

Malthe Bilgram
Malthe Bilgram on 7 May 2018
Edited: Malthe Bilgram on 7 May 2018
Hi Jasper!
Thanks alot for your answer. I've tried to play around with logical indexing and the hint you sent me, but i still can't get the results i wan't. So, if you're willing, i would very much like to have a look at the code you made. It would make my day :)
Here you go
load S4_pre_q_p.mat
data = Data{2};
starts = find(data(2:end)>0 & data(1:end-1)==0) + 1;
ends = find(data(2:end)==0 & data(1:end-1)>0);
feet = cell(length(starts), 1);
for i = 1: length(starts)
feet{i} = data(starts(i):ends(i));
end
firstfoot = feet(1:2:end);
secondfoot = feet(2:2:end);
Btw it's not that I wanted to withhold the code, but it's just a fun exercise. I think my code could also probably be a lot more elegant still.
Thank you for the code, though it is not quite what i had in mind :) I would like the data to be the same as it is now, just with the left foot data, removed completely (replaced with zero's etc), so that the time stamps does not get removed, since these are important for the data processing that we need to do. I have tried something myself aswell, but i cannot get it to work:
Thrs = 80;
cnt = 0;
%
% Separating data
for a = 1:length(ForceData)
if mod(cnt,2) == 0 && ForceData(a) > Thrs
RhtForce(a) = ForceData(a);
elseif mod(cnt,2) == 1 && ForceData < Thrs
RhtForce(a) = 0;
end
cnt = cnt + 1;
end
I cannot figure out what i am doing wrong in the above code, maybe you can help? I'm an 8th semester sports technology student, and the code is part of a data analysis script for some running data. We are a bit under time pressure, so any help would really be appreciated :)
Like this I assume?
Exactly what i needed! Thanks alot, you are a life saver!
You're very welcome. I noticed a small mistake though, first line in the loop should be:
firstfoot(startsFirst(i):endsFirst(i)) = 0;
Instead of
firstfoot(startsFirst(i):startsSecond(i)) = 0;
It doesn't really matter in this case because there is no noise though.
Thanks again! I'll just correct it in the script, just in case :)

Sign in to comment.

More Answers (1)

Jan
Jan on 9 May 2018
Edited: Jan on 9 May 2018
The problem is not easy. The posted file contains these values in Data{2}:
The question contains these details:
  1. "only want to use the data from the right foot"
  2. "the first step is always the right"
This means, that you want the tiny block on the left only and remove the long block on the right?
[EDITED] Ah, I've zoomed into the diagram. These are not 2 blocks only, but some hundreds of blocks.
FileData = load('S4_pre_q_p.mat');
Thresh = 20;
Sig = (FileData.Data{2} >= Thresh);
[B, N] = RunLength(Sig);
match = find(B);
B(match(2:2:end)) = false;
Mask = RunLength(B, N);
Cleaned = FileData.Data{2} .* Mask;
This sets the signal of each 2nd block above the threshold beginning with the 2nd one to 0.
If you do not have a C compiler installed, you can use the slower Matlab version RunLength_M from the same submission instead of the C-Mex version RunLength().
Maybe you want to crop the first block - then use:
B(match(1:2:end)) = false;
By the way, your signal seems like you can reduce the threshold to exactly 0.

1 Comment

Thank you for your answer Jan! The small block on the left is taps we did onto a treadmill with integrated pressure sensor, as to have something to synchronize a sound recording to this (was not possible to record it on the same system an synchronize it that way). The right part is what i'm interested in. It is all the steps done in a 1 minute and 30 second long run :) But Jasper came up with just the answer i needed, but thanks alot again for your contribution! :)

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!