Dawn@4: function [SHR,F0]=func_GetSHRP(y,Fs, variables, datalen) Dawn@4: %function [f0_time,f0_value,SHR,f0_candidates]=func_GetSHRP(y,Fs,F0MinMax,timestep,SHR_Threshold) Dawn@4: % Input: y, Fs - from wavread Dawn@4: % variables - settings from initialization/setting Dawn@4: % datalen - output data length Dawn@4: % Output: F0 - F0 values Dawn@4: % SHR - Subharmonic-harmonic ratio values Dawn@4: % (and eventually, F0 candidates?) Dawn@4: % Author: Kristine Yu, Department of Linguistics, UCLA, based off code Dawn@4: % by Yen-Liang Shue for func_PraatPitch.m Dawn@4: Dawn@4: Dawn@4: %%%%%%%%%%% Get/set arguments to shrp.m Dawn@4: Dawn@4: % TESTING Dawn@4: % [y,Fs]=wavread('work/beijing_f3_50_a.wav'); % for testing Dawn@4: % F0MinMax = [vars.SHRmin, vars.SHRmax]; % For testing Dawn@4: % windowsize = vars.windowsize; % Set frame_length to 25ms, the VS default, for testing Dawn@4: % frameshift = vars.frameshift; % Set 10 ms frameshift, for testing Dawn@4: % SHR_Threshold = 0.4; % Dawn@4: % frame_precision = 1; % fudge factor for time alignment Dawn@4: % ceiling = 1250; Dawn@4: % med_smooth = 0; CHECK_VOICING = 0; % Leave default: no smoothing, no voice detection Dawn@4: Dawn@4: %%% Get settings Dawn@4: Dawn@4: F0MinMax = [variables.SHRmin, variables.SHRmax]; % Set lower and Dawn@4: % upper bounds for Dawn@4: % f0 estimation Dawn@4: Dawn@4: frameshift = variables.frameshift; % this is in ms Dawn@4: windowsize = variables.windowsize; % also in ms Dawn@4: Dawn@4: SHR_Threshold = variables.SHRThreshold; % Set subharmonic-to-harmonic ratio Dawn@4: Dawn@4: ceiling = 1250; % Leave default 1250 Hz Dawn@4: Dawn@4: med_smooth = 0; CHECK_VOICING = 0; % Leave default: no smoothing, no voice detection Dawn@4: Dawn@4: frame_precision = variables.frame_precision; % how many frames can Dawn@4: % time-alignment be off by, Dawn@4: % when outputting data vectors? Dawn@4: Dawn@4: %%%%%%%%%%% Calculate subharmonic-harmonic ratios and f0 tracks Dawn@4: % Call Xuejing Sun's subharmonic-harmonic ratio based pitch detection Dawn@4: % algorithm shrp.m Dawn@4: % Available for download here Dawn@4: %http://www.mathworks.com/matlabcentral/fileexchange/1230-pitch-determination-algorithm Dawn@4: %http://www.speakingx.com/blog/2008/01/02/pitch-determination Dawn@4: Dawn@4: [f0_time,f0_value,SHR_value,f0_candidates]=shrp(y,Fs,F0MinMax,windowsize,frameshift,SHR_Threshold,ceiling,med_smooth,CHECK_VOICING); Dawn@4: Dawn@4: Dawn@4: %%%%%%%%%%% Postprocess subharmonic-harmonic ratios and f0 tracks Dawn@4: Dawn@4: % Initialize F0 and subharmonic-harmonic ratio values Dawn@4: F0 = zeros(datalen, 1) * NaN; Dawn@4: SHR = zeros(datalen, 1) * NaN; Dawn@4: Dawn@4: t = round(f0_time); % time locations rounded to nearest ms Dawn@4: Dawn@4: start = 0; % Like timecoures from Praat, we might have missing values so pad with NaNs at Dawn@4: % beginning and end if necessary. Dawn@4: finish = t(end); Dawn@4: increment = frameshift; Dawn@4: Dawn@4: for k=start:increment:finish Dawn@4: [val, inx] = min(abs(t - k)); % try to find the closest value Dawn@4: if (abs(t(inx) - k) > frame_precision * frameshift) % no valid value found Dawn@4: continue; Dawn@4: end Dawn@4: Dawn@4: n = round(k / frameshift) + 1; % KY I added a 1 because Matlab index starts at 1, not 0 Dawn@4: if (n < 1 || n > datalen) Dawn@4: continue; Dawn@4: end Dawn@4: Dawn@4: F0(n+1) = f0_value(inx); % f0 values Dawn@4: SHR(n+1) = SHR_value(inx); % SHR values Dawn@4: % I eventually would like to get candidates as well Dawn@4: end