function [coeff, gain, pitch] = lpvocod_ana(x, p)
%LPVOCOD_ANA	Analyzes speech waveform into pitch, gain, coefficients
%		[coeff,gain,pitch,vstrength] = LPVOCOD_ANA(x, p)
%
%		x	input signal
%		p	order of LPC model
%
%		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
%
%

% Make x a column vector just to be sure.
x = x(:);

% Initialize variables for loop.  

Fs = 8000;			% sampling frequency 
frlen = round(0.03 * Fs);	% length of each data frame, 30ms
noverlap = fix(frlen/2);        % overlap of successive frames, half of frlen
hop = frlen-noverlap;		% amount to advance for next data frame
nx = length(x);	         	%length of input vector
len = fix((nx - (frlen-hop))/hop);	%length of output vector = total frames

% preallocate outputs for speed
gain = zeros(1, len);
pitch = zeros(1, len);
coeff = zeros(p+1, len);
coeff(1,:) = ones(1,len);
vstrength = zeros(1,len);

% also preallocate window . . .

% Design (but do not yet apply) a lowpass filter with 1 kHz cutoff
% frequency, since we're interested in pitch, which is 80--320 Hz for
% adult voices.  Make the filter length substantially shorter than the
% frame length . . . 

% Here's the loop. Each iteration processes one frame of data.

for i = 1:len
%  Get the next segment/frame of the unfiltered input signal.  
%  The indexing has been done for you.
   seg = x(((i-1)*hop+1):((i-1)*hop+frlen));

%  Window the segment . . .

%  Compute the LPC coefficients and gain of the windowed segment (`lpcoef')
%  and store in coeff matrix and gain vector . . .

% Compute the LP error signal

% Detect voicing and pitch for this frame by applying 1-kHz lowpass filter 
% to error signal and then calling your pitch detector . . .

end  		%end for loop

% Remove spurious values from pitch signal with median filter . . .
	

