function yV = addstochastictrend(xV)
% yV = addstochastictrend(xV)
% ADDSTOCHASTICTREND adds a stochastic trend to a given time series (for
% simulating purposes). The time series of stochastic trend is generated by
% simulating a smoothed random walk time series of the same length as that of the
% given time series.
% INPUT
% - xV      : vector of length 'n' of the given time series
% OUTPUT
% - yV      : vector of length 'n' of the sum of the given time series and
%             a stochastic trend.

n = length(xV);
maorder = round(n/5);
xV = xV(:);
xsd = std(xV);
zV = 0.1*xsd*randn(n,1);
zV = cumsum(zV);
wV = movingaveragesmooth2(zV,maorder);
yV = xV + wV;
