Variance of Simulated Langevin Equation 
I simulated (by Matlab) the Langevin equation for optical-trapped particle in very short time "steps" And I got this white noise figure.. 
The question is how I can calculate the variance (or in physical terms the Mean Squared distance) from this figure if I have the whole data.. 
I saw one article says that the variance is linear but I can't see that intuitively... 
 A: If you want to calculate the numerical variance of your signal, you can simply use the following estimator for variance (if the mean is zero):
$$\mathrm{Var}(X) = \frac{1}{N} \sum \limits_{k=1}^{N} x_k^2$$
However, the value of this quantity will depend on the situation you want to model, especially the presence or absence of a confing potential.


*

*first, I will talk about the random motion described by the Langevin equation $dv/dt = - v/\tau + \eta(t)$ in the absence of any confining potential. In that case, the variance defined as above is indeed linear with time. However, because there is a lot of randomness in a single realization, this only gives you an asymptotic behaviour, and in order to have a cleaner linear dependency with time, you should average over multiple realizations. For this, it is also possible to look at  $\left\langle X(t)^2 \right\rangle$, where $\left\langle \cdot \right\rangle$ denotes the average over all realizations (meaning that you would need to run your simulation a few times, and take the average of all realizations at a given time). This quantity grows linearly with time in the case of no potential (see for instance this section on Wikipedia).

*you talk about an "optical-trapped" particle. When you add a confining potential, the average over all realizations is no longer linear with time, neither is the numerical variance, but both should follow a Boltzmann distribution with density $p(X(t)) \to C\exp(-V(x)/kT)$ when $t \to \infty$ (see for instance this section), where $V(x)$ is the confining potential, $k$ the Boltzmann constant and $T$ the absolute temperature (related to the amplitude of the Langevin force via the Einstein equation). In that case, the numerical variance at long times ($t \to \infty$), should converge to the variance of the Boltzmann law for your potential. For instance, for a quadratic potential $V(x) = \frac{1}{2} k x^2$, you can simply use the equipartition theorem:
$$\frac{1}{2} k \left\langle X^2 \right\rangle = \frac{1}{2} k T,$$
to figure out $\left\langle X^2 \right\rangle$.

You can find the results of a Python simulation below:
I simulate the Langevin equation $dv/dt = - v/\tau + \eta(t)$ for $\tau = 0.1\,\mathrm{s}$ between $t = 0$ and $t = 50\mathrm{s}$, with a step of $1\, \mathrm{ms}$. The Langevin force $\eta(t)$ is taken to be Gaussian, and delta-correlated.
The first simulation is done without any potential. Blue is the average of $\left\langle X(t)^2 \right\rangle$ over $100$ simulations, and orange is the average of $\mathrm{Var}(X(t))$ also over $100$ simulations, where $$\mathrm{Var}(X(t)) \approx \frac{1}{t} \int \limits_{0}^{t} X(t')^2 dt' \approx \frac{dt}{t} \sum \limits_{k=1}^{t/dt} x_k^2.$$
(Note that in the limit where $\tau \to 0$, all $X(t)$'s are independent, and $Var(X(t)) \approx \frac{1}{t} \int \limits_{0}^{t} \left\langle X(t')^2 \right\rangle dt' = \frac{1}{2} \left\langle X(t)^2 \right\rangle $.
You see that despite the average over $100$ realizations, the resulting $\left\langle X(t)^2 \right\rangle$ is still very "noisy". This is because it takes a lot of realization to average all of the randomness. The "variance" curve appears smoother in comparison, but this is just because it can be seen as the sliding average of the first curve, thus reducing the high-frequency fluctuations.
The second simulation is done with an additional restoring force $- k x$ with $k = 2$. You can see that while both curves start similarly to the first simulation, with a linear dependency, as soon as the particle starts to explore regions with a potential energy on the order of $k T$, the two curves stop being linear and both converge to the value of $\left\langle X^2 \right\rangle$ which would be given by the equipartition theorem (the green curve is, once again, more noisy because it takes a lot of realizations to average out all randomness).
