function [spectrum,ph]=apk(spectrum,phc0,phc1)
%%Usage -spectrum,ph]=apk(spectrum,phc0,phc1)
%%Spectrum is a complex matrix with the frequency in the first column
%%and the complex spectrum in the second column. phc0 and phc1 are the first order
%%phase correction parameters, respectively, and are used as initial guesses.
%%This is an implementation of Chen, Weng, Goh and Garland, J. Mag. Res., 2002, 158, 164-168 and depends on entropy.m.

    ph=[phc0;phc1];
	ph=minimize("entropy",{ph,spectrum});

	%compute spectrum with optimal phase params
	pts=linspace(1,size(spectrum(:,2),1),size(spectrum(:,2),1));
	phi=(ph(1)+ph(2).*pts./max(pts))';
	spectrum(:,2)=spectrum(:,2).*exp(i*phi);
end
