# How to use locminima in a signal with nan values?

1 view (last 30 days)
Tomaszzz on 19 Jul 2022
Commented: William Rose on 21 Jul 2022
Hi all,
My signal looks like this:
My aim is to identify elements of the signal indicated by green and red circles, which are intercepted by nan values. ( beacuse this is vertical force data in newtons during repetetive jumping).
My aproach is as below:
I wonder whether this can be done without the need to replace nan values with 0 ?
%Replace nan values in force with 0
force_y_r(isnan(force_y_r))=0;
% Identify local minimas at both sides of the flat section
Lv1_right = islocalmin(force_y_r, 'FlatSelection','first', 'MinSeparation',400, 'MinProminence',500);
Lv2_right = islocalmin(force_y_r, 'FlatSelection','last', 'MinSeparation',400, 'MinProminence',500);
start_location_r = find(Lv2_right);
end_location_r = find(Lv1_right);
%Plot
x_right = 1:numel(force_y_r);
figure
plot(x_right, force_y_r);
hold on
plot(x_right(end_location_r), force_y_r(end_location_r), '^r');
plot(x_right(start_location_r), force_y_r(start_location_r), '^g');
ylabel('Right leg - Force y (N)'); xlabel('Time (samples)');
legend('signal', 'cycle end','cycle start');
hold off
Results in:
Tomaszzz on 19 Jul 2022
Edited: Tomaszzz on 19 Jul 2022
Not sure exactly how locminima works. I have changed minprominence to 400 and it indeed found the first two, although weirdly it omitted two first ''cycle end".
I have image processing toolbox, but I think the suggestion from @Jonas is something I can explore further. For example as in the image below;
Although it tends to idenitfy more than 1 ends or starts depending how signal looks like, for example as in the image below. I would usually apply Butterworth filter to smooth the signal in advance however not sure how to apply the filter on a signal with nans.
William Rose on 19 Jul 2022
@Tomaszzz, is it your goal to get time of flight for each jump? Or is it the case that you want the vertical GRF while on the ground, for each segment between jumps? If you had those segments, then you could average them, as we discussed for your walking data in a separate discussion.
Interesting that your forceplate software returns NaNs instead of zero when the subject is airborne. I haven't seen that.
ANalysis of your data is complicated by teh extistence if microgaps in the recording. That is, there are sometimes gaps of one to three points on the shoulders of the takeoffs and landings. For example, see the figure below which shows the landing of the fourth jump. There is numeric data at samples 9710, 9712, 9714 & following. The bue lines and dots are the file data. The magenta lines and dots are data I filled in by linear interpolaiton. The green and red triangles are the start and end points of segments of numeric data.

William Rose on 19 Jul 2022
Here is the script I usd to make the figure I showed in my comment. It makes two plots, samples of which are below.
Tomaszzz on 20 Jul 2022
@William Rose Hi William. Many thanks for your continued support.
Correct, I want the vertical GRF while on the ground, for each segment between jumps. The code you provided seems to be working very well for the data I have - particularly regarding the issue with the microgaps which is the case for many partcipants. Glad to learn this could be fixed with linear inerpolation as you showed above. The code might actually be useful for another activity where I collected GRFs i.e. sit to stand test where there is not much load placed on the plates while sitting which results in gaps with nan values as well.
Thanks again for your detailed feedback!
William Rose on 21 Jul 2022
@Tomaszzz, you are welcome.
My script would probably need adjustment if the recording starts or ends in the middle of a jump (i.e. if the recording begins or ends with NaNs). If the recording begins with NaNs, then the first marker would be green, not red, and you'd need to adapt "i" versus "i+1" or "i-1" in the loops. If the recordings ends, but does not start, with NaNs, then there will be one more red marker than green. That might cause an issue on the last loop pass.
With the recording you sent, those issues do not arise. It actually looks like you have a complete, or almost complete, inter-jump vertical GRF at the start, and another at the end. Since the first is not preceded by NaNs, it is not identified as a segment by my script. The same for the last one, which does not end with NaNs. If you want to include those segment in your analysis, you can add NaNs to the file at the start and end, so those segments would get identified by the script, and then you'd need to make adjustments to the script, as noted above.
Good luck.