function [ltpDelays, ltpGains] = ... 
    olltpdg( ltpInputBlock, subblockLength, minDelay, ltpInputPast )
% function [ltpDelays, ltpGains] =
%     olltpdg( ltpInputBlock, subblockLength, minDelay, ltpInputPast )
%
% Determine Open-Loop LTP Delays and Gains
%
% ltpInputBlock:     input vector
% subblockLength:    ltpInputBlock is devided in subblocks of size subblockLength
% minDelay:          minimal delay (maximal delay is determined by size of ltpInputPast)		
% ltpInputPast:      ltp filter states before ltp filtering		
% 
% ltpDelays:	     vector containing ltp delays (size: number of subblocks in ltpInputBlock)
% ltpGains:          vector containing ltp gains (size: number of subblocks in ltpInputBlock)		
%  
% Author:  Markus Hauenstein
% Date:    10.01.2002 
% Contact: www.markus-hauenstein.de

blockLength = length(ltpInputBlock);
maxDelay = length(ltpInputPast);
numberOfSubblocks = blockLength / subblockLength;

if numberOfSubblocks ~= floor(blockLength / subblockLength), 
  error( 'iltpfilt: blockLength and subblockLength do not fit' )
end

ltpInputExt = [ltpInputPast; ltpInputBlock];

subblockIndex = 1 : subblockLength;
subblockIndexExt = (maxDelay+1) : (maxDelay+subblockLength);
searchIndex = 1 : (maxDelay+subblockLength);

for j=1:numberOfSubblocks,
  % determine ltp gain and delay for this subblock 
  [ltpGains(j), ltpDelays(j)] = ltpol( ltpInputExt(searchIndex), subblockLength, minDelay );

  % set indices for next subblock
  subblockIndex = subblockIndex + subblockLength;   
  subblockIndexExt = subblockIndexExt + subblockLength;
  searchIndex = searchIndex + subblockLength; 
end

ltpGains = ltpGains(:);
ltpDelays = ltpDelays(:);
