function y=persistence(tarV,preV)
% y = persistence(tarV,preV) computes the root mean square error 
% of the prediction normalized with the root mean square error of
% the persistent estimate, i.e. the estimate of x(t+T) is x(t).
% Therefore, it is assumed that 'preV' has length 'n-T', where
% 'n' is the length of 'tarV'. It is assumed that the components
% of 'tarV' and 'preV' match as follows. 
% tarV: 1 2 ... T T+1 T+2  ... n
% preV:           T+1 T+2  ... n
% INPUTS
%  tarV: Vector of correct values
%  preV: Vector of predicted values

n=length(tarV);
if length(preV)>=n
    error('The length of the target vector should be larger');
else
    T=n-length(preV);
end
persistV = tarV(1:n-T);
vartar = sum((tarV(T+1:n) - persistV).^2);
varpre = sum((tarV(T+1:n) - preV).^2);
y = sqrt(varpre / vartar);
