Local Slope and Maxima of a Curve

11 views (last 30 days)
Louise on 30 Jan 2020
Answered: Star Strider on 30 Jan 2020
My experimental data are in GRF.mat. The curve shows the evolution of the ground reaction force for one step when a subject walk on a forceplate.
My aim is to determine the Value 1 and the Slope between 20% and 80% of this Value 1 (see attached image)
As I'm relative new in Matlab, I've really no idea how to define this Value 1, because this latter is not the same for each subject and each step.
Thanks in advance for your help,

Answers (2)

Image Analyst
Image Analyst on 30 Jan 2020
I'll solve the last part for you - the fitting once you know what value1 is:
s = load('grf.mat')
GroundReactionForce = s.GroundReactionForce;
x = 1 : length(GroundReactionForce);
plot(x, GroundReactionForce, 'b-', 'LineWidth', 2);
grid on;
fontSize = 20;
title('GroundReactionForce', 'fontSize', fontSize);
% Enlarge figure.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0.1, 0.2, 0.8, 0.7]);
% Find value1
value1 = GroundReactionForce(50); % Or however you do it.
% Get indexes that give the 20% and 80% of this
index1 = find(GroundReactionForce > 0.2 * value1, 1, 'first');
index2 = find(GroundReactionForce > 0.8 * value1, 1, 'first');
xline(index1, 'Color', 'r', 'LineWidth', 2);
xline(index2, 'Color', 'r', 'LineWidth', 2);
yline(GroundReactionForce(index1), 'Color', 'r', 'LineWidth', 2);
yline(GroundReactionForce(index2), 'Color', 'r', 'LineWidth', 2);
xLine = x(index1:index2)';
yLine = GroundReactionForce(index1:index2);
% Fit a line
coefficients = polyfit(xLine, yLine, 1);
% Get fitted values
yFit = polyval(coefficients, xLine);
% Plot fit.
hold on;
plot(xLine, yFit, 'k-', 'LineWidth', 4);
0000 Screenshot.png

Star Strider
Star Strider on 30 Jan 2020
This should get you started:
D = load('GRF.mat');
GRF = D.GroundReactionForce; % Column Vector
t = linspace(0,1,numel(GRF)); % Create Time Vector
[cp,m,b] = ischange(GRF, 'linear', 'Threshold',1500); % Slope Changes
idx = find(cp, 3, 'first'); % Indices For First Two Slope Changes
DM = [t(idx([1 2]))' ones(2,1)]; % Design Matrix
B = [t(idx([1 2]))' ones(2,1)] \ GRF(idx([1 2])); % Estimate Regression Parameters
RLine = DM * B; % Regression Line
slope = B(1);
Value1 = [t(idx(3)) GRF(idx(3))];
plot(t, GRF)
hold on
plot(t(idx), GRF(idx), '+r', 'MarkerSize',10, 'LineWidth',1.5)
plot(t(idx([1 2])), RLine, '-k', 'LineWidth',2)
hold off
text(median(t(idx([1 2]))), median(GRF(idx([1 2]))), sprintf('\\leftarrow Slope = %.3f', slope), 'HorizontalAlignment','left')
text(median(t(idx(3))), median(GRF(idx(3))), sprintf('\\leftarrow Value_1 = (%.3f, %.3f)', Value1), 'HorizontalAlignment','left')
Local Slope and Maxima of a Curve m- 2020 01 30.png
The ischange function was iuntroduced in R2017b. A similar function with different syntax is the Signal Processing Toolbox findchangepts (introduced in R2016a).
You may need to alter the arguments to ischange to make this robues to different records. These appear to work for this one.

Community Treasure Hunt

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

Start Hunting!

Translated by