# Generate noise with arbitrary covariance

I am doing a time series change detection experiment. One of the experiments includes generating some artificial data for model evaluation.

I came across a problem in generating noise data with some arbitrary covariance at every 100 time steps.

While randn from Matlab allows me to generate the value, I am never able to figure how to change the covariance of the data. Is there any example that I can refer to?

• There is no such thing as the covariance of the data unless your data has only two items: covariance is a pair-wise property. For time series purposes, you need the covariance function which tells you the covariance between all $\binom{n}{2}$ pairs of the $n$ items. And no, you cannot choose an arbitrary function and say "That's the covariance function I want to achieve" because covariance functions must satisfy certain properties, and if your choice does not meet the criteria, then nobody can tell you how to achieve your heart's desire. – Dilip Sarwate Dec 30 '13 at 19:03

If you want a Gaussian vector $X$ with $E(X)=0$ and $E(X\,X^T)=C$, then find a decomposition $C=AA^T$, for instance a Cholesky decomposition, compute a vector $U$ with standard normal uncorrelated random numbers as components and set $X=AU$.

If you have two iid sequences generated with randn() called x and y, then cov(x(1:100:end),y(1:100:end)) will be zero. If you want that result to be nonzero, then one way is to add a fraction of x(1:100:end) to y(1:100:end) to introduce some correlation at every 100th step. You can control the covariance by changing the fraction of x that is added to y at every 100th step.