-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathf_to_srvf.m
53 lines (49 loc) · 1.14 KB
/
f_to_srvf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function q = f_to_srvf(f,time,smooth,spl)
% F_TO_SRVF Convert function to Square-Root Velocity Function
% -------------------------------------------------------------------------
% Convert to SRSF
%
% Usage: q = f_to_srvf(f,time)
%
% This function converts functions to srsf
%
% Input:
% f: matrix of functions
% time: vector of time samples
% smooth: use smoothing splines (default: true)
% spl: use b-spline computation (old behavior)
%
% Output:
% q: matrix of SRSFs
arguments
f double
time double
smooth=true
spl=false
end
binsize = mean(diff(time));
[M, N] = size(f);
if smooth
fy = zeros(M,N);
for ii = 1:N
y = fit(time(:), f(:,ii),'smoothingspline');
fy(:,ii) = differentiate(y, time);
end
q = fy./sqrt(abs(fy)+eps);
elseif spl
fy = zeros(M,N);
for ii = 1:N
y = Bspline(f(:,ii),3);
ydiff = diff(y);
fy(:,ii) = ydiff(1:length(time))/binsize;
f(:,ii) = y(1:length(time));
end
q = fy./sqrt(abs(fy)+eps);
else
if size(f,2)>1
[~,fy] = gradient(f,binsize,binsize);
else
fy = gradient(f,binsize);
end
q = fy./sqrt(abs(fy)+eps);
end