Trying to synchronize data

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 个评论

OK, presuming OV in the .mat file is the various variables, what out of that are you trying to separate?
OV just stands for original variable and Im just using it to read in table data. Rather I have the following individual variables: TotFootStart_t, CoMStart_t, TrunkStart_t, TrunkEnd_t(same as CoMEnd_t) CoMEnd_t, and TotFootLand_t which the above code calculates (I realize I didn't directly attach those variables so they are below-apologies). The issue is these arrays aren't all the same size as there are some false hits. For example the total number of time entries for the start of center of mass movement(167) is nearly double the number of detected center of mass end times(93). What I'm hoping to do is extract only those points from each of these key variables such that they correspond to the correct pull. Later in my code I have to do some operations like finding the difference between the start and end of COM movement and it would be bad if the start corresponded to the 5th pull motion and the end corresponded to the 8th. So for X pull I want to get all the correct corresponding key variables while excluding false hits.
How did you get those other variables to start with -- are they not selected from the various OV data? Make sure you select simultaneous sets of data to start with instead of trying to piece something back together again.
I have an overall table of position data for the center of mass, feet, and trunk in the three dimensions which I assign the variable name OV. I then differentiate everything to acquire velocities and accelerations both in the three dimensions as well as the net values. Up to this point all the data points/arrays are the same length even though each variable is assigned its own array. The trouble starts when I try to use the FindLevel function above. This function approximates the time (x) at which a line crosses a certain y threshold (such as 150 for the feet acceleration plots). With the different thresholds for the plots and inclusion of non matching nonsense values this results in separate output arrays that have varying lengths. Would there be a way to make the above function run through all of these arrays (TVNet, CoMANet etc) at once and produce say a matrix of values with a tolerance to incorporate lagging times (feet move slightly after the chest starts moving when pulled from the shoulders for a given pull) while filling missing values with NAN so I can erase these rows?
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!"
Alrighty, I'll try those recommendations when I get to my computer tomorrow.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品

版本

R2022a

提问:

2022-8-9

评论:

2022-8-10

Community Treasure Hunt

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

Start Hunting!

Translated by