% Measures the minimum execution time of Volterra kernel calculation 
%
% Discrete-time Volterra kernels of the cascade of 
% ideal discrete/continuous (D/C) converter with gain 1/Fs, 
% D/A reconstruction filter, loudspeaker A, A/D anti-aliasing filter and 
% ideal C/D converter.

% CBVK Toolbox
% JHMG, PMSB 2016


clear

m=11;
P=4;        % Expansion order
N=100;      % Memory length

Fs=5000;    % Sampling frequency
rep=1;      % Number of repetitions for greater precision of execution
            % time measurement

arq1='CB_AfiltA_P4';          % CB file            
arq2='mVK_AfiltA_P4_N100';     % Output file


msk{1}=1;
load mask_P2_N100a;            % Mask file (see cbvkutil/mask_P*m)
msk{2}=m2;
load mask_P3_N100a;            % Mask file (see cbvkutil/mask_P*m)
msk{3}=m3;
load mask_P4_N100a;            % Mask file (see cbvkutil/mask_P*m)
msk{4}=m4;

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


% Carleman Bilinearization 
load(arq1);

% Kernels

warning('off','cbvk:vkrn');

dt=zeros(1,rep);
for i=1:rep
    tic
    % Kernels of filters + loudspeaker
    kernels = vkrn(F,G,b,c,N,1/Fs,m,P,msk);

    
    % Application of 1/Fs gain
    Ts=1/Fs;
    for p=1:P
        kernels{p}=kernels{p}*(Ts^p);
    end
    dt(i)=toc;
    fprintf('%g\n ', dt(i));
end
min(dt)
%save(arq2,'dt');
warning('on','cbvk:vkrn');


