function y = lpvocod_syn(coeff, gain, pitch, fr_int)
%LPVOCOD_SYN	Synthesize speech waveform from pitch, gain, and LPC
%		coefficients  
%
%		y = LPVOCOD_SYN(pitch, coeff, gain, fr_int)
%
%		coeff	matrix of LP coefficients 
%			(column index = frame number;
%		          row index = coefficient number)
%		gain	vector of gain values (one per frame)
%		pitch	vector of pitch values (one per frame), 0=unvoiced
%		fr_int	frame interval (sec)
%
%		y	synthesized speech signal
%

% Error checking
if (nargin < 3), error('There must be 3 or 4 input arguments'); end;
[nrows nframes]=size(coeff);
if (nframes ~= length(pitch)), error('Pitch vector has illegal length'); end;
if (nframes ~= length(gain)), error('Gain vector has illegal length'); end;

% Initialize variables for loop.  
Fs = 8000;			      % sampling frequency 
if (nargin < 4), fr_int = .015; end;  % assume 15-msec frame interval
frlen= round(fr_int*Fs);

% Preallocate output for efficiency
y=zeros(nframes*frlen,1);
delay=0;		               % delay to first pitch pulse
filt_state = zeros(size(coeff,1)-1,1);

% Loop over frames to generate total source signal
for i=1:nframes
    % Pitch value for each frame indicates if voicing source or noise source
    if pitch(i) > 0
       % Compute pitch period (in samples) and generate impulse train (`pulse_train') . . .
       % (Be sure to save new delay for next frame)

    else
       % Generate noise source (`randn') . . .

    end

    % Normalize source signal to have unit energy
    % (to be consistent with assumption made in the analysis stage)
    % Take care not to divide by zero . . .

    %  Now, filter source signal through LP model filter, 
    %  keeping track of the filter state to avoid discontinuities . . .


    % Insert frame into output signal . . .
    y((i-1)*frlen+1:i*frlen) = 

end



