-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLPCSR_Autocorr.m
75 lines (66 loc) · 1.46 KB
/
LPCSR_Autocorr.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
% LPCSR_Autocorr Pitch estimation and voiced/unvoiced detection for an input
% sample
%
% [Tp,V] = LPCSR_Autocorr(X,pitchmin,pitchmax) computes the autocorrelation
% of input sample X to determine whether X is periodic and, if so, estimate
% its fundamental pitch period Tp in samples within the range [pitchmin,
% pitchmax]. If X is periodic, the voiced/unvoiced parameter V will be set
% to 1. If not, both V and Tp will be 0.
%
% LPC Speech Recognition Project
% ECE 529 Spring 2014
% Daniel Ford
function [Tp,V] = LPCSR_Autocorr(X,pitchmin,pitchmax)
kmin = pitchmin;
kmax = pitchmax;
N = length(X);
Rn = zeros(length(X),1);
% measure max value in X
max = X(1);
for i=1:length(X)
if X(i) > max
max = X(i);
end
end
CL = 0.3*max;
% perform clipping
for i=1:length(X)
if X(i) > CL
X(i) = 1;
else
if X(i) < -CL
X(i) = -1;
else
X(i) = 0;
end
end
end
% do autocorrelation
for k=kmin:kmax
for m=1:length(X)-k
Rn(k) = Rn(k) + X(m)*X(m+k);
end
end
% calculate Rn(0)
R0 = 0;
for m=1:length(X)
R0 = R0 + X(m)*X(m);
end
% find max R and delay k
Rmax = Rn(1); kidx = 1;
for k=1:length(Rn)
if Rn(k) > Rmax
Rmax = Rn(k); % save max R
kidx = k + kmin - 1; % save pitch period
end
end
% decide voiced or unvoiced
if Rmax > 0.1*R0 % lower creates more voiced frames
% higher values w/ unfiltered noise are good too
V = 1;
Tp = kidx;
else
V = 0;
Tp = 0;
end
end % function end