-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathelastic_depth.m
71 lines (63 loc) · 1.92 KB
/
elastic_depth.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function [amp, phase] = elastic_depth(f, time, lambda, parallel)
% ELASTIC_DISTANCE Calculates the elastic depth between
% functions
% -------------------------------------------------------------------------
% This functions calculates the depth between a set of functions
%
% Usage: [dy, dx] = elastic_depth(f1, f2, time)
% [dy, dx] = elastic_depth(f1, f2, time, lambda)
%
% Input:
% f: matrix of M time points of N functions, e.g., MxN
% time: vector of size \eqn{N} describing the sample points
% lambda controls amount of warping (default = 0)
%
% Output
% amp: amplitude depth
% phase: phase depth
if nargin < 3
lambda = 0;
parallel = 1;
elseif nargin < 4
parallel = 1;
end
if parallel == 1
if isempty(gcp('nocreate'))
% prompt user for number threads to use
nThreads = input('Enter number of threads to use: ');
if nThreads > 1
parpool(nThreads);
elseif nThreads > 12 % check if the maximum allowable number of threads is exceeded
while (nThreads > 12) % wait until user figures it out
fprintf('Maximum number of threads allowed is 12\n Enter a number between 1 and 12\n');
nThreads = input('Enter number of threads to use: ');
end
if nThreads > 1
parpool(nThreads);
end
end
end
end
N = size(f,2);
% compute the pairwise distance
phs_dist = zeros(N,N);
amp_dist = zeros(N,N);
parfor i = 1:N
for j = i:N
[da, dp] = elastic_distance(f(:,i),f(:,j),time,lambda)
% y-distance
amp_dist(i,j) = da;
% x-distance
phs_dist(i,j) = dp;
end
end
amp_dist = amp_dist + amp_dist.';
phs_dist = phs_dist + phs_dist.';
amp = 1 ./ (1 + median(amp_dist, 1));
phase = 1 ./ (1 + median(phs_dist, 1));
phase = ((2+pi)/pi) .* (phase - 2/(2+pi));
if parallel == 1
if isempty(gcp('nocreate'))
delete(gcp('nocreate'))
end
end