-
Notifications
You must be signed in to change notification settings - Fork 0
/
zcr_dtwcomparision.m
96 lines (72 loc) · 2.06 KB
/
zcr_dtwcomparision.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function [ minimum_distance,area,matrixX,matrixY,steps ] = zcr_dtwcomparision( y1,y2,Fs1,Fs2,Tw,Ts )
%DTW of ZCR and finds the area and horizontal and vertical segments
%y1 AND y2 are 2 signals and Fs1 and Fs2 are their sampling frequency,Tw-window length,Ts-window Shift
%area is the area between y=x and the minimum path curve
%matrixX and matrixY has 3 columns the length of the horizontal segment and
%starting and ending co-ordinates of the segment in other 2 columns
y1 = y1.';
N = length(y1); % signal length
n = 0:N-1;
ts = n*(1/Fs1); % time for signal
% define the window
wintype = 'rectwin';
winlen = 1323;
winamp = [0.5,1]*(1/winlen);
% find the zero-crossing rate
zc1 = zerocross(y1,wintype,winamp(1),winlen);
x=floor(length(zc1)/100)
zc1b=decimate(zc1,x);
for i=1:length(zc1b)
if zc1b(i)>.1
zc1b(i)=zc1b(i)*5;
else
zc1b(i)=zc1b(i)/50;
end
end
%time index for the ST-ZCR and STE after delay compensation
out = (winlen-1)/2:(N+winlen-1)-(winlen-1)/2;
t = (out-(winlen-1)/2)*(1/Fs1);
figure;
subplot(2,1,1);
plot(ts,y1); hold on;
plot(t,zc1(out),'r','Linewidth',2); xlabel('t, seconds');
title('Short-time Zero Crossing Rate');
legend('signal','STZCR');
y2 = y2.';
N = length(y2); % signal length
n = 0:N-1;
ts = n*(1/Fs2); % time for signal
% define the window
wintype = 'rectwin';
winlen = 201;
winamp = [0.5,1]*(1/winlen);
% find the zero-crossing rate
zc2 = zerocross(y2,wintype,winamp(1),winlen);
x=floor(length(zc2)/100);
zc2b=decimate(zc2,x);
for i=1:length(zc2b)
if zc2b(i)>.1
zc2b(i)=zc2b(i)*5;
else
zc2b(i)=zc2b(i)/50;
end
end
%time index for the ST-ZCR and STE after delay compensation
out = (winlen-1)/2:(N+winlen-1)-(winlen-1)/2;
t = (out-(winlen-1)/2)*(1/Fs2);
subplot(2,1,2);
plot(ts,y2); hold on;
plot(t,zc2(out),'r','Linewidth',2); xlabel('t, seconds');
title('Short-time Zero Crossing Rate');
legend('signal','STZCR');
%custom zcr
%
% [ zc1 ] = stzcr( y1,Fs1,Tw,Ts );
% figure
% plot(zc1);
% [ zc2 ] = stzcr( y2,Fs2,Tw,Ts );
% figure
% plot(zc2)
figure
[ minimum_distance,area,matrixX,matrixY,steps ] = dtwFeatureExtraction( zc1b,zc2b,Tw );
end