Calculating Normalized Jerk in a signal?
조회 수: 30 (최근 30일)
이전 댓글 표시
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
Mathieu NOE
2023년 5월 4일
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
채택된 답변
Zuber
2023년 5월 9일
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:-
- https://www.mathworks.com/help/matlab/ref/trapz.html
- https://www.mathworks.com/help/matlab/ref/diff.html
I hope it resolves your query.
댓글 수: 2
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!