-
Notifications
You must be signed in to change notification settings - Fork 0
/
casestudy1.m
executable file
·70 lines (62 loc) · 2.19 KB
/
casestudy1.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
% case study 1.
clc;clear all;close all;
load testdata;
[M,i] = max(size(ref));
if i ~= 1;ref = ref';end
[N,i] = max(size(target));
if i ~= 1;target = target';end
subplot(311);ylim([0 0.1])
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
% simple interpolation
target_s = interp1(linspace(1,N,N),target,linspace(1,N,M)');
plot(target_s,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
legend('Reference','Target','Warped');
title('Interpolation');
ylim([0 0.1]);xlim([50 300]);
subplot(312);
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
[Dist, D,k,w,target_s] = dtw(ref,target,0);
plot(target_s,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
title('Dynamic Time Warping (unconstrained)');
ylim([0 0.1]);xlim([50 300]);
subplot(313);ylim([0 0.1])
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
[Dist,D,d,k,w,target_s] = LCdtw(ref,target,ones(numel(ref),numel(target)),2,0);
plot(target_s,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
title('Dynamic Time Warping (with slope constraint (0.5,2))');
ylim([0 0.1]);xlim([50 300]);
%%
figure;
subplot(311);ylim([0 0.1])
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
% apply my warping method
warped_result = mywarping(ref,target,[150],[250],0);
target_s = warped_result.tww;
plot(target_s,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
legend('Reference','Target','Warped');
title('Proposed Warping Method');
ylim([0 0.1]);xlim([50 300]);
subplot(312);
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
[Warping, target_s] = cow(ref',target',10,5,[0 1 1 0 0]);
[Warping, target_s2] = cow(ref',target',20,10,[0 1 1 0 0]);
plot(target_s,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
title('Correlation Optimized Warping (Segments = 10, slack = 5)');
ylim([0 0.1]);xlim([50 300]);
subplot(313);
plot(ref,'-','LineWidth',1.5);hold on;plot(target,':r','LineWidth',0.5);
plot(target_s2,':g','LineWidth',1.5)
xlabel('Time');
ylabel('Amplitude');
title('Correlation Optimized Warping (Segments = 20, slack = 10)');
ylim([0 0.1]);xlim([50 300]);