function  [S_perp,S_prll] = RField_size(Iparams)

%RFIELD_SIZE -- Standard deviations of Gabor receptive fields
%
%  [S_perp,S_prll] = RField_size(Iparams)
%
%  IPARAMS is an "input parameter structure" (see PLM_INPUT_PARAMS).
%  IPARAMS.D_spfreq specifies the spatial frequency domain with N elts.
%  IPARAMS.HW_orient specifies the half-width [deg] of the orientation
%  tuning curves for each neuron. A column vector or a scalar can be
%  used as shorthand for the full N_orient-by-N_spfreq matrix.
%  Typically, HW_orient is the same for all neurons when expressed in 
%  polar coordinates in the frequency domain. In Cartesian coordinates, 
%  it is proportional to the spatial frequency.
%  IPARAMS.octaves specifies the full-width [octaves] of the frequency
%  tuning curves for each neuron. A row vector or a scalar can be used
%  as shorthand for the full N_orient-by-N_spfreq matrix. Typically, 
%  it is the same for all neurons when expressed in logarithmic terms 
%  (and hence also proportional to SPFREQ in non-log).
%
%  Each Gaussian kernel in the frequency domain corresponds to a Gabor
%  receptive field in the space domain. RFIELD_SIZE calculates the
%  standard deviations [in deg.vis.ang] of the Gaussian envelopes of
%  these RFields. S_PERP is in the direction perpendicular to the bars
%  and S_PRLL parallel to them. Each sigma is inversely proportional to
%  the corresponding sigma in the frequency domain (see Table 2.2 in
%  Norma Graham's "Visual Pattern Analyzers", Oxford Univ.Press, 1989).
%
%  See also PLM_RFIELDS, PLM_INPUT_PARAMS, MAKE_PLFRONTEND.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 2.1 $  $Date: 2005/03/11 11:32 $

N_orient = Iparams.N_orient ;    % 7
N_spfreq = Iparams.N_spfreq ;    % 5

%-- Bandwidth along the orientation dimension. It would be constant in
% polar coordinates but has to be multiplied by R=SP_FREQ in Cartesian.
sigma_orient = 2.*Iparams.HW_orient.*(pi/180) .* Iparams.W2sigma ;

%-- Multiplicative bandwidth along the spatial-frequency dimension
k = 2.^(Iparams.octaves./2) ;    % logarithmic --> linear scale
W_spfreq = k - 1./k ;            % between the lobes of the log-Gaussian
sigma_spfreq = W_spfreq * Iparams.W2sigma ; % will be multiplied by SP_FREQ

%-- Expand shorthand notation
[M_orient,M_spfreq] = size(sigma_orient) ;
if (M_orient==1 & M_spfreq==1)   % scalar -- the typical case
   sigma_orient = repmat(sigma_orient,N_orient,N_spfreq) ;
elseif (M_orient==N_orient & M_spfreq==1)  % column vector
   sigma_orient = repmat(sigma_orient,1,N_spfreq) ;
elseif (~(M_orient==N_orient & M_spfreq==N_spfreq))
   error(sprintf('Iparams.HW_orient has invalid size [%d,%d].',...
      M_orient,M_spfreq)) ;
% else do nothing: (M_orient==N_orient & M_spfreq==N_spfreq)
end

[M_orient,M_spfreq] = size(sigma_spfreq) ;
if (M_orient==1 & M_spfreq==1)   % scalar -- the typical case
   sigma_spfreq = repmat(sigma_spfreq,N_orient,N_spfreq) ;
elseif (M_orient==1 & M_spfreq==N_spfreq)  % row vector
   sigma_spfreq = repmat(sigma_spfreq,N_orient,1) ;
elseif (~(M_orient==N_orient & M_spfreq==N_spfreq))
   error(sprintf('Iparams.octaves has invalid size [%d,%d].',...
      M_orient,M_spfreq)) ;
% else do nothing: (M_orient==N_orient & M_spfreq==N_spfreq)
end

%-- Final std.deviations in the frequency domain
R = abs(Iparams.D_spfreq) ;   % allow for negative spatial frequencies
R = repmat(R,N_orient,1) ;    % [N_orient x N_spfreq]
So = sigma_orient .* R ;
Sf = sigma_spfreq .* R ;

%-- Invert to the space domain (see Table 2.2 in Graham, 1989)
S_perp = (1/(2*pi)) ./ Sf ;
S_prll = (1/(2*pi)) ./ So ;


%--- Return S_PERP and S_PRLL
%%%%% End of file RFIELD_SIZE.M
