www.pudn.com > audioProcessingtoolbox.rar > getfrmnt.m


function spectData = getfrmnt(frame, fs, lpcOrder, frmntmethod, plotopt) 
 
% GETFRMNT Get Formant information : frequency and bandwidth 
%    Usage : spectData = getfrmnt(frame, fs, lpcOrder, frmntmethod, plotopt) 
%    The spectData is a structural variable inclusive several fields. 
%    These fields are frmntfrq, frmntbw, pitch, fftspect, lpcspect, A, presig, poles, etc. 
%    The frmntmethod presents several well known approaches to implement the procedure. 
%    The lpcOrder usaully is set 12. 
% 
%    Cheng-Yuan Lin, 2003, January, 20. 
 
if nargin < 5, plotopt = 0; end; 
if nargin < 4, frmntmethod = 2; end; 
if nargin < 3, lpcOrder = 12; end; 
if nargin==0; selfdemo; return; end; 
 
% To get spectrum information and related LPC poles solutions. 
[fftspect, lpcspect, freqscale, A, presig, poles] = getspect(frame, fs, lpcOrder); 
spectfactor = (fs/2)/length(fftspect); 
Hzfactor    = fs/(2*pi); 
 
switch frmntmethod, 
case 1, %方法1 : W = arg(Z), B = -2*log(|Z|),   
   W = Hzfactor*angle(poles); 
   B = Hzfactor*-2*log(abs(poles));  
case 2, %方法2 : W 由 LPC spectrum 的 local maximum求取, B = 50 + 0.005*W 
   [maxIndex, value] = localmax(lpcspect); 
   W = maxIndex*spectfactor; 
   B = 50 + 0.005*W; 
end; 
 
%由上面所求得的W, B再經一些formant基本定義的rules判斷是否合法 
%index = find(W>90 & W90 & W800, 
   frameSize = 512; 
else 
   frameSize = 256; 
end; 
overlap   = (frameSize/2); 
frmdY = buffer2mex(y, frameSize, overlap); 
for k = 1 : size(frmdY, 2), 
   frame = frmdY(:, k).*hamming(frameSize); 
   spectData = getfrmnt(frame, fs, lpcOrder, frmntmethod, plotopt); 
   pause; 
   close all; 
end;