% Measures the minimum execution time of non-redundant Carleman
% Bilinearization, using sparsity, of filters + loudspeaker A
%

% CBVK Toolbox
% JHMG, PMSB 2016


clear

P=5;        % Expansion order
rep=50;     % Number of repetitions for greater precision of execution
            % time measurement

arq='mCB_nr_sp_AfiltA_P5';  % Ouput file

%------------------------------------------


% Literal model
[f,g,h,x,names,values]=dloudAfiltA_lit;      % Regenerate model to be sure


% ----------------------------------------------------
% Taylor expansion

[F1i,F1c,F11] = multaylorsp(f,x,P);
[G1i,G1c,G11] = multaylorsp(g,x,P-1);

% Pre-calculated weights and indices (cbvkutil/mkwtaylor.m)
load wtaylor_m11_P5

% Numerical evaluation
m=length(x);
[F1cn,F11n,G1cn,G11n]=evtaylorsp(m,F1c,F1i,F11,G1c,G1i,G11,names,values,wtylr);


%----------------------------------------------------
% Carleman Bilinearization

dt=zeros(1,rep);
[D,Dg,K]=precbsp(m,P);
for r=1:rep
  tic
  [Fi,Fc,Gi,Gc] = carlbilinsp(F1i,F1cn,G1i,G1cn,G11n,P,K,D,Dg);
  dt(r)=toc;
  fprintf('%g\n ', dt(r));
end

min(dt)
%save(arq,'dt');

