


LPCCOVAR performs covariance LPC analysis [AR,E,DC]=(S,P,T)
Inputs: S(NS) is the input signal
P is the order (default: 12)
T(NF,:) specifies the frames size details: each row specifies one frame
T can be a cell array if rows have unequal numbers of values
T(:,1) gives the start of the analysis interval: must be >P
T(:,2) gives the end of the anaylsis interval [default: t(:+1,1)-1]
subsequent pairs can be used to specify multiple disjoint segments
If T is omitted, T(1,1)=P+1, T(1,2)=NS;
The elements of t need not be integers.
W(NS) The error at each sample is weighted by W^2 (default: 1)
Outputs: AR(NF,P+1) are the AR coefficients with AR(:,1) = 1
E(NF,2) is the energy in the residual and in the original window.
sqrt(E) is often called the 'gain' of the LPC filter.
DC is the DC component of the signal S. If this output is included,
the LPC equations are modified to include a DC offset.

0001 function [ar,e,dc]=lpccovar(s,p,t,w) 0002 %LPCCOVAR performs covariance LPC analysis [AR,E,DC]=(S,P,T) 0003 % 0004 % Inputs: S(NS) is the input signal 0005 % P is the order (default: 12) 0006 % T(NF,:) specifies the frames size details: each row specifies one frame 0007 % T can be a cell array if rows have unequal numbers of values 0008 % T(:,1) gives the start of the analysis interval: must be >P 0009 % T(:,2) gives the end of the anaylsis interval [default: t(:+1,1)-1] 0010 % subsequent pairs can be used to specify multiple disjoint segments 0011 % If T is omitted, T(1,1)=P+1, T(1,2)=NS; 0012 % The elements of t need not be integers. 0013 % W(NS) The error at each sample is weighted by W^2 (default: 1) 0014 % 0015 % Outputs: AR(NF,P+1) are the AR coefficients with AR(:,1) = 1 0016 % E(NF,2) is the energy in the residual and in the original window. 0017 % sqrt(E) is often called the 'gain' of the LPC filter. 0018 % DC is the DC component of the signal S. If this output is included, 0019 % the LPC equations are modified to include a DC offset. 0020 0021 % Notes: 0022 % 0023 % (1) For speech processing P should be at least 2*F*L/C where F is the sampling 0024 % frequency, L the vocal tract length and C the speed of sound. For a typical 0025 % male (l=17 cm) this gives f/1000. 0026 % 0027 % (2) Each analysis frame should contain at least 2P samples. If note (1) is followed 0028 % this implies at least 2 ms of speech signal per frame. 0029 % 0030 % (3) It can be advantageous to restrict the analysis regions to time intervals 0031 % when the glottis is closed (closed-phase analysis). This can be achieved by 0032 % setting the T input parameter appropriately. If the closed-phase is shorter than 0033 % 2 ms then two or more successive closed-phases should be used by defining 4 or more 0034 % elements in the corresponding row of T. 0035 % 0036 % (4) A previous version of this routine allowed T() to have a single row which would 0037 % be replicated for the entire file length. This has be removed because it gave rise 0038 % to an ambiguity. 0039 0040 % Bugs: sould really detect a singular matrix and reduce the order accordingly 0041 0042 % Copyright (C) Mike Brookes 1995 0043 % Version: $Id: lpccovar.m 713 2011-10-16 14:45:43Z dmb $ 0044 % 0045 % VOICEBOX is a MATLAB toolbox for speech processing. 0046 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0047 % 0048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0049 % This program is free software; you can redistribute it and/or modify 0050 % it under the terms of the GNU General Public License as published by 0051 % the Free Software Foundation; either version 2 of the License, or 0052 % (at your option) any later version. 0053 % 0054 % This program is distributed in the hope that it will be useful, 0055 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0056 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0057 % GNU General Public License for more details. 0058 % 0059 % You can obtain a copy of the GNU General Public License from 0060 % http://www.gnu.org/copyleft/gpl.html or by writing to 0061 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0063 0064 s = s(:); % make it a column vector 0065 if nargin < 2 p=12; end; 0066 if nargin < 3 t=[p+1 length(s)]; end; 0067 wq = nargin>3; 0068 [nf,ng]=size(t); 0069 if iscell(t) 0070 t{nf+1}=length(s)+1; 0071 else 0072 if rem(ng,2) 0073 t(:,end+1)=[t(2:nf,1)-1; length(s)]; 0074 end 0075 end 0076 ar=zeros(nf,p+1); 0077 ar(:,1)=1; 0078 e=zeros(nf,2); 0079 dc=zeros(nf,1); 0080 d0=nargout >2; 0081 0082 rs=(1:p); 0083 0084 for jf=1:nf 0085 if iscell(t) 0086 tj=t{jf}; 0087 if rem(length(tj),2) 0088 tj(end+1)=t{jf+1}(1)-1; 0089 end 0090 else 0091 tj=t(jf,:); 0092 end 0093 0094 ta = ceil(tj(1)); 0095 tb = floor(tj(2)); 0096 cs = (ta:tb).'; 0097 for js=3:2:length(tj) 0098 ta = ceil(tj(js)); 0099 tb = floor(tj(js+1)); 0100 cs = [cs; (ta:tb).']; 0101 end 0102 %disp(cs([logical(1); (cs(2:end-1)~=cs(1:end-2)+1)|(cs(2:end-1)~=cs(3:end)-1); logical(1)])'); 0103 nc = length(cs); 0104 pp=min(p,nc-d0); 0105 dm=zeros(nc,pp); % predefine shape 0106 dm(:) = s(cs(:,ones(1,pp))-rs(ones(nc,1),1:pp)); 0107 if nargout>2 0108 if wq 0109 dm = [ones(nc,1) dm].*w(cs(:,ones(1,1+pp))); 0110 sc=(s(cs).*w(cs)); 0111 aa = (dm\sc).'; 0112 else 0113 dm = [ones(nc,1) dm]; 0114 sc=s(cs); 0115 aa = (dm\sc).'; 0116 end 0117 ar(jf,2:pp+1) = -aa(2:pp+1); 0118 e(jf,1)=sc.'*(sc - dm*aa.'); 0119 e(jf,2)=sc.'*sc; 0120 dc(jf)=aa(1)/sum(ar(jf,:)); 0121 else 0122 if wq 0123 dm = dm.*w(cs(:,ones(1,pp))); 0124 sc=(s(cs).*w(cs)); 0125 aa = (dm\sc).'; 0126 else 0127 sc=s(cs); 0128 aa = (dm\sc).'; 0129 end; 0130 ar(jf,2:pp+1) = -aa; 0131 if nargout>1 0132 e(jf,1)=sc.'*(sc - dm*aa.'); 0133 e(jf,2)=sc.'*sc; 0134 end 0135 end 0136 end 0137 if ~nargout 0138 lpcar2db(ar,127); 0139 end 0140