Borrar filtros
Borrar filtros

Plot change in velocity

19 visualizaciones (últimos 30 días)
alexandra ligeti
alexandra ligeti el 3 de Abr. de 2024
Comentada: Mathieu NOE el 3 de Abr. de 2024
Hi again,
I am now wanting to slightly alter my Bland-Altman curve, to be able to determine whether velocity causes larger errors.
I have my average data and would like to calcualte the change in mean angle over percentage gait cycle as follows:
delta angle = (mean data (i +1) - mean data (i - 1) ) / 0.02.
I have 101 data points, but the issue comes when I want to calculate the angular change in giat cycle percentage for the first data point.
Mean data is the average angle measured in the gait cycle and so I am wanting to take a point in the gait cycle, move to the point in front of it (+1%), then to the point behind it (-1%) to calculate the velocity, and divide by 2% of the giat cycle etc etc for the entire gait cycle.
I am having problems calculating delta angle.
I then want to plot delta angle against difference.
%% Angular velocity per gait cycle percentage
figure()
for a = 0
delta_angle(a,1) = ((mean_data(a+1)- mean_data(a-1))/0.02);
end
plot(delta_angle, mean_diff)
xlabel('Change in mean angle/ gait cycle percentage')
ylabel('Difference (deg)')
If this does not make sense please let me know.
Thanks in advance

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 3 de Abr. de 2024
hello again
we could use gradient or the function provided below
then all vectors are of same size (101 samples) which allows you to do :
(NB : no need for the for loop)
delta_angle = gradient(mean_data)/0.02;
or
[dy, ddy] = firstsecondderivatives((1:numel(mean_data)),mean_data);
delta_angle = dy/0.02;
(I prefer the second option as it seems the end points are better handled)
% gradient of firstsecondderivatives ?
[dy, ddy] = firstsecondderivatives((1:numel(mean_data)),mean_data);
figure(1),
plot(gradient(mean_data))
hold on
plot(dy)
legend('gradient','function')
%%%%%%%%%%%%%%%%
function [dy, ddy] = firstsecondderivatives(x,y)
% The function calculates the first & second derivative of a function that is given by a set
% of points. The first derivatives at the first and last points are calculated by
% the 3 point forward and 3 point backward finite difference scheme respectively.
% The first derivatives at all the other points are calculated by the 2 point
% central approach.
% The second derivatives at the first and last points are calculated by
% the 4 point forward and 4 point backward finite difference scheme respectively.
% The second derivatives at all the other points are calculated by the 3 point
% central approach.
n = length (x);
dy = zeros;
ddy = zeros;
% Input variables:
% x: vector with the x the data points.
% y: vector with the f(x) data points.
% Output variable:
% dy: Vector with first derivative at each point.
% ddy: Vector with second derivative at each point.
dy(1) = (-3*y(1) + 4*y(2) - y(3)) / (2*(x(2) - x(1))); % First derivative
ddy(1) = (2*y(1) - 5*y(2) + 4*y(3) - y(4)) / (x(2) - x(1))^2; % Second derivative
for i = 2:n-1
dy(i) = (y(i+1) - y(i-1)) / (x(i+1) - x(i-1));
ddy(i) = (y(i-1) - 2*y(i) + y(i+1)) / (x(i-1) - x(i))^2;
end
dy(n) = (y(n-2) - 4*y(n-1) + 3*y(n)) / (2*(x(n) - x(n-1)));
ddy(n) = (-y(n-3) + 4*y(n-2) - 5*y(n-1) + 2*y(n)) / (x(n) - x(n-1))^2;
end
  5 comentarios
Mathieu NOE
Mathieu NOE el 3 de Abr. de 2024
it's my own interpretation, but we could pick for both curves their 4 peaks and then trace the values of one set of peaks vs the other set ?
Mathieu NOE
Mathieu NOE el 3 de Abr. de 2024
here I plotted the 4 peaks belonging to both datas sets. Of course the x indexes don't match but we consider that as "non problematic" (??)
assuming this is not pure nonsense, then If I plot only the the peaks of abs(diff data) vs the peaks of Abs(dy), maybe there is a kind of almost linear trend that appears :
[dy, ddy] = firstsecondderivatives((1:numel(mean_data)),mean_data);
delta_angle = dy/0.02;
x = 1:numel(delta_angle);
% delta_angle
y1 = abs(delta_angle);
y1 = y1./max(y1);
tf1 = islocalmax(y1,'MinSeparation',10);
x1_peaks = x(tf1);
y1_peaks = y1(tf1);
% diff_data
y2 = abs(diff_data);
y2 = y2./max(y2);
tf2 = islocalmax(y2,'MinSeparation',10);
x2_peaks = x(tf2);
y2_peaks = y2(tf2);
figure,
plot(x,y1)
hold on
plot(x,y2)
plot(x1_peaks,y1_peaks,'db')
plot(x2_peaks,y2_peaks,'dr')
legend('normalized delta angle','normalized diff data','normalized delta angle peaks ','normalized diff data peaks');
% now use tf1 and tf2 logical indexes on the raw (non normalized ) data
figure,
[xx,ind] = sort(abs(dy(tf1)));% use sort to avoid zig zags in plot
yy = abs(diff_data(tf2));
yy = yy(ind);
plot(xx, yy,'-*')
title('Abs(diff data) vs. Abs(dy)')
xlabel('Abs(dy)')
ylabel('Abs(diff data)')

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by