Calculating Normalized Jerk in a signal?

30 Ansichten (letzte 30 Tage)
FsC
FsC am 3 Mai 2023
Kommentiert: Jak am 17 Jul. 2023
Hello,
I am trying to calculate the normalized jerk of a signal using a specific formula but am unsure how to implement it using MATLAB.
I have a signal (1x N array of positive values) that changes position across time (sampling frequency is 60 Hz). From this I am trying to calculate the normalized jerk using the following equation:
where jerk is the third derivative of the position as a function of time, stroke duration is the total time the stroke takes from strart to finish and stroke length is the total distance of the stroke from start to finish (in this case Euclidean Distance)
I am especially confused on how to implement the integral and jerk components of the equation.
Do you know how to implement the equation in MATLAB?
  1 Kommentar
Mathieu NOE
Mathieu NOE am 4 Mai 2023
hello
have you started a code ? where is the biggest hurdle ?
to differentiate a signal you can use either diff , gradient or the function firstsecondderivatives code provided below
to do the integral you can use trapz
read the doc and you should be able to putthe puzzle together
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Zuber
Zuber am 9 Mai 2023
Hi,
I understand that you want to implement the specified equation in MATLAB for calculating normalized jerk. Let the signal (1xN array) which represents position as a function of time denoted by ‘s’. The ‘diff’ function can be used to calculate the jerk as follows: -
freq = 60 % sampling frequency
dt = 1/freq; % time interval between samples
first_der = diff(s)/dt % first derivative of signal ‘s’
sec_der = diff(first_der)/dt % second derivative of signal 's’
jerk = diff(sec_der)/dt % third derivative of signal ‘s’
Further, the integral can be evaluated using ‘trapz’ function. Overall, the equation can be implemented in MATLAB as follows:-
integrand = dt * jerk.^2;
nj = sqrt(0.5 * trapz(integrand) * (StrokeDuration^5 / StrokeLength^2));
For more information on ‘trapz’ and ‘diff’ functions, please refer to the following documentation links:-
  1. https://www.mathworks.com/help/matlab/ref/trapz.html
  2. https://www.mathworks.com/help/matlab/ref/diff.html
I hope it resolves your query.
  2 Kommentare
FsC
FsC am 9 Mai 2023
amazing! Thank you!
Jak
Jak am 17 Jul. 2023
Hi, how did you account for the (t) in dt jerk^2 (t)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by