## I. INTRODUCTION

Numerically averaging data to extract meaningful physical parameters is a fundamental process in quantitative science, yet it is often taken for granted. Because of the explosion of single-particle tracking experiments and automated high-throughput microscopy, mean squared displacement (MSD) has become a standard measurement across a wide range of biophysical disciplines (1). Despite its ubiquity in biophysics research, undergraduate students are rarely formally introduced to MSD or the practical aspects of the calculation. Here, we present a flexible experimental or computational laboratory exercise that we believe fills a critical gap in undergraduate biophysics education and will better prepare the next generation of biophysicists for the challenges and rigor of interdisciplinary experimental science.

Mean squared displacement was first theoretically described by Albert Einstein in one of his 4 infamous *Annus mirabilis* publications of 1905 (2, 3). Nearly a century earlier, Robert Brown observed that small pollen particles suspended in water jiggle around randomly in space, a phenomenon now aptly referred to as Brownian motion, but was unable to determine the source of the motion (4). Einstein's theory connected the thermal motion of the molecules in the surrounding fluid to the Brownian motion of the pollen: the pollen particles are constantly being bombarded by fast-moving water molecules traveling in random directions. Although we cannot directly observe the motion of the water molecules, the motion of the pollen provides insight into the surrounding fluid environment. This work provided a theoretical prediction for Jean Baptiste Perrin to verify experimentally, effectively proving the still controversial atomic theory of matter (5).

A particle undergoing Brownian motion tends to travel away from its initial position, a process called *diffusion*. Einstein showed that the average squared distance a diffusing particle travels in 1 dimension is directly proportional to time,
\(\def\upalpha{\unicode[Times]{x3B1}}\)\(\def\upbeta{\unicode[Times]{x3B2}}\)\(\def\upgamma{\unicode[Times]{x3B3}}\)\(\def\updelta{\unicode[Times]{x3B4}}\)\(\def\upvarepsilon{\unicode[Times]{x3B5}}\)\(\def\upzeta{\unicode[Times]{x3B6}}\)\(\def\upeta{\unicode[Times]{x3B7}}\)\(\def\uptheta{\unicode[Times]{x3B8}}\)\(\def\upiota{\unicode[Times]{x3B9}}\)\(\def\upkappa{\unicode[Times]{x3BA}}\)\(\def\uplambda{\unicode[Times]{x3BB}}\)\(\def\upmu{\unicode[Times]{x3BC}}\)\(\def\upnu{\unicode[Times]{x3BD}}\)\(\def\upxi{\unicode[Times]{x3BE}}\)\(\def\upomicron{\unicode[Times]{x3BF}}\)\(\def\uppi{\unicode[Times]{x3C0}}\)\(\def\uprho{\unicode[Times]{x3C1}}\)\(\def\upsigma{\unicode[Times]{x3C3}}\)\(\def\uptau{\unicode[Times]{x3C4}}\)\(\def\upupsilon{\unicode[Times]{x3C5}}\)\(\def\upphi{\unicode[Times]{x3C6}}\)\(\def\upchi{\unicode[Times]{x3C7}}\)\(\def\uppsy{\unicode[Times]{x3C8}}\)\(\def\upomega{\unicode[Times]{x3C9}}\)\(\def\bialpha{\boldsymbol{\alpha}}\)\(\def\bibeta{\boldsymbol{\beta}}\)\(\def\bigamma{\boldsymbol{\gamma}}\)\(\def\bidelta{\boldsymbol{\delta}}\)\(\def\bivarepsilon{\boldsymbol{\varepsilon}}\)\(\def\bizeta{\boldsymbol{\zeta}}\)\(\def\bieta{\boldsymbol{\eta}}\)\(\def\bitheta{\boldsymbol{\theta}}\)\(\def\biiota{\boldsymbol{\iota}}\)\(\def\bikappa{\boldsymbol{\kappa}}\)\(\def\bilambda{\boldsymbol{\lambda}}\)\(\def\bimu{\boldsymbol{\mu}}\)\(\def\binu{\boldsymbol{\nu}}\)\(\def\bixi{\boldsymbol{\xi}}\)\(\def\biomicron{\boldsymbol{\micron}}\)\(\def\bipi{\boldsymbol{\pi}}\)\(\def\birho{\boldsymbol{\rho}}\)\(\def\bisigma{\boldsymbol{\sigma}}\)\(\def\bitau{\boldsymbol{\tau}}\)\(\def\biupsilon{\boldsymbol{\upsilon}}\)\(\def\biphi{\boldsymbol{\phi}}\)\(\def\bichi{\boldsymbol{\chi}}\)\(\def\bipsy{\boldsymbol{\psy}}\)\(\def\biomega{\boldsymbol{\omega}}\)\(\def\bupalpha{\bf{\alpha}}\)\(\def\bupbeta{\bf{\beta}}\)\(\def\bupgamma{\bf{\gamma}}\)\(\def\bupdelta{\bf{\delta}}\)\(\def\bupvarepsilon{\bf{\varepsilon}}\)\(\def\bupzeta{\bf{\zeta}}\)\(\def\bupeta{\bf{\eta}}\)\(\def\buptheta{\bf{\theta}}\)\(\def\bupiota{\bf{\iota}}\)\(\def\bupkappa{\bf{\kappa}}\)\(\def\buplambda{\bf{\lambda}}\)\(\def\bupmu{\bf{\mu}}\)\(\def\bupnu{\bf{\nu}}\)\(\def\bupxi{\bf{\xi}}\)\(\def\bupomicron{\bf{\micron}}\)\(\def\buppi{\bf{\pi}}\)\(\def\buprho{\bf{\rho}}\)\(\def\bupsigma{\bf{\sigma}}\)\(\def\buptau{\bf{\tau}}\)\(\def\bupupsilon{\bf{\upsilon}}\)\(\def\bupphi{\bf{\phi}}\)\(\def\bupchi{\bf{\chi}}\)\(\def\buppsy{\bf{\psy}}\)\(\def\bupomega{\bf{\omega}}\)\(\def\bGamma{\bf{\Gamma}}\)\(\def\bDelta{\bf{\Delta}}\)\(\def\bTheta{\bf{\Theta}}\)\(\def\bLambda{\bf{\Lambda}}\)\(\def\bXi{\bf{\Xi}}\)\(\def\bPi{\bf{\Pi}}\)\(\def\bSigma{\bf{\Sigma}}\)\(\def\bPhi{\bf{\Phi}}\)\(\def\bPsi{\bf{\Psi}}\)\(\def\bOmega{\bf{\Omega}}\)\begin{equation}\left\langle {{{\left( {x\left( t \right) - x(0)} \right)}^2}} \right\rangle = 2Dt,\end{equation}
where the constant *D* is referred to as the *diffusion constant* of the particle, which depends on the size and shape of the object as well as material properties of the surrounding medium. Note that the factor of 2 applies to 1-dimensional diffusion; 2- and 3-dimensional diffusion have the same time dependence, but instead include factors of 4 and 6, respectively.

Einstein's theory relies on the Brownian motion of the particle being truly random: the motion at any time point should be completely *uncorrelated* with any previous motion. In contrast, if we consider a particle undergoing motion at a constant velocity, where at each point in time the particle is traveling at the same speed and in the same direction as the prior time point, its equation of motion would be *x*(*t*) = *vt* + *x*
_{0}, and the MSD would instead be proportional to the *squared* time.

Since Einstein's seminal work, it has been shown that there is essentially a continuous spectrum of MSD behavior,
\begin{equation}{\left\langle {\left( {x\left( t \right) - x\left( 0 \right)} \right)} \right\rangle ^2} \propto {t^\alpha },\end{equation}
where the value of *α* provides information about the physical environment of the particle. An *α* = 1 represents pure diffusion, *α* = 2 represents ballistic motion (constant velocity), and fractional values are generally referred to as *anomalous* or *non-Brownian* diffusion (6, 7).

Anomalous diffusion typically arises from a diffusing particle interacting with its local environment in a nonrandom or correlated manner. For instance, proteins diffusing in both prokaryotic and eukaryotic cells exhibit subdiffusive motion (*α* ∼ 0.7) because of viscoelastic properties of the cytoplasm that lead to anticorrelated motion (8–10). A number of biological systems exhibit subdiffusive motion (*α* < 1) because of similar mechanisms (e.g., bacterial plasmids and chromosomal loci [*α* ∼ 0.4] and eukaryotic cytoskeletal networks [*α* ∼ 0.7]) (11–14). Some biological systems exhibit superdiffusive motion *α* > 1, typically associated with active transport (e.g., cargo carried by molecular motors) (15).

Many different physical processes can lead to anomalous diffusion (e.g., viscoelasticity, memory, short-timescale binding events, molecular crowding) that result in different values of the exponent *α* (14). Thus, one of the most powerful biological applications of MSD measurements is analyzing the motion of a probe particle in vivo. By experimentally determining the functional form of the MSD we can elucidate mechanical details about the physical environment of the diffusing particle that are otherwise inaccessible (Fig 1).

Although popular undergraduate biophysics textbooks introduce the concepts of diffusion and MSD, most do not discuss the practical aspects of calculating MSD with the use of a variety of experimental data (16, 17). A number of laboratory exercises on characterizing diffusive systems have been described (18–23), but our goal here is to provide a laboratory exercise to introduce upper-level undergraduates to MSD that is flexible, modular, and applicable to a variety of institutions, departments, and teaching modalities. In our version of the exercise we focus our analysis on one practical consideration of MSD, *ergodicity*, in which averaging can either be taken over a single trajectory (time averaging) or as an average over many independent trajectories (ensemble averaging) (24, 25). For purely diffusive systems, the choice to perform either averaging method is typically determined by the practical limitations of the experiment. But, systems that exhibit anomalous diffusion tend to be *non-ergodic*; therefore, differences between averaging methods can be another indicator of anomalous behavior (24). Thus, our version of this exercise exploits MSD to focus less on calculating specific numbers and more on answering the question: Is the system purely diffusive or not?

The first implementation of this exercise was designed to be a standalone lab in our Experimental Biophysics course to be completed over three, 3-h meetings with 3-4 students (predominantly physics majors) working together in lab groups, with students submitting individual 4–6-page lab reports. Because of COVID-19 restrictions, the second implementation was employed completely online, with students performing particle tracking and data analysis on their personal computers asynchronously. Our institution offers 2 undergraduate courses in biophysics, Computational Biophysics and Experimental Biophysics, but this exercise could be performed in any computationally intensive upper-division course (e.g., computational physics, advanced lab).

Here, we include methods for data collection with micron-scale (μm) beads in inexpensive custom-made microchambers, open-source code for creating simulated particle trajectories, and preproduced simulated particle trajectories. We also include lesson plans for data analysis with both open-source code as well as instructions for spreadsheet processing depending on the intended level of instruction.

## II. SCIENTIFIC AND PEDAGOGICAL BACKGROUND

The mean squared displacement of a particle confined to move in 1 dimension is defined as 〈(*x*(*t*) − *x*(0))^{2}〉, where the angle brackets represent the arithmetic mean of a set of uncorrelated trajectories. For a particle undergoing pure diffusion, the MSD is proportional to time, 〈(*x*(*t*) − *x*(0))^{2}〉 = 2*Dt*, where *D* is the diffusion constant of the particle.

### A. Random walk model

The diffusion of small particles is well modeled by a random walk, where the trajectory of a particle can be approximated as a set of uncorrelated steps in random directions. To understand the source of linear time dependence in a diffusive MSD, we summarize the classic approach of Howard Berg (26): we can define the position of a particle undergoing 1-dimensional diffusion as:
\begin{equation}x\left( {n + 1} \right) = x\left( n \right) + Pd,\end{equation}
where *n* represents the number of steps, *d* represents the step size, and *P* is randomly chosen as either +1 or −1. If we now consider a set of *N* trajectories, we can take the mean position at (*n* + 1) as
\begin{equation}{1 \over N}\mathop \sum \limits_{i = 1}^N x\left( {n + 1} \right) = {1 \over N}\mathop \sum \limits_{i = 1}^N \left( {x\left( n \right) + {P_i}d} \right)\end{equation}
\begin{equation}{1 \over N}\mathop \sum \limits_{i = 1}^N x\left( {n + 1} \right) = {1 \over N}\mathop \sum \limits_{i = 1}^N x\left( n \right) + {1 \over N}\mathop \sum \limits_{i = 1}^N {P_i}d\end{equation}
because *P _{i}
* has equal probability of being +1 or −1. As

*N*gets large the last term sums to zero, and we can see that the mean position of the particles does not evolve in time; that is, \begin{equation}\left\langle {x\left( {n + 1} \right)} \right\rangle = \left\langle {x\left( n \right)} \right\rangle .\end{equation} Therefore, if all our particles start at

*x*= 0, the mean position of all trajectories will remain constant (i.e., 〈

*x*(

*t*)〉 = 0). If we now consider the squared position of our particle, \begin{equation}{x^2}\left( {n + 1} \right) = {\left( {x\left( n \right) + Pd} \right)^{2}} = {x^2}\left( n \right) + {P^2}{d^2} + 2Pdx\left( n \right),\end{equation} and again take the arithmetic mean of

*N*trajectories, \begin{equation}{1 \over N}\mathop \sum \limits_{i = 1}^N {x^2}\left( {n + 1} \right) = {1 \over N}\mathop \sum \limits_{i = 1}^N {x^2}\left( n \right) + {1 \over N}\mathop \sum \limits_{i = 1}^N {P_i}^2{d^2} + {1 \over N}\mathop \sum \limits_{i = 1}^N 2Pdx\left( n \right),\end{equation} the last term is again linear in

*P*and should sum to zero, but now we are left with \begin{equation}\left\langle {{x^2}\left( {n + 1} \right)} \right\rangle - \left\langle {{x^2}\left( n \right)} \right\rangle = {1 \over N}\left( {N{d^2}} \right) = {d^2}.\end{equation}

So we see that each successive step is a distance *d* away from the previous step, which in hindsight is an assumption of our model. At each successive step, we add another *d*
^{2} such that after *N* steps,
\begin{equation}\left\langle {{x^2}\left( N \right)} \right\rangle - \left\langle {{x^2}\left( 0 \right)} \right\rangle = N{d^2}.\end{equation}

If we assume that we take a constant number of steps per unit time, we can rewrite our MSD as
\begin{equation}\left\langle \left(x\left( t \right) - x\left( 0 \right) \right) \right\rangle ^2 \propto Dt,\end{equation}
where we define *D* roughly as the square of the average step size per unit time.

### B. Binomial distribution and Fick's law

For a more advanced introduction to diffusion, instructors may want to discuss the continuous limit of our random stepping model. We again suggest Berg (26) as an excellent reference, but for completeness we will again summarize his approach. The most straightforward extension of the random stepping model is to represent the position of our random walker using a binomial distribution, where the probability of taking exactly *L* steps to the left after *N* random steps is
\begin{equation}p\left( {L,N} \right) = {{N!} \over {L!\left( {N - L} \right)!}}{(1/2)^N}.\end{equation}

The total number of steps away from the origin (*S*) is just the number of steps to the left minus the number of steps to the right, which we can represent as (*N* − *L*), such that
\begin{equation}S\left( {L,N} \right) = \left( {L - \left( {N - L} \right)} \right) = \left( {2L - N} \right).\end{equation}
Thus, but substituting S into our probability function, we have
\begin{equation}p\left( {S,N} \right) = {{N!} \over {\left( {{{S + N} \over 2}} \right)!\left( {{{S - N} \over 2}} \right)!}}{(1/2)^N}.\end{equation}

For typical experimental conditions in which the random movement of particles is driven by thermal fluctuations (e.g., tracking a protein in a cell), we assume our walker takes a large number of very small steps during our observations. In this limit, we assume *N* to be very large, and because we have equal probability of taking a step to the left or right, we will also assume that the net number of steps from the origin (*S*) is much smaller than the total number of steps taken. Using these 2 approximations, we can make use of Stirling's approximation to simplify the factorials and a Taylor expansion of the resulting logarithms (a useful exercise) to derive the ubiquitous Gaussian (normal) distribution,
\begin{equation}p\left( {S,N} \right)dS = {1 \over {{{\left( {2\pi N} \right)}^{1/2}}}}{\rm{exp}}\left( { - {S^2}/2N} \right)dS,\end{equation}
which represents the probability of finding our random walker in a region of space between *S* and *S* + *dS*. We can now repeat a similar approach as the last section by defining a time step *τ*, such that the number of steps *N* = *t*/*τ*, and a step size *d*, such that the distance from the origin is *x = Sd*. By substituting our expression for *x* and defining a new constant *D* = *d*
^{2}/2*τ*, we arrive at the classic probability distribution for a 1-dimensional diffusing particle,
\begin{equation}p\left( {x,t} \right)dx = {1 \over {{{\left( {4\pi Dt} \right)}^{1/2}}}}{\rm{exp}}\left( { - {{\left( {x - {x_0}} \right)}^2}/4Dt} \right)dx,\end{equation}
where we have generalized the initial position of the particle as *x*
_{0}. For any function *f*(*x, t*), the average value, or expectation value, of that function in time is given by
\begin{equation}\left\langle {f\left( x \right)} \right\rangle = \mathop \int \limits_{ - \infty }^\infty f\left( x \right)p\left( {x,t} \right)dt.\end{equation}
Thus, the average value for the function *f*(*x*, *t*) = (*x*(*t*) − *x*
_{0})^{2} is given by
\begin{equation}{\left\langle {\left( {x\left( t \right) - {x_0}} \right)} \right\rangle ^2} = \mathop \int \limits_{ - \infty }^\infty {\left( {x\left( t \right) - {x_0}} \right)^2}p\left( {x,t} \right)dt = 2Dt.\end{equation}

A useful extension of this derivation for advanced students is to show by direct substitution that our probability density function *p*(*x*, *t*) for a diffusing particle in 1 dimension is also a solution to Fick's law:
\begin{equation}{{\partial p\left( {x,t} \right)} \over {\partial t}} = D{{{\partial ^2}p\left( {x,t} \right)} \over {\partial {x^2}}}.\end{equation}

## III. MATERIALS AND METHODS

Our aim is that this exercise is flexible and modular such that it can be implemented in a variety of different environments and modalities. The learning objectives for our face-to-face version of this exercise focus primarily on developing and applying experimental skills and analysis techniques applicable to modern biophysical research. These include literature review, sample preparation, microscopy, automated image analysis, and data analysis. An instructor of a more theoretical course may want to instead focus more on the scientific background of MSD, whereas an instructor of a computationally intensive course may want to focus more on simulation techniques or advanced statistical analysis. Furthermore, to make this exercise as accessible and equitable as possible, all of our protocols make use of freely available, open-source software. We also provide sample simulation and analysis programs, as well as prepackaged data as Supplemental Material.

### A. Data collection

To make this exercise accessible to a range of educational environments with a variety of time and equipment commitment, we provide 3 options for data collection in descending order of investment: tracking micron-sized bead diffusion by microscopy, simulating particle trajectories by molecular dynamics, and a spreadsheet of prepackaged trajectories ready for analysis.

#### 1. Bead microscopy

The richest version of this exercise includes collecting data of real diffusing particles because it requires the student to make decisions about practical aspects of experimental science (e.g., how many trajectories to collect, how long each trajectory should be), as well as address the limitations of the data itself (e.g., beads traveling in and out of focus). The following protocol is specific for our implementation of this exercise but can be easily modified for any high-magnification optical microscope equipped with a high-resolution digital camera. Note that in this implementation, data was collected by groups of 3 students over two, 3-h lab sessions.

Custom-made microchambers are constructed by placing 2 pieces of clear double-stick tape lengthwise on a standard microscope slide spaced approximately 1–2 mm away from each other. A standard 22 × 22-mm coverslip is placed on top of the tape, forming an open-ended channel with a volume of approximately 10 μL. A solution of suspended micron-sized silica beads can be pipetted through the channel by capillary action (Thorlabs, Newton, NJ; catalog OTKBTK), and each end can be sealed with nail polish or VALP, a heated wax mixture equal parts by weight of Vaseline (petroleum jelly), lanolin, and paraffin. A diagram of the slide design is included in Supplemental Figure S1. Note that tracking efficiency can be increased by the use of fluorescent beads (Thermo Fisher, Waltham, MA; catalog F13839), but they are not required. A variety of microscope control software and particle tracking tools are available, but in our implementation, time series images were collected by the open-source microscopy software μManager, version 1.4 (27, 28) and particle trajectories were created using the open-source particle tracking software TrackMate, version 4.0.0 (29) implemented through the open-source image-processing package Fiji (30). The frame rate and total number of frames are determined by the students and limited by the available computer memory, but typical data is on the order of 1 frame per second for at least 100 seconds.

#### 2. Simulated particle trajectories

An alternative version of this activity that provides equally valuable experience as gathering empirical data is producing particle trajectories by a simple random walk computational simulation. If time permits, we suggest acquiring both experimental and simulated trajectories to expose students to the important practical process of extracting relevant physical parameters (e.g., the diffusion constant) from simulations and comparing them with experimental data.

Numerous platforms and languages can be used to produce random walk trajectories, including spreadsheet programs; therefore, we begin by outlining the general simulation approach in a way that can be applied to a number of different programming environments. We also include a set of GNU Octave, version 4.4.1 (31) scripts (compatible with MATLAB) that produce particle trajectories, as well as a set of preproduced trajectories as Supplemental Material.

An individual particle trajectory is simulated by a recursive Langevin dynamics approach,
\begin{equation}x\left( {t + \delta t} \right) = x\left( t \right) + \xi {\left( {2D\delta t} \right)^{1/2}},\end{equation}
where *D* is the diffusion constant, *δt* is the simulation timestep, and *ξ* is a random number pulled from a normal distribution with mean 0 and variance 1. The simulation units are determined by the choice of both *D* and *δt* (e.g., if the simulated particle has a known diffusion constant of 1 μm^{2}/s, a choice of *D* = 1 and *δt =* 1 would give a timestep of 1 second and a distance unit of microns). To simulate higher dimensional motion, the recipe is the same, except that the random displacements in each direction should be uncorrelated, such that at each time step is
\begin{equation}x\left( {t + \delta t} \right) = x\left( t \right) + {\xi _x}{\left( {2D\delta t} \right)^{1/2}}\end{equation}
\begin{equation}y\left( {t + \delta t} \right) = y\left( t \right) + {\xi _y}{\left( {2D\delta t} \right)^{1/2}}\end{equation}
\begin{equation}z\left( {t + \delta t} \right) = z\left( t \right) + {\xi _z}{\left( {2D\delta t} \right)^{1/2}}\end{equation}
\begin{equation}\vec r\left( {t + \delta t} \right) = x\left( {t + \delta t} \right)\hat i + y\left( {t + \delta t} \right)\hat j + z\left( {t + \delta t} \right)\hat k.\end{equation}

Because a significant amount of cellular-scale transport relies on biasing diffusive motion [e.g., molecular motors (32) and DNA partitioning (12, 33)], an extremely useful and relevant extension of the simulation is to introduce some bias in the motion and further characterize the resulting MSD. Bias can be introduced by either adding a constant velocity term to the recursive relation (i.e., *vδt*) or by pulling *ξ* from a normal distribution with a nonzero mean.

## IV. DATA ANALYSIS

### A. Visualizing mean squared displacement

The first task we have our students perform after data collection is to plot all the trajectories on a single plot (Fig 2). Because this lab occurs in an upper-division course at our institution, we have our students plot in the open-source scientific programing language GNU Octave (31), which is compatible with the widely used proprietary software Matlab, but these plots can also be easily made in any spreadsheet software (e.g., Excel, Open Office, Google Sheets). By plotting the trajectories on a single graph, fundamental properties of the average displacement for an ensemble of tracks (e.g., zero mean and nonzero squared mean) can be easily visualized. A valuable extension of this exercise is also to plot a small number of tracks (*N* < 5) to demonstrate the variability in the data and the necessity of analyzing enough data to produce a meaningful average (Fig 2, inset).

### B. Computing mean squared displacement

The next task for our students is to determine the mean squared displacement MSD(*t*) = 〈(*x*(*t*) − *x*(0))^{2}〉, where the average should be taken over a set of uncorrelated trajectories. Typically an experiment will either produce a large set of uncorrelated trajectories by default (e.g., tracking the diffusion of many fluorescent beads in a single field of view) or produce a small set of long trajectories (e.g., the motion of a fluorescently tagged protein in a cell).

In the prior case, which we refer to as the *ensemble* method, computing the MSD is relatively straightforward. The process can be performed in a number of ways, but here we give a procedure for finding the MSD with a simple spreadsheet program by importing the trajectory data as columns on a spreadsheet. For each column (trajectory), subtract the value of the first time point from all successive time points and then square all of the values in the column. This should be the squared displacement for each trajectory. To compute the average at each time point [e.g., MSD(*t*)], simply average over all the rows at that time point, producing a new column of data, the MSD(*t*). Additional statistical parameters can be calculated at this point as well (e.g., the variance, standard deviation, and standard error), if applicable to the lesson. An example GNU Octave (31) script for calculating the ensemble MSD is included as Supplemental Material.

The latter case, which we refer to as the *time-average* method, is qualitatively straightforward but computationally more difficult than the ensemble method. The basic approach is to break a longer single trajectory of time duration *N* into many individual, nonoverlapping subtracks of length Δ*t*. For each subtrack, the squared displacement from the final position to the initial position can be calculated, and then the MSD(Δ*t*) for that particular time value is the average value of the displacement for all of the subtracks. The process is then repeated for a new set of nonoverlapping tracks of length (*t* + 1)*,* and so on until the trajectory can no longer be split into independent overlapping tracks (*t*/*N* < 2).

Because the single trajectory is being cut into nonoverlapping pieces, the number of independent trajectories used for averaging drops precipitously with increasing window size, drastically increasing the standard error. To mitigate this effect, Qian *et al*. (34) developed an analysis method that allows for splitting single trajectories into overlapping, and thus correlated, subtrajectories. In this approach, referred to as the *sliding window* averaging method, the trajectory is again split into tracks of length Δ*t*, but now the first track is from (*t*
_{0} → *t*
_{0} + Δ*t*), the second track from (*t*
_{1} → *t*
_{1} + Δ*t*), and so on. Just as before, the squared displacement for each subtrack is calculated, and the average is the MSD(Δ*t*) for that window size. Although the sliding window method drastically increases the number of subtrajectories used in the average, the correlation between subtrajectories becomes an issue as the window size increases. As the window size approaches the length of the total trajectory, the squared displacements become nearly identical because the first and last points of each subtrajectory are very near each other, and thus the average is no longer meaningful. To account for correlated tracks, Qian *et al*. (34) modified the standard error to
\begin{equation}{\rm{SE}} = 2Dt{\left[ {{{2{t^2} + 1} \over {3t\left( {N - t + 1} \right)}}} \right]^{1/2}},\end{equation}
where *N* is again the total number of time points in the track. A representation of the process for creating uncorrelated single tracks, as well as correlated sliding window tracks, is shown in Figure 3. An example of a GNU Octave (31) script for calculating both the uncorrelated time average and sliding window MSDs is included as Supplemental Material.

### C. Fitting mean squared displacement

The final set of analysis that we have our students perform is fitting their MSD functions, calculating relevant statistics, and testing for ergodicity. To first order, if their trajectories are purely diffusive and uncorrelated, their data should be well modeled by a proportional fit, where the slope of the line is proportional to the diffusion constant. The Stokes-Einstein equation,
\begin{equation}D = {{{k_b}T} \over {6\pi \eta R}},\end{equation}
famously relates the diffusion constant of a spherical particle of radius *R* to the thermodynamic energy (*k _{b}T*) dissipated by friction because of the viscous diffusive medium (dynamic viscosity

*η*). By calculating the empirical value of the diffusion coefficient from MSD data, students can compare their results to a theoretical value for a known particle size or determine physical properties of the system (e.g., temperature, viscosity). If the trajectories are created through simulations, similar learning objectives could be achieved by adjusting parameters in the track simulations and measuring the effects. A more advanced or computationally intensive implementation of this lab could include an expanded error analysis of the diffusion constant or more statistically advanced methods for determining the diffusion constant (e.g., maximum likelihood estimates), described thoroughly in the literature (35–37).

If the particles are undergoing pure diffusion, where each time step is completely uncorrelated, the process should be ergodic, and either time averaging a single track or ensemble averaging a set of tracks should provide the same diffusion coefficient. However, a practical consideration must be addressed in any experimental design: the statistical significance of the mean. In most cases, the primary consideration is the amount of data for a given interval of time. For ensemble averaging, we always have the same number of data points to average, and thus the standard error grows linearly. For single-track averaging, though, the number of data points diminishes with increased window size. For small time intervals, the single track may have a lower standard error than the ensemble (Fig 4A), whereas for long intervals, the ensemble will win, as seen in the inset of Figure 4A. The correlated time steps used in the sliding window method can reduce the standard error of a long track at smaller time steps, as seen in Figure 4B; however, the corrected standard error grows rapidly at larger time steps (Fig 4B, inset). Therefore, if one is interested in exploring short-timescale dynamics, an experiment should be designed to capture a small number of long trajectories, whereas a large number of shorter trajectories is more appropriate for long-timescale investigations.

## V. RESULTS AND DISCUSSION

We have employed this lab twice in our Experimental Biophysics lab course in 2 different modalities: face-to-face and completely online (because of COVID-19 restrictions). In the face-to-face version, students prepared slides and took data during the first 3-hour lab session, took additional data and began analysis in the second session, and completed analysis in the final session. In the online version, students were provided movie files of diffusing beads and performed particle tracking and analysis on their own computers asynchronously over a 3-week period. The use of free, open-source software was especially important to provide an equitable online learning environment. While lab groups and online discussion boards were facilitated through our learning management system (Canvas), the majority of students appeared to have completed the exercise alone.

The most challenging component of the lab for students is the computational analysis, specifically the time-averaged (sliding window) method for determining the MSD from a single trajectory. This is due to both conceptual misunderstanding and the computational challenge. In both teaching modalities, we initially provided little detail on how to calculate the averages, relying on the students to perform background literature review, which is a primary learning outcome of the course. This approach worked much better in the face-to-face version, where analysis was performed in the lab under instructor supervision, than in the online version, where analysis was performed individually and asynchronously. Because the primary goal of our version of the exercise was to verify ergodicity, the inconsistencies in time average analysis caused many students to arrive at the wrong conclusions. In whatever modality we employ this exercise next, we plan on providing more detailed instructions on how to compute the averages to alleviate student confusion and frustration and ensure that they arrive at the correct conclusions.

## VI. CONCLUSION

Because of the relatively young age and broad skillset of the field of biophysics, many of the standard research techniques used in graduate school and beyond have yet to be formally integrated into the undergraduate curriculum. Mean squared displacement has become a ubiquitous tool for characterizing biological systems, especially since the advent of fluorescence microscopy and sophisticated particle tracking algorithms. We believe that this flexible and adaptable activity can be successfully implemented in upper-division undergraduate courses across multiple disciplines and modalities, including courses that do not have a biological focus. The concepts discussed and skills gained are applicable to a broad range of science, technology, engineering, and math careers and will help the next generation of biophysicists be more prepared for our dynamic and rapidly expanding field.