How to use locminima in a signal with nan values?

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 ?
Can you help please?
load 'signal'
%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:

8 Kommentare

Where exactly would you want it to find the start and end of each segment?
Tomaszzz
Tomaszzz am 19 Jul. 2022
Bearbeitet: Tomaszzz am 19 Jul. 2022
Start of each segment - first value of the signal after nans (green in the second image; I mixed up the colour in the first image))
End of each segment - first value of the signal before nans (red in the second image)
Image Analyst
Image Analyst am 19 Jul. 2022
Bearbeitet: Image Analyst am 19 Jul. 2022
Looks like you're trying to find the non-zero sections. I'm not sure why the first two "0" sections don't have starts and ends indicated. Why not?
Do you have the Image Processing Toolbox - could make it easier to find the 0 sections though you could do it with strfind(). It's a little known "trick" that strfind() works with numbers as well as character arrays.
Jonas
Jonas am 19 Jul. 2022
Bearbeitet: Jonas am 19 Jul. 2022
you can find the start and end by using
myData=[1 3 5 3 2 NaN NaN NaN 3 54 2 5 6 2 NaN NaN NaN 3 6 2 7];
ends=strfind(isnan(myData),[0 1])
ends = 1×2
5 14
starts=strfind(isnan(myData),[1 0])+1
starts = 1×2
9 18
Tomaszzz
Tomaszzz am 19 Jul. 2022
@Image Analyst thanks, maybe because the first peak is below 500, not sure
@Jonas thanks, this looks promising, I will check this out
Image Analyst
Image Analyst am 19 Jul. 2022
Bearbeitet: Image Analyst am 19 Jul. 2022
Not sure how you can be not sure. It's your data. You must know what you want, right?
Thanks Jonas for the strfind() approach. Tomas, if you still want the other approach I mentioned (with the Image Processing Toolbox), let me know. Or maybe I'll just give both anyway down in the Answers section below.
Tomaszzz
Tomaszzz am 19 Jul. 2022
Bearbeitet: Tomaszzz am 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.
@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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

William Rose
William Rose am 19 Jul. 2022

1 Stimme

Here is the script I usd to make the figure I showed in my comment. It makes two plots, samples of which are below.

2 Kommentare

Tomaszzz
Tomaszzz am 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!
@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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation of 2-D Selections in 3-D Grids finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by