indicating when data reaches a certain threshold
35 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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'
その他の回答 (4 件)
William Rose
2021 年 12 月 11 日
FYI here's a paper on determining ground contact time.
Will get back to you on the other part.
0 件のコメント
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);
OK
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
2021 年 12 月 11 日
Try this:
heelDownIndexes = reshape(force > threshold, 1, []); % Threshold and make into a row vector.
startingIndexes = strfind(heelDownIndexes, [0, 1]) + 1;
If you need to get rid of small noise regions that are too short to be legitimate, you can use bwareaopen() to get rid of runs less than a certain number of indexes long. Again, if you need more help, attach your data.
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);
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
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.
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!