function [fea, pitch, segment]=trFeaExtract(au, trOpt, showPlot) % trFeaExtract: Feature extraction for tone recognition % % Usage: % [fea, segment]=trFeaExtract(au, trOpt, showPlot) % % Description: % fea=trFeaExtract(au, trOpt, showPlot) returns the feature used for tone recognition. % [fea, pitch, segment]=trFeaExtract(au, trOpt, showPlot) also returns the segment after EPD. % % Example: % auFile='wo3.wav'; % trOpt=trOptSet; % [fea, pitch, segment]=trFeaExtract(auFile, trOpt, 1); % % See also trOptSet. % Category: tone recognition % Roger Jang, 20171005 if nargin<1, selfdemo; return; end % ====== Set the default options if nargin<2 && ischar(au) && strcmpi(au, 'defaultOpt') fea=trOptSet; return end if nargin<2||isempty(au), trOpt=feval(mfilename, 'defaultOpt'); end if nargin<3, showPlot=0; end if isstr(au), au=myAudioRead(au); end %% EPD [epInSampleIndex, epInFrameIndex, segment]=epdByVol(au, trOpt.epdOpt, showPlot); au.signal=au.signal(epInSampleIndex(1):epInSampleIndex(2)); %% PT if showPlot, figure; end pitch=pitchTrackForcedSmooth(au, trOpt.ptOpt, showPlot); %% Polynomial fitting pitchNorm=pitch-mean(pitch); %coef=polyfit(x, pitchNorm, trOpt.feaOpt.polyOrder); % Common polynomial fitting coef=polyFitChebyshev(pitchNorm, trOpt.feaOpt.polyOrder); % Chebysheve polynomial fitting. Why pitchNorm does not give better performance? fea=coef; if showPlot % figure; plot(1:length(pitch), pitchNorm, 'marker', '.'); grid on % xlabel('Pitch index'); % ylabel('Semitone'); end % ====== Self demo function selfdemo mObj=mFileParse(which(mfilename)); strEval(mObj.example);