function  phi_pr = approx_phi(phi, pi_B, del_B, NB)
%Called by my_moo.m
%phi= complex, 2^(NB-1) component,  column vector 
%pi_B=  row vector, permutation of (1: NB-1)
%del_B= integer in range 0:NB-1; bit deficit
%NB= integer, number of bits
%phi_pr= phi prime; complex, 2^(NB-1) component, column vector; 
%        approximation of phi
if (NB<1)
	error("NB is less than 1");
end
len_phi = 2^(NB-1);
if (length(phi)!=len_phi)
	error("phi has wrong length");
end
if (length(pi_B)!=NB-1)
	error("pi_B has wrong length");
end
if (del_B>NB-1| del_B<0) 
	error("del_B  is out of range");
end
NS_pr=2^(NB-1-del_B);
h = zeros(len_phi, 1);
h_norma = sqrt(len_phi);
phi_pr=zeros(len_phi, 1);
for j=0:(NS_pr-1)
	j1 = grayish_code(j, pi_B, NB-1);
	for i=0:(len_phi-1)
		h(i+1) = (-1)^( dec_to_bin(j1, NB-1)*dec_to_bin(i, NB-1)')./h_norma;
	end
	phi_pr = phi_pr + h *(h'*phi);
end