function  Fparams = spectral_diag_params(sz)

%SPECTRAL_DIAG_PARAMS -- Spectral diagram parameters (see SPECTRAL_DIAG).
%
% Fparams = spectral_diag_params(sz)
%
% SZ specifies the size of the image(s) whose spectrum will be plotted,
% as returned by SIZEOF. Typically, SZ is a vector of two equal numbers.
% Currently, only sizes [64 64] and [256 256] are implemented.
%
% FPARAMS is a structure with the following fields:
%  size
%  deg_pix
%  max_power
%  sqrtp
%  f_vert
%  f_horiz
%  THi
%  Ri
%  log_origin
%  u
%  v
%  spokes
%  rings
%  linewidth
%  cob_range
%  ann_range
%  colormap
%  xtick
%  xticklabel
%  xlabel
%
% Example:
%  P=PLExp2_params; F=spectral_diag_params(P.size)
%  spectral_diag(P.Gabor(:,:,1,1),F);   % colormap(flipud(gray))
%
% See also SPECTRAL_DIAG, HINTON_PARAMS, FFTMESH, CART2POL2.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2004/12/02 11:37 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

if (sz(1)~=sz(2))
   error('Only square sizes are currently implemented. Sorry...') ;
end

Fparams.size = sz ;    % [64 64] or [256 256]

switch sz(1)
case 64
   Fparams.deg_pix = 0.0450 ;    % See PLExp1_params and PLExp2_params
   Fparams.max_power = 50 ;      % determined by trial and error
case 256
   Fparams.deg_pix = 1/90 ;      % 0.0111, see PLExp3_params
   Fparams.max_power = 50 ;      % ???
otherwise
   error('Only sizes [64 64] and [256 256] are currently implemented.') ;
end

Fparams.sqrtp = 0 ;   % whether to SQRT each abs(FFT2) value or not

%-- FFT mesh, expressed in cycles per degree
[Fx,Fy] = fftmesh(sz) ;
Fx = fftshift(Fx) ./ Fparams.deg_pix ;     % [64 64] or [256 256]
Fy = fftshift(Fy) ./ Fparams.deg_pix ;     % [64 64] or [256 256]

%- All spectra are mirror symmetric. Discard the half with Fx<0:
Fx(:,1:sz(1)/2) = [] ;    % [64 32] or [256 128]
Fy(:,1:sz(2)/2) = [] ;    % [64 32] or [256 128]

%- The spectra are rotated 90* relative to the images. Rotate them back:
Fx = flipud(Fx') ;        % [32 64] or [128 256]
Fy = flipud(Fy') ;        % [32 64] or [128 256]

%- Keep only one line of each mesh. The full mesh can be
%  reconstructed via:  [Fy,Fx] = meshgrid(f_horiz,f_vert)
Fparams.f_horiz = Fy(1,:) ;   % [1 64] or [1 256]
Fparams.f_vert = Fx(:,1) ;    % [32 1] or [128 1]

%-- As an intermediate step, the spectra are transformed from Cartesian
%   to polar coordinates using CART2POL2 using THi and Ri below:
Fparams.THi = [0:1.5:180].*(pi/180) ;    % [1 121]
Fparams.Ri = [.2:.2:10]' ;               % [50 1]

%-- The R-axis is log2-transformed, and then LOG_ORIGNI is added:
log_origin = 1 ;       % map R=1cyc/deg to log2R=1
Fparams.log_origin = log_origin ;

%-- (Part of) the log2-transformed spectrum is then re-expressed in
%   the Cartesian coordinates of the canvas. [U,V]=meshgrid(u,v)
Fparams.u = [-4.2:0.025:+4.2] ;  % [1 337]
Fparams.v = [0:0.025:4.2]';      % [169 1]

%-- SPOKES and RINGS are generated by COBWEB
Fparams.spokes = [0:30:180] ;
Fparams.rings = [1:4] ;
Fparams.linewidth = 0.03 ;       % in U,V coordinates
Fparams.cob_rng = [0.9 4.1] ;    % in U,V coordinates

%-- Eliminate the very low frequencies (they are spurious) and
% the very high frequencies, restricting the canvas to an annulus:
Fparams.ann_rng = [log_origin 4] ;    % in U,V coordinates

%-- Modified 'jet' colormap: black[1x3] + jet[64x3] + white[1x3]
Fparams.colormap = [0 0 0 ; jet(64) ; 1 1 1] ;
% Alternatively, use flipud(gray) for black and white colormap.

%-- Tick labels
Fparams.xtick = [-4:4] ;
Fparams.xticklabel = '8|4|2|1||1|2|4|8' ;
Fparams.xlabel = 'Spatial frequency [cycles/degree]' ;

%--- Return FPARAMS
%%%%% End of file SPECTRAL_DIAG_PARAMS.M
