function RO=defroP_conv(Par,q,yy,mu,ee,range_rho,ToX)

%Derivation of  the optimal regularization parameter for deconvolution of
%signal (image) 'yy'

%mu -- coordinates of the kernel in the basis of  exponential splines of
%order 'q'
%range_rho -range of search for regularization parameter
%Par -- order of approximating spline should be even number
%ee--estimated squared norm of errors 
%ToX--termination tolerance on the solution



[m,N]=size(yy);
[u,~]=juviP(Par,N);
[u2,~]=juviP(Par*2,N);

% uq=1;
 %q=0;
  [urq,~]=juviP((Par+q),N); 
s=(2*sin(pi*(0:N-1)/N)).^(Par);

W=s.*u;

%R=urq./sqrt(u2)./uq;
if m==1
    Y=fft(yy);
    Hr=urq.*abs(mu);
    
    Hr=abs(Hr);
erho=@(rho)sum((abs(Y).*(rho.*W)./(eps+(rho.*W)+Hr.^2)).^2)/N-ee;
else
    Y=fft2(yy);
    %H=fft2(h);  
    %V=u./sqrt(u2);
  W=u2'*(s.*u);
 W2=W'+W;
   u2=u2'*u2;
   u=u'*u;
    
    urq=urq'*urq;

 erho=@(rho)(sum(sum(abs(Y.*(rho*W2)./(eps+rho*W2+(abs(mu.*urq)).^2)).^2))*(1/N/m)-ee);   
end       
 
  options=optimset('TolX',ToX);
 RO = fzero(erho,range_rho,options) ;
% Copyright (c) 2011. Valery A. Zheludev
   