computes the fundamental frequency of the (monophonic) audio > > supported pitch trackers are: > 'SpectralAcf', > 'SpectralHps', > 'TimeAcf', > 'TimeAmdf', > 'TimeAuditory', > 'TimeZeroCrossings', > > @param cPitchTrackName: feature to compute, e.g. 'SpectralHps' > @param x: time domain sample data, dimension channels X samples > @param f_s: sample rate of audio data > @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty > @param iBlockLength: internal block length (default: 4096 samples) > @param iHopLength: internal hop length (default: 2048 samples) > > @retval f frequency > @retval t time stamp for the frequency value ======================================================================
0001 %computes the fundamental frequency of the (monophonic) audio 0002 %> 0003 %> supported pitch trackers are: 0004 %> 'SpectralAcf', 0005 %> 'SpectralHps', 0006 %> 'TimeAcf', 0007 %> 'TimeAmdf', 0008 %> 'TimeAuditory', 0009 %> 'TimeZeroCrossings', 0010 %> 0011 %> @param cPitchTrackName: feature to compute, e.g. 'SpectralHps' 0012 %> @param x: time domain sample data, dimension channels X samples 0013 %> @param f_s: sample rate of audio data 0014 %> @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty 0015 %> @param iBlockLength: internal block length (default: 4096 samples) 0016 %> @param iHopLength: internal hop length (default: 2048 samples) 0017 %> 0018 %> @retval f frequency 0019 %> @retval t time stamp for the frequency value 0020 % ====================================================================== 0021 function [f, t] = ComputePitch (cPitchTrackName, x, f_s, afWindow, iBlockLength, iHopLength) 0022 0023 % set function handle 0024 hPitchFunc = str2func (['Pitch' cPitchTrackName]); 0025 0026 % set default parameters if necessary 0027 if (nargin < 6) 0028 iHopLength = 2048; 0029 end 0030 if (nargin < 5) 0031 iBlockLength = 4096; 0032 end 0033 0034 % pre-processing: down-mixing 0035 x = ToolDownmix(x); 0036 0037 % pre-processing: normalization (not necessary for many features) 0038 if (length(x)> 1) 0039 x = x/max(abs(x)); 0040 end 0041 0042 x = [x; zeros(iBlockLength, 1)]; 0043 0044 if (IsSpectral_I(cPitchTrackName)) 0045 if (nargin < 4 || isempty(afWindow)) 0046 afWindow = hann(iBlockLength, 'periodic'); 0047 end 0048 0049 % check FFT window function 0050 if (length(afWindow) ~= iBlockLength) 0051 error('window length mismatch'); 0052 end 0053 0054 % in the real world, we would do this block by block... 0055 [X, f, t] = ComputeSpectrogram(x, ... 0056 f_s, ... 0057 afWindow, ... 0058 iBlockLength, ... 0059 iHopLength); 0060 0061 % compute frequency 0062 f = hPitchFunc(X, f_s); 0063 end %if (IsSpectral_I(cPitchTrackName)) 0064 0065 if (IsTemporal_I(cPitchTrackName)) 0066 % compute frequency 0067 [f,t] = hPitchFunc( x, ... 0068 iBlockLength, ... 0069 iHopLength, ... 0070 f_s); 0071 end %if (IsTemporal_I(cPitchTrackName)) 0072 end 0073 0074 function [bResult] = IsSpectral_I(cName) 0075 bResult = false; 0076 iIdx = strfind(cName, 'Spectral'); 0077 if (~isempty(iIdx)) 0078 if (iIdx(1) == 1) 0079 bResult = true; 0080 end 0081 end 0082 end 0083 0084 function [bResult] = IsTemporal_I(cName) 0085 bResult = false; 0086 iIdx = strfind(cName, 'Time'); 0087 if (~isempty(iIdx)) 0088 if (iIdx(1) == 1) 0089 bResult = true; 0090 end 0091 end 0092 end