function E=entropy(ph,spectrum)
%%Used by apk.m
    pts=linspace(1,size(spectrum(:,2),1),size(spectrum(:,2),1));
	penalty=5.53;

    phi=(ph(1)+ph(2).*pts./max(pts))';
	size(phi);
	spectrum(:,2)=spectrum(:,2).*exp(i*phi);
	R=real(spectrum(:,2));
	size(R);
    Rm=firstderiv(R);
	size(Rm);
    h=abs(Rm)/sum(abs(Rm));
	size(h);

	negs= imag((R).^(1/2));
	negs(find(negs>1))=1;
    P= @(R) penalty.*sum((negs).*R.^2);

    E=-sum(h.*log(h))+P(R);
end
