% This routine is for computing the scattering transform at the k-grid.
%
% We load from file the (Fourier coefficients of the) traces of Faddeev 
% exponentially growing solutions created by routine psi_BIE_comp.m 
% (and saved to file data/psi_BIE.mat). We integrate 
%
%  tBIE(k) = \int_{boundary} e^{i*conj(kx)} (Lg-L1) psi(x,k) d\sigma(x)
%
% using a loop over all k values in the vector kvec.
% The result is saved to file data/tBIE.mat.
%
% Samuli Siltanen June 2012

% Load vectors of k and theta values
load data/kvec kvec
load data/theta theta Ntheta Dtheta

% Initialize the result
tBIE  = zeros(size(kvec));

% Load precomputed Fourier coefficients of traces of psi
load  data/psi_BIE Fpsi_BIE Nvec 

% Load precomputed DN maps
load data/DN DN DN1 Ntrig
Nvec = [-Ntrig : Ntrig];

% Loop over k values
load data/BIEindex BIEindex
for iii = 1:BIEindex
    k = kvec(iii);
    
    % Compute Fourier representation of trace of psi
    Fpsi = Fpsi_BIE(:,iii);
    
    % Apply DN maps to evaluate (Lg-L1) psi(x,k)
    FLLpsi  = (DN - DN1)*Fpsi;
    LLpsi  = zeros(size(theta));
    for jjj = 1:length(Nvec)
        LLpsi  = LLpsi  + FLLpsi(jjj)*exp(i*Nvec(jjj)*theta);
    end 

    % Integrate 
    tBIE(iii)  = Dtheta*exp(i*conj(k)*exp(-i*theta.'))*LLpsi;
    
    % Monitor the run
    if mod(iii,100)==0
        disp(['Done ', num2str(iii), ' out of ', num2str(BIEindex)])
    end
end

% Save the result to file.
save data/tBIE tBIE kvec 

