-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpitch_detector.m
64 lines (58 loc) · 1.9 KB
/
pitch_detector.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
function p1m = pitch_detector(xin,ss,es,fs,imf,L,R,n_f,window,detect_method)
% wrapper function for pitch generation
% Inputs:
% -> xin = input signal
% -> ss = starting sample
% -> es = ending sample
% -> fs = original sampling freq
% -> L = length of sample [ms]
% -> R = frame offset [ms]
% -> p = LPC model order
% -> window = frame window
% -> detect_method = method of detecting pitch per frame (0 or 1)
% Outputs:
% -> p1m = pitch period at original Fs; use to generate impulses
% -> pitch = pitch period contour at fsd=8kbit/s
% ceptsrum-based pitch detector
debug=0;
switch detect_method
case 0
% cepstrum
pitch_thresh=2.5;
len_fft=4*L;
cept_file='cepstral.mat';
[period1,period2,level1,level2]=pitch_detect_candidates(xin,fs,imf,...
len_fft,L,R,cept_file,window,debug);
case 1
% autocorrelation
pitch_thresh=1.5;
[period1,period2,level1,level2]=pitch_via_auto(xin,fs,imf,...
L,R,window,debug);
% assign 2nd most likely estimates identical to most likely estimates
% period2=period1;
% level2=level1;
end
debug=0;
if (debug)
figure(2);clf;hold on;
scatter((1:length(level1)),level1);
scatter((1:length(level2)),level2);
legend('Level 1', 'Level2');
end
% smooth pitch
% pitch_thresh=2.5;
p_smoothed=pitch_smooth(period1,period2,level1,level2,pitch_thresh);
p_smoothed_len=length(p_smoothed);
% median pitch
Lmed=5;
p1m=med_filt(p_smoothed,Lmed,length(period1));
debug=0;
if (debug)
fprintf('p1m:\n');
disp(p1m);
end
% zero pad pitch to lpc
if (p_smoothed_len < n_f)
p1m(p_smoothed_len+1:n_f)=0;
end
end