function [c, opt_output] = OLC(ci, a, omega, anl, opt_options, lr) 

%OLC            Cepstral envelope estimation by optimization of the penalized
%               likelihood criterion
%               [c, output] = OLC(ci, a, omega, anl, options[, lr]);
%               ci              Initial guess of the envelope
%               a               Squared harmonic magnitudes
%               omega           Fundamental frequency or list of frequencies
%               anl             Apparent noise level at the harm. freq.
%               lr              Smoothing parameter
%               opt_options     Optimization options for fminunc
%
%This method is referred to as "OLC" in the paper. REQUIRES MATLAB'S
%OPTIMIZATION TOOLBOX VERSION 2.0 (version 1.0 can be used as well, but you
%will have to replace the call to fminunc by the corresponding one using fmin).
%
%_______________________________________________________________________
%For more information about this mfile please take a look at the paper
%"Estimation of the spectral envelope of voiced sounds using a penalized
%likelihood approach" by Marine Oudot, Olivier Cappé and Eric Moulines.

% Authors: Marine Oudot, Olivier Cappé, 1996 - 2000
% ENST Dpt. TSI / LTCI (CNRS URA 820), Paris

% Input parameters
if (nargin < 6)
  lr = 0.15;
end
% Cepstrum order
p=length(ci)-1;
% Use column vectors
ci = ci(:);
omega = omega(:);
a = a(:);
anl = anl(:);

% Compute diagonal of the regularization matrix
B = lr*2*((0:p).^2)';
% and cepstral regression matrix
PHI = [ones(length(omega),1) 2*cos(omega*(1:p))];

[c,fval,exitflag,opt_output] = ...
  fminunc('OLC_eval', ci, opt_options, a, PHI, B, anl);
