

function [alpha_comb, lambda, level_opt, block_opt,  ekm] =D_purs_optP(list, t_coef,fnois, FT_remainder)
%calculation of the oblique projection coefficients 'alpha_comb' of the
%remainder for waveforms listed in 'list' 
%finding an optimal waveform, located at 'level_opt, block_opt', whose coefficient is  'alpha_max_max'
%its shift is determined by 'ekm'
%lambda=aplha_max_max/norm_opt;
%fnois --DFT of noise
%FT_remainder --DFT of remainder
N=length(fnois);
[vt, ht]=size(list);
n = 0:(N-1);
nn=pi*(n)/N;
	mw=exp(i*2* nn);
   alpha_comb=[];
    for mm=1:vt
 level=list(mm,1);      block=list(mm,2);
 Nz=list(mm,3);
tet= t_coef{level}{block};
%Ez=abs(tet*fnois')/N;
Ez=(ifft(tet.*conj(fnois)));

Tz=(ifft(tet.*conj(FT_remainder)));
aa=1-abs(Ez./(Tz+eps));
 aplha=real(Tz)/(Nz+eps).*aa.*(aa>0);
 [ma, ii]=max(abs(aplha));
 
 aplha_max=aplha(ii);
 
 alpha_comb=[alpha_comb ;aplha_max ii level block Nz];
    end
   [mp, ij]=max( abs(alpha_comb(:,1)));
   aplha_max_max=alpha_comb(ij,1);
   %MP=[MP aplha_max_max];
   level_opt=alpha_comb(ij,3);
   block_opt=alpha_comb(ij,4); 
   pos_opt=alpha_comb(ij,2);
   norm_opt=alpha_comb(ij,5);
   lambda=aplha_max_max/norm_opt;
   
   ekm=mw.^(pos_opt-1);
   % Copyright (c) 2013. Valery A. Zheludev 