Trying to synchronize data

4 views (last 30 days)
T-800
T-800 on 9 Aug 2022
Commented: T-800 on 10 Aug 2022
Hello, I am using matlab to analyze pull test (balance test) data gathered from several sensors on the body. A major issue I am dealing with is that when I try to manipulate my processed data all of my arrays are of different size. In an attempt to alleviate this I am trying to go upstream and create a loop that goes through the data in a way that links multiple key events (Center of mass start, foot land etc) such that say a Center of Mass start time is only logged if within 2 seconds a Footland is detected—along with other variables. The upstream portion of my current code, below, calculates these variables but since they lack any dependence the code generates values that have no correspondence i.e. a center of mass start event without any movement of the feet or trunk which ultimately leads to uneven arrays which can’t be properly organized in the end. I am hoping to create a code that calculates all these variables at once and only if they each have a relevant data point within say 2 seconds of each other (a pull event occurs over roughly 2 seconds). I was thinking there might be a way to create a loop with conditional statements that have a time tolerance but I’m lost on how to do that. I also attached below a file that contains the variables I am working with.
%code to acquire individual events
LevelRFA=150
FootStart_trf=FindLevel(Time, RFANet, 150)
FootStart_tRF=FootStart_trf.'%foot start time of right foot
LevelLFA=150
FootStart_tlf=FindLevel(Time, LFANet, 150)
FootStart_tLF=FootStart_tlf.'%foot start time of left foot
CombinedFootStart_t=[FootStart_tRF;FootStart_tLF]
TotFootStart_t=sort(CombinedFootStart_t, "ascend")%total foot start times
LevelCoMA=25
CoMStart=FindLevel(Time, CoMANet, 25)
CoMStart_t=CoMStart.'%Center of mass start time
LevelTA=55
TrunkStart=FindLevel(Time, TANet, 55)
TrunkStart_t=TrunkStart.'%start time of trunk movement
LevelCoMV=10
CoMEnd=FindLevel(Time, CoMVNet, 10)
CoMEnd_t=CoMEnd.'%time for end of Center of mass movement
LevelRFV=12
FootLand_trf=FindLevel(Time,RFVNet, 12)
FootLand_tRF=FootLand_trf.'%time for end for right foot movement
LevelLFV=12
FootLand_tlf=FindLevel(Time,LFVNet, 12)
FootLand_tLF=FootLand_tlf.'%time for end of left foot movement
CombinedFootLand_t=[FootLand_tRF;FootLand_tLF]
TotFootLand_t=sort(CombinedFootLand_t, "ascend")%total foot land times
Below here is the FindLevel function:
function xv = FindLevel(x,y,level)
cxi = find(diff(sign(y-level)));
for k = 1:numel(cxi)
idxrng = max(1,cxi(k)-1) : min(numel(x), cxi(k)+1);
xv(k) = interp1(y(idxrng), x(idxrng), level);
end
end
  6 Comments
dpb
dpb on 10 Aug 2022
Undoubtedly there could be, I'd think, yes...although to do so you need to get away from using all those independently-named separate variables and use either an array or, preferably, the original table programmatically so you can refer to the variables programmatically instead of by fixed name.
Then, it would seem you would find the first trigger in time across the composite of all variables to be considered as a single group and the pick up the next in sequence until whatever it is that terminates a single event or there's a nonsense "too long" parameter that limits the maximum time.
Then, select across all from that start to end time at once instead of independently.
I'd strongly suggest to pare down your number of considered variables to just a handful initially and work on the logic and algorithm there where it's small enough you can deal with it -- once that works, then you can expand it to the remainder. "Divide and conquer!"
T-800
T-800 on 10 Aug 2022
Alrighty, I'll try those recommendations when I get to my computer tomorrow.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!