# 3 Lines Matlab Code to R Code (Generating autocorrelated random values)

#### consuli

##### Member
Hello,

I have found the following Matlab Code for generating autocorrelated random values, with a defined autocorrelation on lag 1.

I understand your question such that you want to generate
a time series whose autocorrelation series has certain
properties. The simplest way to do that, is to use
a filter and apply it to a pseudorandom sequence.

In the case of an AR(1) process, this becomes
Code:
a1=0.5;
A=[1,-a1]; # A=[1,-a1] <=> A= c(1, -a1)
x=filter(A,1,randn(1000,1)); # randn(1000,1)) <=> rnorm(1000)
But I do not know how to reproduce the Matlab Funktion filter.

Last edited: