www.pudn.com > LPCToolbox.rar > ANALYZESND.M
% pks = analyzeSnd(snd,ncoeffs)
%
% Estimate the formants F1, F2, F3 and their bandwidths for a sound
% 'snd' using an LPC filter of order 'ncoeffs'.
%
% pks: Nx3x2 matrix (N = # of analysis frames in the sound)
% pks(i,:,1) are the formant peak locations (F1 F2 F3) for frame i
% pks(i,:,2) are the corresponding bandwidths (bw1 bw2 bw3)
%
% uses global variable Ap (see SETPARAMS). This should be used to
% tweak the analysis parameters (e.g. width of the analysis frame).
%
function analyzeSnd
global Ap Cs
% Remove the DC bias. This trick is used in the COLEA package, and it
% helps eliminate complaints from LPC about ill-conditioned matrices.
mysnd = Cs.snd - mean(Cs.snd);
% If length of snd didn't line up with (k*context_width)+analysis_width,
% then ILS padded the sound with zeros (I think). We simply trim the
% sound down to (k-1)*context_width+analysis_width.
ncontexts = floor((length(mysnd) - Ap.analysis_width) / Ap.context_width);
Cs.nframes = ncontexts + 1;
Cs.pks = zeros(Cs.nframes, 3, 2);
for frnum=1:Cs.nframes,
ii = frame(frnum);
y = preham(mysnd(ii), Ap.preemph);
[a,g]=lpc(y, Cs.ncoeffs);
estpk = getpeaks(a, Ap.fftlen, Cs.Fs);
Cs.pks(frnum, :, 1) = estpk(1:3,1)'; % locations of F1,F2,F3
Cs.pks(frnum, :, 2) = estpk(1:3,2)'; % bandwidths
end