3
$\begingroup$

Recently, I have been trying to simulate a random/stochastic variable that follows Gaussian distribution and also has an exponential correlation function $\left\langle X(t)X(s)\right\rangle= e^{-\frac{|t-s|}{tc}}$. Through many interesting posts from Stack, I realized the function I was looking was the OrnsteinUhlenbeckProcess.

Accordingly, I created the following code to simulate my random variable $X(t)$ using a useful post Continuous noise representation

ti = 0;
tf = 100;
tc = 1;
dt = .1;

(*analytical correlation*)
corrana[t_]:=CorrelationFunction[OrnsteinUhlenbeckProcess[0,1/10,1/tc],0,t]

(*defining variable*)
X = Interpolation[Normal[RandomFunction[OrnsteinUhlenbeckProcess[0, 1/10, 1/tc],{ti,tf,dt}]][[1]]];

data = Table[X[t], {t, ti, tf, dt}];
{Plot[X[t], {t, ti, tf}], Histogram[data]}

corr = ListPlot[{CorrelationFunction[data, {IntegerPart[tf/dt]}],Table[{t, corrana[t]}, {t, ti, tf, dt}]}, PlotRange -> {Automatic, All}, PlotLegends -> {"From data", "From model"}, Joined -> True, AxesLabel -> {"t", "Correlation"}, PlotStyle -> {Orange, Black}];

Show[corr, PlotRange -> {{0, (3/10)*f/dt}, All}]

First, we can see that the histogram presents the Gaussian character of my variable

enter image description here

Additionally, the plot comparing the numerical and analytical calculation of the correlation function do also match to each other, but only for small times.

enter image description here

Accordingly to those features, I have some questions, namely:

Question 1: Why the numerical and analytical correlation functions only present a good aggreement for $t\lesssim tc$? Additionally, it seems there is a revival of the correlation for long times, which is evidenced by the oscillations of the numerical correlation functions around the $0$ value. Is this reasonable?

Question 2: The axis of the correlation function is not the real time but rather the position of the discrete time. How could I plot the numerical correlation as a function of the real time?

$\endgroup$

1 Answer 1

4
$\begingroup$

You have different x axes. For the correlation function the x axis is 0,1,2,... And for the Table you have 0,0.1,0.2,0.3,... (Note: f is not defined, I set it to f=0.1)

If we change the x axis of the correlation function to 0,0.1,0.2... we get:

corr = ListPlot[{Transpose[{Range[0, tf, dt], 
     CorrelationFunction[data, {IntegerPart[tf/dt]}]}], 
   Table[{t, corrana[t]}, {t, ti, tf, dt}]}, 
  PlotRange -> {Automatic, All}, 
  PlotLegends -> {"From data", "From model"}, Joined -> True, 
  AxesLabel -> {"t", "Correlation"}, PlotStyle -> {Orange, Black}]

Show[corr, PlotRange -> {{0, (3/10)*f/dt}, All}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you! Do you know how to address my question 2? $\endgroup$
    – sined
    Oct 3, 2022 at 19:34
  • 1
    $\begingroup$ The real time goes from 0..100. And the x axis of the correlation plot goes from 0..100. Does this not answer your question? $\endgroup$ Oct 3, 2022 at 19:40
  • $\begingroup$ I am sorry, I wrote it wrongly. I was actually referring to Question 1 $\endgroup$
    – sined
    Oct 3, 2022 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.