indicating when data reaches a certain threshold

34 ビュー (過去 30 日間)
Perri Johnson
Perri Johnson 2021 年 12 月 11 日
コメント済み: Image Analyst 2021 年 12 月 12 日
Hi,
I have a data set with time in one column and force in the second column during a persons walking trial. I'm trying to establish heel contact by trying to find when rising force value crosses a specific threshold in. I would like to identify the time and force value for when the data crosses this threshold value. I'm still very knew to Matlab and havent't had any luck with using the find function or trying to threshold and could use some assistance for how I can go about establising heel strike and when the foor leaves the ground.
Thank you.

採用された回答

Image Analyst
Image Analyst 2021 年 12 月 12 日
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
lineWidth = 3;
data = readmatrix('S1C1.txt');
t = data(:, 2);
force = data(:, 3);
plot(t, force, 'b-', 'LineWidth', lineWidth)
grid on;
title('Heel Strike Forces', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Force', 'FontSize', fontSize);
threshold = 5; % Whatever...
yline(threshold, 'Color', 'm', 'LineWidth', lineWidth)
heelDownIndexes = reshape(force > threshold, 1, []); % Threshold and make into a row vector.
startingIndexes = strfind(heelDownIndexes, [0, 1]) + 1;
endingIndexes = strfind(heelDownIndexes, [1, 0]) + 1;
% Put vertical green lines at the start of the force pulse.
xline(t(startingIndexes), 'Color', 'g', 'LineWidth', lineWidth)
% Put vertical red lines at the end of the force pulse.
xline(t(endingIndexes), 'Color', 'r', 'LineWidth', lineWidth)
g = gcf;
g.WindowState = 'maximized'
  2 件のコメント
Perri Johnson
Perri Johnson 2021 年 12 月 12 日
@Image Analyst, Thank you for the help. I just got settled and about to work on my code some more from the recommendations you and @William Rose have offered.

サインインしてコメントする。

その他の回答 (4 件)

William Rose
William Rose 2021 年 12 月 11 日
FYI here's a paper on determining ground contact time.
Will get back to you on the other part.

William Rose
William Rose 2021 年 12 月 11 日
SInce you did not provide data I will provide some
data=load('grf_z_raw.txt');
t=data(:,1); y=data(:,2);
plot(t,y,'-r'); xlabel('Time (s)'); ylabel('GRF_z (N)');
It's upside down so lets flip it.
y=-y; plot(t,y,'-r'); xlabel('Time (s)'); ylabel('GRF_z (N)');
OK that's better.
tHS=min(t(y>20)); fprintf('Heel strike time=%.3f\n',tHS);
Heel strike time=0.434
OK
  1 件のコメント
Perri Johnson
Perri Johnson 2021 年 12 月 11 日
William,
Thank you, this really helps. I'm going to work on adapting this more to identify toe off as well and for more than one time when it occurs since I have multiple instances in one data set.

サインインしてコメントする。


Image Analyst
Image Analyst 2021 年 12 月 11 日
Try this to find the first time the heel gets contact:
times = data(:, 1); % Times are in column 1
force = data(:, 2); % Forces are in column 2
threshold = 0.7; % Whatever it is....
% Find first time signal exceeds threshold:
indexOfFirstHeelContact = find(force > threshold, 1, 'first');
% Get the force there
force1 = force(indexOfFirstHeelContact)
% Get the time there.
time1 = times(indexOfFirstHeelContact)
If you have multiple times where if crosses the threshold, you can use strfind() instead of find():
heelDownIndexes = force > threshold;
startingIndexes = strfind(heelDownIndexes, [0, 1]) + 1;
Attach your actual data if you still need help.
  5 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 12 日
See my other answer for a full demo.

サインインしてコメントする。


William Rose
William Rose 2021 年 12 月 11 日
Here is ground reaction force for 10 second sampled at 2.5 kHz. (Really one step, duplicated to make 10.)
clear;
data=load('grf_z_10step.txt');
t=data(:,1); y=data(:,2);
thresh=20; %detection threshold, in Y-units
jh=0; jt=0;
for i=2:length(t)
if y(i)>=thresh && y(i-1)<thresh
jh=jh+1;
ths(jh)=t(i);
elseif y(i)<thresh && y(i-1)>=thresh
jt=jt+1;
tto(jt)=t(i);
end
end
fprintf('Found %d heel strikes and %d toe offs.\n',jh,jt);
Found 10 heel strikes and 10 toe offs.
figure; plot(t,y,'-k',ths,thresh,'rx',tto,thresh,'bo');
xlabel('Time (s)'); ylabel('GRF_z (N)'); grid on
Looks good.
  4 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 12 日
@Perri Johnson, you're quite welcome, and thanks for accepting and voting for the answers to award reputation points. If you have any more questions, feel free to ask. Finding and defining peaks and valleys can be very tricky as the signal gets noisier, and it's a whole order of magnitude more difficult if you're dealing with 2-D images rather than 1-D signals.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by