Dawn@4
|
1 function [SHR,F0]=func_GetSHRP(y,Fs, variables, datalen)
|
Dawn@4
|
2 %function [f0_time,f0_value,SHR,f0_candidates]=func_GetSHRP(y,Fs,F0MinMax,timestep,SHR_Threshold)
|
Dawn@4
|
3 % Input: y, Fs - from wavread
|
Dawn@4
|
4 % variables - settings from initialization/setting
|
Dawn@4
|
5 % datalen - output data length
|
Dawn@4
|
6 % Output: F0 - F0 values
|
Dawn@4
|
7 % SHR - Subharmonic-harmonic ratio values
|
Dawn@4
|
8 % (and eventually, F0 candidates?)
|
Dawn@4
|
9 % Author: Kristine Yu, Department of Linguistics, UCLA, based off code
|
Dawn@4
|
10 % by Yen-Liang Shue for func_PraatPitch.m
|
Dawn@4
|
11
|
Dawn@4
|
12
|
Dawn@4
|
13 %%%%%%%%%%% Get/set arguments to shrp.m
|
Dawn@4
|
14
|
Dawn@4
|
15 % TESTING
|
Dawn@4
|
16 % [y,Fs]=wavread('work/beijing_f3_50_a.wav'); % for testing
|
Dawn@4
|
17 % F0MinMax = [vars.SHRmin, vars.SHRmax]; % For testing
|
Dawn@4
|
18 % windowsize = vars.windowsize; % Set frame_length to 25ms, the VS default, for testing
|
Dawn@4
|
19 % frameshift = vars.frameshift; % Set 10 ms frameshift, for testing
|
Dawn@4
|
20 % SHR_Threshold = 0.4; %
|
Dawn@4
|
21 % frame_precision = 1; % fudge factor for time alignment
|
Dawn@4
|
22 % ceiling = 1250;
|
Dawn@4
|
23 % med_smooth = 0; CHECK_VOICING = 0; % Leave default: no smoothing, no voice detection
|
Dawn@4
|
24
|
Dawn@4
|
25 %%% Get settings
|
Dawn@4
|
26
|
Dawn@4
|
27 F0MinMax = [variables.SHRmin, variables.SHRmax]; % Set lower and
|
Dawn@4
|
28 % upper bounds for
|
Dawn@4
|
29 % f0 estimation
|
Dawn@4
|
30
|
Dawn@4
|
31 frameshift = variables.frameshift; % this is in ms
|
Dawn@4
|
32 windowsize = variables.windowsize; % also in ms
|
Dawn@4
|
33
|
Dawn@4
|
34 SHR_Threshold = variables.SHRThreshold; % Set subharmonic-to-harmonic ratio
|
Dawn@4
|
35
|
Dawn@4
|
36 ceiling = 1250; % Leave default 1250 Hz
|
Dawn@4
|
37
|
Dawn@4
|
38 med_smooth = 0; CHECK_VOICING = 0; % Leave default: no smoothing, no voice detection
|
Dawn@4
|
39
|
Dawn@4
|
40 frame_precision = variables.frame_precision; % how many frames can
|
Dawn@4
|
41 % time-alignment be off by,
|
Dawn@4
|
42 % when outputting data vectors?
|
Dawn@4
|
43
|
Dawn@4
|
44 %%%%%%%%%%% Calculate subharmonic-harmonic ratios and f0 tracks
|
Dawn@4
|
45 % Call Xuejing Sun's subharmonic-harmonic ratio based pitch detection
|
Dawn@4
|
46 % algorithm shrp.m
|
Dawn@4
|
47 % Available for download here
|
Dawn@4
|
48 %http://www.mathworks.com/matlabcentral/fileexchange/1230-pitch-determination-algorithm
|
Dawn@4
|
49 %http://www.speakingx.com/blog/2008/01/02/pitch-determination
|
Dawn@4
|
50
|
Dawn@4
|
51 [f0_time,f0_value,SHR_value,f0_candidates]=shrp(y,Fs,F0MinMax,windowsize,frameshift,SHR_Threshold,ceiling,med_smooth,CHECK_VOICING);
|
Dawn@4
|
52
|
Dawn@4
|
53
|
Dawn@4
|
54 %%%%%%%%%%% Postprocess subharmonic-harmonic ratios and f0 tracks
|
Dawn@4
|
55
|
Dawn@4
|
56 % Initialize F0 and subharmonic-harmonic ratio values
|
Dawn@4
|
57 F0 = zeros(datalen, 1) * NaN;
|
Dawn@4
|
58 SHR = zeros(datalen, 1) * NaN;
|
Dawn@4
|
59
|
Dawn@4
|
60 t = round(f0_time); % time locations rounded to nearest ms
|
Dawn@4
|
61
|
Dawn@4
|
62 start = 0; % Like timecoures from Praat, we might have missing values so pad with NaNs at
|
Dawn@4
|
63 % beginning and end if necessary.
|
Dawn@4
|
64 finish = t(end);
|
Dawn@4
|
65 increment = frameshift;
|
Dawn@4
|
66
|
Dawn@4
|
67 for k=start:increment:finish
|
Dawn@4
|
68 [val, inx] = min(abs(t - k)); % try to find the closest value
|
Dawn@4
|
69 if (abs(t(inx) - k) > frame_precision * frameshift) % no valid value found
|
Dawn@4
|
70 continue;
|
Dawn@4
|
71 end
|
Dawn@4
|
72
|
Dawn@4
|
73 n = round(k / frameshift) + 1; % KY I added a 1 because Matlab index starts at 1, not 0
|
Dawn@4
|
74 if (n < 1 || n > datalen)
|
Dawn@4
|
75 continue;
|
Dawn@4
|
76 end
|
Dawn@4
|
77
|
Dawn@4
|
78 F0(n+1) = f0_value(inx); % f0 values
|
Dawn@4
|
79 SHR(n+1) = SHR_value(inx); % SHR values
|
Dawn@4
|
80 % I eventually would like to get candidates as well
|
Dawn@4
|
81 end
|