function [y,e]=voc(x, Aanal, Asyn, lseg); % Syntax [y,e]=voc(x, Aanal, Asyn, lseg); % % very simple LPC vocoder to analyze the effects of spectral quantization. % x - signal to analyze/synthesize - row vector ! % Aanal - LPC coeffs. for analysis (one vector per column (including a0=1)) % Asyn - LPC for synthesis (same format) % lseg - length of segment. This function cannot handle overlapping % y - synthesized signal % e - error signal [P, trames] = size(Aanal); P=P-1; [Ps, tramess]= size(Asyn); Ps=Ps-1; if (Ps ~= P | tramess ~= trames) error ('bad dimensions of parameter matrices'); end %%%%%%%%%%%%%%%%% analysis %%%%%%%%%%%%%%%%%%%%%%%%%%% % filtering to get excit - use initial and final conditions of the function % filter init=zeros(1,P); % initial conditions of the filter e=[]; % excitation pos=1; for i=1:trames, fen=x(pos:pos+lseg-1); pos=pos+lseg; % window a=Aanal(:,i); % filter [esmall,final]=filter(a,1,fen,init); % filtering with initial cond. init=final; % next init must be this final e=[e esmall]; % appending to the exct. % plot(esmall); % pause; end len=trames*lseg; % figure(1); plot(1:len, x(1:len), 1:len, e); %%%%%%%%%%%%%%%%%%% synthesis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init=zeros(1,P); % initial conditions of the filter y=[]; % excitation pos=1; for i=1:trames, fen=e(pos:pos+lseg-1); pos=pos+lseg; % window b=Asyn(:,i); [ysmall, final]=filter(1,b,fen,init); % filtering with initial cond. init=final; y=[y ysmall]; % appending to the synt. sig. % plot(1:lseg, ysmall, 1:lseg, x(pos-lseg:pos-1) ); % pause; end