A Cardiovascular Simulator for Research 1.0.0

File: <base>/src/ilv_dec.m (1,668 bytes)
% The function ilv_dec.m resamples Qlu for implementation
% of the direct neural coupling mechanism between Qlu
% and F.
%
%
% Function arguments:
%	   ilv - vector of Qlu at original sampling period
%	   Ogran - original granularity (deltaT/2)	   
%	   Sgran - desired granularity
%
% Function output:
%	   ilvn - vector of Qlu at desired granularity
%

function ilvn = ilv_dec(ilv,Ogran,Sgran)

% Creating time vector which corresponds to Qlu at the original granularity.
t = (0:length(ilv))*Ogran;

% Pre-allocating memory for function output.
N = floor(((length(ilv)-1)*Ogran)/Sgran)-1;
ilvn = zeros(1,N);

% Initializing variables.
m = 1;
start = m;

% Calculating the samples of the function output at Sgran intervals
% by averaging the originally sampled Qlu from the start of the 
% previous Sgran interval to the end of the next Sgran interval. 
for i = 1:N

	% Integrating over precisely over the desired interval
	% according to the trapezoidal rule.
	ts = i*Sgran;	
	ti = (i-1)*Sgran;
	tf = (i+1)*Sgran;

	m = start;

	scale = (ti-t(m))/(t(m+1)-t(m));

	sumilv = 0.5*(t(m+1)-ti)*(scale*(ilv(:,m+1)-ilv(:,m))+ilv(:,m)+ilv(:,m+1));

	m = m+1;

	mbrealscalar(t(m+1) < ts);
	while (t(m+1) < ts)

		sumilv = sumilv + 0.5*(t(m+1)-t(m))*(ilv(:,m+1)+ilv(:,m));

                m = m+1;

	end

	start = m;

	mbrealscalar(t(m+1) < tf);
	while (t(m+1) < tf)

		sumilv = sumilv + 0.5*(t(m+1)-t(m))*(ilv(:,m+1)+ilv(:,m));

                m = m+1;

	end

	scale = (tf-t(m))/(t(m+1)-t(m));

        sumilv = sumilv+0.5*(tf-t(m))*(scale*(ilv(:,m+1)-ilv(:,m))+ilv(:,m)+ilv(:,m));

	% Averaging over the integration interval.
        ilvn(:,i) = sumilv/(2*Sgran);

end