comparison Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_GetSHRP.m @ 4:92ca03a8fa99 tip

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