View on GitHub


A MATLAB class for Mean Square Displacement analysis.

Download this project as a .zip file Download this project as a tar.gz file

Mean square displacement analysis of particle trajectories.

Mean square displacement (MSD) analysis is a technique commonly used in colloidal studies and biophysics to determine what is the mode of displacement of particles followed over time. In particular, it can help determine whether the particle is:

On top of this, it can also derive an estimate of the parameters of the movement, such as the diffusion coefficient.

@msdanalyzer is a MATLAB per-value class that helps performing this kind of analysis. The user provides several trajectories he measured, and the class can derive meaningful quantities for the determination of the movement modality, assuming that all particles follow the same movement model and sample the same environment.

This tutorial doubles the documentation of the class, that can be accessed in classical ways. We demonstrate here how to use it, using very basic numerical simulations. The literature on MSD analysis is quite dense; in no way this beginner tutorial can hope to replace it. The examples we use are trivial, and we do not discuss the complex but important matter of the results significance. A demanding user is referred to the publications listed in this tutorial, and to the references they link.

Citing this work.

If you use this tool for your work, we kindly ask you to cite the following article for which it was created:

Nadine Tarantino, Jean-Yves Tinevez, Elizabeth Faris Crowell, Bertrand Boisson, Ricardo Henriques, Musa Mhlanga, Fabrice Agou, Alain Israël, and Emmanuel Laplantine. TNF and IL-1 exhibit distinct ubiquitin requirements for inducing NEMO-IKK supramolecular structures. J Cell Biol (2014) vol. 204 (2) pp. 231-45


Just download the link to the zip file or the tar.gz file and extract the @msdanalyzer folder. Drop it in a folder that belongs to the MATLAB path (the @msdanalyzer folder should not be in the path itself).

If everything works, typing

>> ma = msdanalyzer(2, 'µm', 's')

should return something like:

  msdanalyzer with properties:

      TOLERANCE: 12
         tracks: {}
          n_dim: 2
    space_units: 'µm'
     time_units: 's'
            msd: []
          vcorr: []
           lfit: []
      loglogfit: []
          drift: []

Brownian motion and mean square displacement.

According to Einstein theory (the first part), an ensemble of particles undergoing brownian motion will have the following density:

ρ ( r , t ) = ρ 0 Dt e - r 2 4Dt

assuming all the particles where followed from a single point at t=0, that r is the distance to this point, and D the diffusion coefficient. This (and much more) can be found in Einstein historical paper [1].

Using this formula, one can derive the mean square displacement for such particles:

r 2 = 2 d D t

where d is the dimensionality of the problem (2 for 2D, etc...) and D the diffusion coefficient. The mean is taken over a whole ensemble of particles: you have to sample many particles, compute msd i ( τ ) = ( r i ( τ ) - r i ( 0 ) ) 2 for each particle i and average the resulting msd i over all particles.

We see that the plot of the MSD value as a function of time should be a straight line in the case of diffusing movement. We therefore have a way to check what is the modality of the particle movement. If the MSD is a line, then it is diffusing, and the slope gives us the diffusion coefficient. If the MSD saturates and has a concave curvature, then its movement is impeded: it cannot freely diffuse away from its starting point. On the contrary, if the MSD increases faster than at linear rate, then it must be transported, because Brownian motion could not take it away that fast.

This is great, because to decide whether the erratic movement of a particle that you are observing is freely diffusive, bound, or transported, you would have to follow the particle for an infinite amount of time. This formula gives you a function that can be evaluated to check whether the particle movement is of any type. So we just need a way to evaluate it practically.

Experimentally, the MSD for a single particle is also taken as a mean. If the process is stationary (that is: the "situation", experimental conditions, etc... do not change over time), the ensemble average can be taken as a time average for a single trajectory, and MSD for a single particle can be calculated as

msd i ( τ ) = t ( r i ( t + τ ) - r i ( t ) ) 2

τ is called the delay; the MSD tells you how far can a particle under Brownian motion can go over a time τ. For finite trajectories, obviously the smaller delays τ will be more represented in the average than longer delays. For instance, if a trajectory has N points in it, the delay corresponding to one frame will have N-1 points in the average, and the delay corresponding to N frames will only have one. This has major consequences on measurement certainty, see [2].

@msdanalyzer: a MATLAB per-value class for MSD analysis.

The class presented here perform these computations automatically, and offers a lot of convenience methods to simplify the analysis of trajectories.

The user must provide the class with particle trajectories, possibly several thousands of them. The class itself cannot generate those trajectories. For this, you want to check single-particle tracking tools. Here are a few examples, drawn from Life-Sciences and my work:

And there are most likely plenty of other solutions out there.

@msdanalyzer can deal with tracks (particle trajectories) that do not start all at the same time, have different lengths, have missing detections (gaps: a particle fails to be detected in one or several frame then reappear), and do not have the same time sampling. As soon as you added your tracks to the class, everything is transparent. It offers facilities to plot and inspect the data, whether for individual particles, or on ensemble average quantities. It has several methods for correcting for drift, which is the main source of error in the analysis. Once corrected, the data can analyzed via the MSD curves or via the velocity autocorrelation. Automated fits of the MSD curves are included (but they require you have the curve fitting toolbox), allowing to derive the type of motion and its characteristics.

The class code is made of one several M-files. I made sure the documentation was extensive. In case of doubt, start with

>> doc msdanalyzer

and will get a page where all methods and fields are detailed.

To document the class, we will play with toy examples, using simulated trajectories, Our simulations will be kept simple, even trivial. There is a deep literature on the modeling of diffusion, but we will skip any complexities, at the expense of scientific relevance. See [3] for details on modeling.

Tutorial content.

  1. Simulating and analyzing Brownian motion. Here we introduce the class using the most simple example: a few particles undergoing a purely diffusive process. We will review all the important functions of the class for calculating and analyzing the MSD curves.
  2. Velocities and velocity auto-correlation. In this chapter we quickly review how to exploit the displacement and velocity autocorrelation function to analyze the particles motion.
  3. Impact of tracking and localization error. We refine a little bit the plain simulations of the previous chapter, trying to generate tracks that are more resembling experimental measurements. We reproduce some of the results of [4], investigating how these errors impact the final analysis results.
  4. Directed motion. We deal with the case of particles that have a directed motion on top of a Brownian motion. We introduce how to distinguish between the two kind of motion, and exploit analysis results to derive motion characteristics.
  5. Confined movements. This is just the converse case: for this type of motion, the particle is not free to diffuse, but somehow bound to a fixed structure or hindered in its movement by an invisible fence.
  6. Correcting for drift. This chapter details what methods are offered to correct for drift in measurements. It also provides an assessment of the most adequate method. And concludes this tutorial.

Since most of the complexity of the calculation is hidden in the @msdanalyzer class, these tutorial chapters involve mainly MATLAB code to generate and simulate fake particle trajectories. Some hacks are presented to facilitate the task, that I hope you will find useful as well.


  1. Einstein. Investigations on the Theory of the Brownian Movement. Ann. d. Phys (1926) vol. 17 pp. 549
  2. Qian et al. Single particle tracking. Analysis of diffusion and flow in two-dimensional systems. Biophys J (1991) vol. 60 (4) pp. 910-21
  3. Saxton. Modeling 2D and 3D diffusion. Methods Mol Biol (2007) vol. 400 pp. 295-321
  4. Michalet. Mean square displacement analysis of single-particle trajectories with localization error: Brownian motion in an isotropic medium. Phys Rev E Stat Nonlin Soft Matter Phys (2010) vol. 82 (4 Pt 1) pp. 041914