-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcSTZCR.asv
58 lines (40 loc) · 1.36 KB
/
calcSTZCR.asv
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
%Tavas, Romelio Jr. 2011-11218
%Gomez, Emilio Vicente 2009-22091
%HONOR CODE
%I do hereby affirm, on my honor as a student at the end of this exam, that
%I had no unlawful knowledge of the questions or answers prior to this
%exercise and that I have neither given nor received assistance in answering
%any of the questions during this exam.
function Z = calcSTZCR(sig,l,ovrlp,window_type)
%calcSTZCR
% Computes the short time zero crossing rate
%
% USAGE: Z = calcSTZCR(sig,l,ovrlp,window_type)
% INPUT: sig = input signal vector
% l = length of window
% ovrlp = window overlap
% window_type = 'rectwin' or 'hamming'
% OUTPUT: Z = zero crossing rate
Ns = max(size(sig));
%construct window depending on window_type
% if(strcmp(window_type,'Rectangular'))
% window = rectwin(window_len);
% elseif (strcmp(window_type,'Hamming'))
% window = hamming(window_len);
% end
wndw = window(window_type,l);
% Framing and windowing of the signal
sig_framed = buffer(sig, l, ovrlp, 'nodelay');
sig_windowed = diag(sparse(wndw)) * sig_framed;
disp(size(sig_windowed));
cols = size(sig_windowed,2);
padding = zeros(1,cols);
sig_windowed = vertcat(sig_windowed,padding);
Z = zeros(cols,1);
for i = 1:cols
for j = 1:l
x = abs(sig_windowed(j+1,i)-sig_windowed(j,i))/(2*l);
end
Z(i) = sum(x);
end
end