## Introduction

In many experiments in biology, physics, and materials science, a microscopic colloidal particle is used to probe local forces1,2,3,4; this is the case, for example, in the measurement of the forces produced by biomolecules, cells, and colloidal interactions. Often particles are held by optical, acoustic, or magnetic tweezers in a harmonic trapping potential with stiffness k so that a homogeneous force acting on the particle results in a displacement Δx from the equilibrium position and can therefore be measured as kΔx. To perform such measurement, it is necessary to determine the value of k, which is often done by measuring the Brownian fluctuations of the particle around its stable equilibrium position. This is achieved by measuring the particle position as a function of time, x(t), and then using some calibration algorithms; the most commonly employed techniques are the potential5, the power spectral density (PSD)6, and the auto-correlation function (ACF)7 analyses (see Methods for details). The first method samples the particle position distribution ρ(x), calculates the potential using the Boltzmann factor, and then fits the value of k; this method requires a series of independent particle positions acquired over a time much longer than the system equilibration time to sample the probability distribution, and depends on the choice of some analysis parameters, such as the size of the bins. The latter two methods respectively calculate the PSD and ACF of the particle trajectory in the trap and fit them to their theoretical form to find the value of k; both methods require a time series of correlated particle positions at regular time intervals with a sufficiently short timestep Δt, and depend on the choice of some analysis parameters that determine how the fits are made.

Here we introduce a new powerful algorithm for microscopic force reconstruction via maximum-likelihood-estimator analysis (FORMA). FORMA exploits the fact that in the proximity of an equilibrium position the force field can be approximated by a linear form4,8, and therefore, optimally estimated using a linear maximum-likelihood-estimator (MLE)9,10. FORMA has several advantages over the methods mentioned above. First, FORMA executes much faster because its algorithm is based on linear algebra for which highly optimised libraries are readily available. Second, it requires less data and therefore it converges faster and with smaller error bars. Third, it has less stringent requirements on the input data, as it does not require a series of particle positions sampled at regular time intervals or for a time long enough to reconstruct the equilibrium distribution. Fourth, it is simpler to execute and automatise because it does not have any analysis parameter to be chosen. Fifth, it probes simultaneously the conservative and non-conservative components of the force field. Finally, as it does not need to use the trajectory of a particle held in a potential, it can identify and characterise both stable and unstable equilibrium points in extended force fields, and therefore it is compatible with a broader range of possible scenarios where a freely diffusing particle is used as a tracer, e.g., in microscopy and rheology.

## Results

### FORMA in one-dimension

To introduce the algorithm in the simplest one-dimensional (1D) situation, we start by considering a spherical microparticle of radius R immersed in a liquid with viscosity η, at temperature T, and held in a harmonic confining potential of stiffness k. Experimentally, we have used a standard optical tweezers with a single-focused laser beam to create a harmonic trap; in this configuration, the motion along each dimension is independent and can be treated separately as effectively 1D4. The details of the experimental setup are described in the Methods and Supplementary Figure 1. Briefly, we have employed a focused laser beam (Gaussian profile, linear polarisation, wavelength 532 nm, power at the sample 0.8 mW) and used it to trap a silica microsphere (R = 0.48 ± 0.02 μm) in an aqueous solution. We have tracked the particle position using digital video microscopy11 with a spatial resolution below 5 nm and with a frame frequency fs = 4504.5 s−1, corresponding to a sampling timestep Δt = 0.222 ms. Note that, as in the case of the PSD and ACF analyses, the sampling frequency needs to be at least about one order of magnitude greater than the characteristic trap frequency in order to obtain accurate results (see also Supplementary Figure 2). The corresponding overdamped Langevin equation is12:

$$\dot x = - {k\over\gamma} x + \sqrt {2D} w,$$
(1)

where x(t) is the 1D particle position, γ = 6πηR, D = kBT/γ, and w(t) is a 1D white noise. We assume to have N measurements of the particle displacement Δxn at position xn during a time Δtn, where n = 1,...,N (note that the time intervals do not need to be equal). Discretizing Eq. (1), we obtain that the average viscous friction force in the n-th time interval is

$$f_n = \gamma {\Delta x_n\over\Delta t_n} = - k x_n + \sigma w_n,$$
(2)

where $$\sigma = \sqrt {\frac{2D{\gamma} ^{2}}{{\mathrm{\Delta }}t_n}}$$ and wn is a Gaussian random number with zero mean and unit variance12. The central observation is that Eq. (2) is a linear regression model9,10, whose parameters, k and σ, can therefore be optimally estimated with a maximum-likelihood estimator from a series of observations of the dependent (fn) and independent (xn) variables, as schematically illustrated in Fig. 1. The detailed derivation is provided in the Methods for the general case. Wu et al.13 have proposed a direct force measurement method based on taking the average of fn around each position of the force field; this approach requires many more samples than FORMA. The MLE estimation of the trap stiffness is then

$$k^ \ast = {\mathop {\sum}\limits_n x_n f_n\over\mathop {\sum}\limits_n x_n^2}.$$
(3)

Equation (3) is indeed a very simple expression that can be executed extremely fast using standard highly optimised linear algebra libraries, such as LAPACK14, which is incorporated in most high-level programming languages, including MatLab and Python. Using the fact that fn + k*xn = σ wn (Eq. 2), we can estimate the diffusion coefficient as

$$D^ \ast = {1\over N}\mathop {\sum}\limits_n {{\mathrm{\Delta }} t_n\over 2\gamma^2}\left[ {f_n + k^ \ast x_n} \right]^2$$
(4)

and compare it to the expected value D, which provides an intrinsic quantitative consistency check for the quality of the estimation.

### Performance of FORMA

In Fig. 2a, we show the estimation of the trap stiffness as a function of the number of samples (orange line). Already with as little as 103 samples (corresponding to a total acquisition time of ~0.2 s), the stiffness has converged to its final value with small relative error (<20%), which improves as the number of samples increases reaching <2% relative error for 105 samples (~20 s). The quality of the estimation can be evaluated by estimating the diffusion coefficient D (Fig. 2b), which indeed converges to the expected value (dashed line) already for 103 samples with a 3% relative error. Even for the highest number of samples, the algorithm execution time is in the order of a few milliseconds on a laptop computer (Fig. 2c). We have further verified these results on simulated data with physical parameters equal to the experimental ones (Fig. 2d–f). These simulations are in very good agreement with the results of the experiments and, given that the value of k is fixed and known a priori (dashed line in Fig. 2d), they demonstrate the high accuracy of FORMA estimation: FORMA converges to the ground truth value of k for about 104 samples with 10% relative error, which, as in the experiments, reduces to 2% for 105 samples.

In Fig. 2, we also compare the performance of FORMA with other established methods typically used in the calibration of optical tweezers, i.e. the potential, PSD, and ACF analyses4,5,6,7 (the details and parameters used for these analyses are provided in the Methods). Overall, these results show that FORMA is more precise than other methods when estimating k for a given number of samples, as the other methods typically need 10–100 times more data points to obtain comparable relative errors (Fig. 2a, b, d, and e). FORMA also executes faster by one to two orders of magnitude than the other methods (Fig. 2c, f). The relative errors of the FORMA estimation are also typically smaller, being 2% for 105 samples, while the potential, PSD and ACF analyses achieve relative errors larger than 6, 7, and 20%, respectively. FORMA is also more accurate in estimating the value of k, as can been seen comparing experiments and simulations (Fig. 2a, d): whereas the potential and ACF analyses also converge to the correct k value, the PSD analysis introduces a significant bias in the estimation (around 8%). Although for the specific case of the potential analysis (green lines), FORMA’s performance can be considered a marginal improvement in terms of accuracy, it actually provides access to additional information that the potential analysis does not provide, namely the estimation of the diffusion coefficient D. Nonetheless, FORMA is significantly more accurate than the PSD analysis (blue lines), whose estimated k and D present a systematic error; with experience this error can be reduced by tweaking the fitting PSD range, although this process can still be tricky without knowing a priori the value of k. Finally, FORMA is also significantly more precise and about two orders of magnitude faster than the ACF analysis (pink lines), which in fact is the least precise and the slowest method with 20% relative error and 100 ms execution time for 105 samples, while FORMA has 2% relative error and 2 ms execution time for the same number of samples.

### FORMA in two-dimensions

We now generalise FORMA to the two-dimensional (2D) case. Beyond a conservative component that is also present in 1D force fields, 2D force fields can also feature a non-conservative component8; as we will see, FORMA is able to estimate both simultaneously, differently from most other methods. The overdamped Langevin equation is now best written in vectorial form as

$$\dot {\mathbf{r}} = {1\over\gamma} {\mathbf{F}}({\mathbf{r}}) + \sqrt {2D} \, {\mathbf{w}},$$
(5)

where F(r) is a force field and w is a vector of independent white noises. F(r) can be expanded in Taylor series around 0 as F(r) = F0 + J0r + o(r), where F0 = F(0) is the force and J0 = J(0) the Jacobian at 0. If we assume that 0 is an equilibrium point, then F0 = 0; with this assumption, the results in the following become much simpler without loss of generality, as this is equivalent to translating the experimental reference frame so that it is centred at the equilibrium position (we discuss below how to proceed if the equilibrium position is not known). Analogously to the 1D case explained above, using Eq. (5) the average friction force in the n-th time interval is

$${\mathbf{f}}_n = \gamma \frac{{{\mathrm{\Delta }}{\mathbf{r}}_n}}{{{\mathrm{\Delta }}t_n}} = {\mathbf{J}}_0{\mathbf{r}}_n + \sigma {\mathbf{w}}_n,$$
(6)

where wn is an array of independent random numbers with zero mean and unit variance. Eq. (6) is again a linear regression model and therefore the MLE estimator of J0 is given by

$${\mathbf{J}}_0^ {\ast} = \left[ {{\mathbf{r}}^{\mathrm{T}}{\mathbf{r}}} \right]^{ - 1}{\mathbf{r}}^{\mathrm{T}}{\mathbf{f}},$$
(7)

where r = (rn) and f = (fn) are matrices with N × 2 elements. Eq. (6) can be computed extremely efficiently as it only requires matrix multiplications and the trivial inversion of a 2 × 2 matrix. As in the 1D case, we can calculate the residual error (see Methods) and use it to determine the quality of the reconstruction of the force field by estimating the value of the diffusion coefficient along each of the two axes.

A schematic of the workflow of the 2D version of FORMA is presented in Fig. 3a–c. The estimated force field around the equilibrium point is $${\mathbf{F}}^ \ast (\mathbf{r}) = {\mathbf{J}}_0^ \ast \,{\mathbf{r}}$$, where we use the estimated Jacobian8 (Eq. 7). This is a linear form that results from the superposition of a conservative harmonic potential (which is characterised by its stiffnesses $$k_1^ \ast$$ and $$k_2^ \ast$$ along the principle axes, and the orientation θ* of the principle axes with respect to the Cartesian axes) and a non-conservative rotational force field (which is characterised by its angular frequency Ω*). Some examples of this decomposition are shown in Supplementary Figure 3. It is possible to obtain these two components directly from the Jacobian, by separating it into its conservative and non-conservative parts as $${\mathbf{J}}_0^ \ast = {\mathbf{J}}_{\mathrm{c}}^ \ast + {\mathbf{J}}_{\mathrm{r}}^ \ast$$, making use of the fact that they are respectively symmetric and antisymmetric. The conservative part is

$${\mathbf{J}}_{\mathrm{c}}^ \ast = {1\over 2}({\mathbf{J}}_0^ \ast + {\mathbf{J}}_0^{ \ast {\mathrm{T}}}) = {\mathbf{R}}(\theta ^ \ast )\left[ {\begin{array}{*{20}{c}} { - k_1^ \ast } & 0 \\ 0 & { - k_2^ \ast } \end{array}} \right]{\mathbf{R}}^{ - 1}(\theta ^ \ast ),$$
(8)

where R(θ) is a rotation matrix that diagonalises Jc and whose principal axes correspond to the eigenvectors corresponding to the principle axes of the harmonic potential and the stiffnesses along these axes correspond to the eigenvalues with a minus sign. The non-conservative (rotational) part is

$${\mathbf{J}}_{\mathrm{r}}^ \ast = {1\over2}\left( {{\mathbf{J}}_0^ \ast - {\mathbf{J}}_0^{ \ast {\mathrm{T}}}} \right) = \left[ {\begin{array}{*{20}{c}} 0 & { - \gamma {\mathrm{\Omega }}} \\ {\gamma {\mathrm{\Omega }}} & 0 \end{array}} \right]$$
(9)

and, as it is invariant under a rotation of the reference system, the angular frequency can be simply estimated as

$$\Omega ^ \ast = {1\over2\gamma} \left[ {J_{0,21}^ \ast - J_{0,12}^ \ast } \right].$$
(10)

To demonstrate this 2D version of FORMA at work, we have used it to estimate the transfer of orbital and spin angular momentum to an optically trapped particle. In fact, orbital and spin angular momentum can make a transparent particle orbit, even though the precise angular-momentum-transfer mechanisms can be very complex when the beam is tightly focused, depending on the size, shape and material of the particle, as well as on the size and shape of the beam13,15,16,17,18,19. We employ the same setup and microparticle as for the results presented in Fig. 2 (see Methods and Supplementary Figure 1), using a spatial light modulator to generate Laguerre-Gaussian (LG) beams carrying orbital angular momentum (OAM) to trap the particle and a quarter-wave plate to switch their polarisation state from linear to positive or negative circular polarisation. The results of the force field reconstruction are the stiffnesses kx and ky (Fig. 3d–f) and the angular frequencies Ω (Fig. 3g–i) of a Brownian particle optically trapped in various LG beams. In Fig. 3d, g, we employ a linearly polarized LG beam with topological charge l = −2, −1, 0, 1, 2 (the case l = 0 corresponds to the standard Gaussian beam already employed in Fig. 2). As already observed in previous experiments, we also measure that Ω* is proportional to l* ≈ 1.8 s−1l), which follows the quantisation of the OAM20. We have verified that these values are in good quantitative agreement with those obtained using the more standard cross-correlation function (CCF) analysis, which is an extension of the ACF analysis that permits one to detect the presence of non-conservative force fields8. These non-conservative rotational force fields are very small, produce an almost imperceptible bending of the force lines when comparing LG0 with LG2 (insets of Fig. 3g), and, therefore, cannot be detected by directly counting rotations of the particle around the beam axis. To further test our results, we have then changed the polarisation state of the beam switching it to positive circular polarisation (Fig. 3e, h), which introduces an additional spin angular momentum (SAM), so that Ω* ≈ 1.8 s−1(l + 1), recovering the SAM quantisation. This relation suggests that the OAM and SAM contribute equally to the rotation of the particle. We finally changed the polarisation state of the beam to negative circular polarisation (Fig. 3f, i) obtaining Ω* ≈ 1.8 s−1(l − 1).

### FORMA in three-dimensions

Following the same procedure, FORMA can be extended also to measure three-dimensional (3D) force fields. The resulting equations are provided in the Methods, and we have tested them on simulated data (see Supplementary Table 1).

### Measurement of stable and unstable equilibrium points

Until now, we have always centred the reference frame at the equilibrium position. However, the positions of the equilibria might be unknown a priori, for example when exploring extended potential landscapes. FORMA can be further refined to address this problem and determine the value of F0 in Eq. (5), which permits one to identify equilibrium points when F0 = 0. We obtain the following estimator (see Methods for detailed derivation):

$$\left[ {{\mathbf{J}}_0^ \ast {\mathbf{F}}_0^ \ast } \right] = \left( {\widetilde {\mathbf{r}}^{\mathrm{T}}\widetilde {\mathbf{r}}} \right)^{ - 1}\widetilde {\mathbf{r}}^{\mathrm{T}}{\mathbf{f}},$$
(11)

where $$\widetilde {\mathbf{r}} = [{\mathbf{r}}\,{\mathbf{1}}]$$ with 1 a column vector constituted of N ones. Having the trajectory of a particle moving in an extended potential landscape, it is possible to use Eq. (11) to simultaneously identify the equilibrium points, classify their stability, and characterise their local force field: For each position in the potential landscape, the parts of the trajectory that fall within a radius a smaller than the characteristic length over which the force field varies from this position are selected and analysed with FORMA; if $${\mathbf{F}}_0^ \ast \approx {\mathbf{0}}$$, then this position is an equilibrium point and $${\mathbf{J}}_0^ \ast$$ permits us to determine the local force field.

We have applied this procedure to identify the equilibrium points in a multistable potential, which we realised focusing two slightly displaced laser beams obtained using a spatial light modulator (see Methods and Supplementary Figure 1). Similar configurations have been extensively studied as a model system for thermally activated transitions in bistable potentials21,22; however, the presence of additional minima other than the two typically expected has been recognized only recently due to their weak elusive nature23. The results of the reconstruction are shown in Fig. 4. In Fig. 4a, we use the potential analysis to determine the potential (green solid line with error bars denoted by the shaded area) by acquiring a sufficiently long trajectory so that the particle has equilibrated and fully explored the region of interest; this potential appears to be bistable with two potential minima (stable equilibrium points) and a potential barrier between them corresponding to an unstable equilibrium point. When we use FORMA, we identify five equilibria, and classify them as stable ($$x_1^ \ast$$, $$x_3^ \ast$$, $$x_5^ \ast$$; full circles) and unstable ($$x_2^ \ast$$, $$x_4^ \ast$$; empty circles); importantly, we are able to clearly resolve the presence of additional equilibrium points within the potential barrier ($$x_2^ \ast$$, $$x_3^ \ast$$, $$x_4^ \ast$$). For each point, FORMA provides the respective stiffness (the corresponding harmonic potentials are shown by the orange lines), which is negative for unstable equilibrium points. This highlights one of the additional key advantages of FORMA: It can also measure the properties of the force field around unstable equilibrium points, thanks to the fact that it does not require an uninterrupted series of data points or a complete sampling of the equilibrium distribution, which are difficult or impossible near an unstable equilibrium. Figure 4b shows a 2D view of the potential, where we used FORMA to estimate the force field on a 2D grid and to identify the stable and unstable equilibria. The background colour represents the potential reconstructed using the equilibrium distribution, which shows a good agreement with the results of FORMA, but does not allow to clearly identify the presence of the additional equilibria in the potential barrier.

### Measurement of extended force fields

Finally, we can also use FORMA to study larger extended force fields, such as the random optical force fields generated by speckle patterns24,25,26,27,28. Speckles are complex interference patterns with well-defined statistical properties generated by the scattering of coherent light by disordered structures29; the equilibrium positions are not known a priori due to their random appearance, the configuration space is virtually infinite, and there can be a non-conservative component. Thus, the challenge is at least twofold. First, the configuration space is virtually infinite and, therefore, cannot be sampled by a single trajectory in any reasonable amount of time. Second, the force field can present a non-conservative component; in fact, whereas several works have demonstrated micromanipulation with speckle patterns24,25,26,27,28, none of them has so far achieved the experimental characterisation of this non-conservative nature of the optical forces. To study this situation, we have employed a speckle light field generated using a second optical setup (see Methods and Supplementary Figure 4). A portion of the resulting speckle field is shown by the green background in Fig. 5a. To sample the force field, we have acquired the trajectories of a particle in various regions of the speckle field: In each of these trajectories the particle typically explores the regions surrounding several contiguous stable equilibrium points by being metastably trapped in each of them while still being able to cross over the potential barriers separating them30. These trajectories cannot be used in the potential analysis because they do not provide a fair sampling of the position space. Nevertheless, they can be used by FORMA to identify the equilibrium points, which are shown in Fig. 5a by the full circles (stable points) and empty circles (unstable and saddle points), and to determine the force field around them (see Supplementary Table 2 for the measured values): For example, in Fig. 5b we show a stable point, in Fig. 5c an unstable point with a significant rotational component, and in Fig. 5d a series of two stable points with a saddle between them in a configuration reminiscent of that explored in Fig. 4.

## Discussion

We have introduced FORMA: a new, powerful algorithm to measure microscopic force fields using the Brownian motion of a microscopic particle based on a linear MLE. We first introduced the 1D version of FORMA; we quantitatively compared it to other standard methods, showing that it needs less samples, it has smaller relative errors, it is more accurate, and it is orders-of-magnitude faster. We then introduced the 2D version of FORMA; we showed that it can also measure the presence of a non-conservative force field, going beyond what can be done by the other methods. Finally, we applied it to more general force-field landscapes, including situations where the shape of the potential is not harmonic and the forces are too shallow to achieve long-term trapping: we used FORMA to identify the equilibrium points; to classify them as stable, unstable and saddle points; and to characterise their local force fields. Overall, we have shown that, requiring less data and having a faster run time, FORMA can be applied to situations that require a fast response such as in real-time applications (e.g., in haptic optical tweezers31) and in the presence of time-varying conditions (e.g., in the study of biological systems32,33,34, of active baths35,36 and of systems out of equilibrium37,38,39). Even though we have presented results only for particles of a single size, FORMA can be used as described in this work for spherical particles of any size, from Rayleigh particles much smaller than the optical wavelength to large Mie particles. FORMA can be straighforwardly extended also to measure flow fields and 3D force fields. FORMA can also be extended to deal with non-translational degrees of freedom, which might be important when dealing with non-spherical particles. For force fields that cannot be approximated by a linear form around an equilibrium position, because J0 = 0, FORMA needs to be extended using a higher-order MLE estimator. Thanks to the fact that this algorithm is significantly faster, simpler and more robust than commonly employed alternatives, it has the potential to accelerate the development of force transducers capable of measuring and applying forces on microscopic and nanoscopic scales, which are needed in many areas of physics, biology, and engineering.

## Methods

### Potential analysis

The potential method4,5 relies on the fact that a harmonic potential has the form U(x) = $$\frac{1}{2}$$ kx2 and the associated position probability distribution of the particle is $$\rho (x) = \rho _0{\mathrm{exp}}\left( { - \frac{{U(x)}}{{{k}_{\mathrm{B}}T}}} \right)$$. Therefore, by sampling ρ(x) it is possible to reconstruct U(x) = −kBln(ρ(x)) and $$F(x) = { - \frac{{\mathrm{d}}U(x)}{{\mathrm{d}}x}}$$. The value of k is finally obtained by fitting F(x) to a linear function. The potential method requires a series of particle positions acquired over a time long enough for the system to equilibrate as well as the choice of the number of bins and of the fitting algorithm to be employed in the analysis: here, we used 100 bins equally spaced between the minimum and maximum value of the particle position, and a linear fitting.

### Power spectral density analysis

The PSD method4,6 uses the particle trajectory in the harmonic trap, x(t), to calculate the PSD, $$P(f) = \frac{D}{{2\pi ^2}}(f_{\mathrm{c}}^2 + f^2)^{ - 1}$$, where fc = (2πγ)−1k is the harmonic trap cutoff frequency, γ is the particle friction coefficient, and D is its diffusion coefficient. It then fits this function to find the value of k, and therefore the harmonic force field surrounding the particle. The PSD method requires a time series of correlated particle positions at regular time intervals with a sufficiently short timestep Δt. It also requires to choose how the PSD is calculated (e.g., use of windowing and binning6) and the frequency range over which the fitting is made: here, we performed the PSD fitting over the frequency range between five times the minimum measured frequency and half the Nyquist frequency without using windowing and binning.

### Auto-correlation function analysis

The ACF method4,7 calculates the ACF of the particle position, $$C(\tau ) = \frac{{k_{\mathrm{B}}T}}{k}{\mathrm{exp}}\left( { - \frac{{k|\tau |}}{\gamma }} \right)$$, where kB is the Boltzmann constant and T is the absolute temperature. It then fits this function to find the value of k, and therefore the harmonic force field surrounding the particle. Like the PSD method, also the ACF method requires a time series of correlated particle positions at regular time intervals. It also requires to choose over which range to perform the fitting: here, we have performed the fitting over the values of the ACF >1% its maximum.

### Experimental setups

For the single-beam (Figs. 2 and 3) and two-beam (Fig. 4) experiments, we used the standard optical tweezers shown in Supplementary Figure 14,28,40. An expanded 532-nm-wavelength laser beam (power at the sample 0.8 mW) is reflected by a spatial light modulator (SLM) in a 4f-configuration with a diaphragm in the Fourier space acting as spatial filter4,28. By altering the phase profile of the beam we generate different beams, including the Gaussian beam used in Fig. 2, the Laguerre-Gaussian beams with l = −2, −1, 0, 1, 2 used in Fig. 3, and the double beam used in Fig. 4. We control the polarization of the beam using a quarter-wave plate, which permits us to switch the polarisation state of the beam between linearly polarised (Fig. 3d, g), circularly (+) polarised (Fig. 3e, h), and circularly (−) polarised (Fig. 3f, i). These experiments are performed with spherical silica microparticles with radius R = 0.48 ± 0.02 μm in an aqueous medium of viscosity η = 0.0011 Pa s−1 (corrected using Faxén formula for the proximity of the cover slip41) whose position is acquired with digital video microscopy11 at a sampling frequency fs = 4504.5 s−1 and a resolution below 5 nm.

For the speckle experiments (Fig. 5), we used the SLM in the image plane, as shown in Supplementary Figure 4: The 532-nm laser beam is reflected by the SLM, which projects a random phase (with uniform distribution of values in (0, 2π)) in every domain of 6 × 6 pixels, and is directed to the sample using two telescopes. We control the effective numerical aperture of the system, and therefore the grain size of the speckle, by using a diaphragm with a diameter Di = 1.54 ± 0.05 mm in the Fourier plane of the first telescope. The mean intensity of the speckle is 0.015 mW μm−2. These experiments are performed with spherical polystyrene microparticles with radius R = 0.50 ± 0.02 μm in an aqueous medium of viscosity η = 0.0013 Pa s−1 measured by using the mean diffusion of the particle in the speckle pattern obtained from FORMA and using Einstein-Stokes relation. Because of the radiation pressure of the optical forces generated by the speckle light field, the probe bead is pushed towards the upper cover slip (without touching it because of screened electrostatic repulsion), where it remains confined in a quasi-2D configuration and diffuses exploring a wide area. In order to have control of the region of interest the initial positions of the particles were prepared using an optical trap generated with the same laser beam and SLM. The particle’s position is recorded for 2 × 106 frames each at a sampling frequency fs = 600 s−1.

### Detailed derivation of FORMA in two-dimensions

Here we derive FORMA in its most general form presented in the article (Eq. 11). The average friction force in the n-th time interval is

$${\mathbf{f}}_n = \gamma \frac{{{\mathrm{\Delta }}{\mathbf{r}}_n}}{{{\mathrm{\Delta }}t_n}} = {\mathbf{F}}_0 + {\mathbf{J}}_0{\mathbf{r}}_n + \sqrt {\frac{{2k_{\mathrm{B}}T\gamma }}{{{\mathrm{\Delta }}t_n}}} {\mathbf{w}}_n,$$
(12)

which can be rewritten explicitly as

$$\left[ {\begin{array}{*{20}{c}} {f_{{\mathrm{x}},n}} \\ {f_{{\mathrm{y}},n}} \end{array}} \right] \approx \left[ {\begin{array}{*{20}{c}} {J_{0,11}} & {J_{0,12}} & {F_{0,{\mathrm{x}}}} \\ {J_{0,21}} & {J_{0,22}} & {F_{0,{\mathrm{y}}}} \end{array}} \right]\left[ {\begin{array}{*{20}{c}} {x_n} \\ {y_n} \\ 1 \end{array}} \right] + \sqrt {\frac{{2k_{\mathrm{B}}T\gamma }}{{{\mathrm{\Delta }}t}}} \left[ {\begin{array}{*{20}{c}} {w_{{\mathrm{x}},n}} \\ {w_{{\mathrm{y}},n}} \end{array}} \right],$$
(13)

Assuming to have N measurements, we introduce the vectors

$${\mathbf{f}} = \left[ {\begin{array}{*{20}{c}} {\gamma \frac{{{\mathrm{\Delta }}x_1}}{{{\mathrm{\Delta }}t_1}}} & {\gamma \frac{{{\mathrm{\Delta }}y_1}}{{{\mathrm{\Delta }}t_1}}} \\ {...} & {...} \\ {\gamma \frac{{{\mathrm{\Delta }}x_n}}{{{\mathrm{\Delta }}t_n}}} & {\gamma \frac{{{\mathrm{\Delta }}y_n}}{{{\mathrm{\Delta }}t_n}}} \\ {...} & {...} \\ {\gamma \frac{{{\mathrm{\Delta }}x_N}}{{{\mathrm{\Delta }}t_N}}} & {\gamma \frac{{{\mathrm{\Delta }}y_N}}{{{\mathrm{\Delta }}t_N}}} \end{array}} \right]$$
(14)

and

$$\widetilde {\mathbf{r}} = \left[ {\begin{array}{*{20}{c}} {x_1} & {y_1} & 1 \\ {...} & {...} & {...} \\ {x_n} & {y_n} & 1 \\ {...} & {...} & {...} \\ {x_N} & {y_N} & 1 \end{array}} \right],$$
(15)

the MLE is given by Eq. (11), i.e.,

$$\left[ {{\mathbf{J}}_0^ \ast \; {\mathbf{F}}_0^ \ast } \right] = \left[ {\begin{array}{*{20}{c}} {J_{0,11}^ \ast } & {J_{0,12}^ \ast } & {F_{0,x}^ \ast } \\ {J_{0,21}^ \ast } & {J_{0,22}^ \ast } & {F_{0,y}^ \ast } \end{array}} \right] = \left( {\widetilde {\mathbf{r}}^{\mathrm{T}}\widetilde {\mathbf{r}}} \right)^{ - 1}\widetilde {\mathbf{r}}^{\mathrm{T}}{\mathbf{f}}$$

and the estimated particle diffusivity along each axis can be calculated from the residual error of the MLE

$$\begin{array}{*{20}{c}} {D_{\mathrm{x}}^ \ast } & = & {{1\over N}\mathop {\sum}\limits_{n = 1}^N \frac{{{\mathrm{\Delta }}t_n}}{{2\gamma ^2}}\left( {f_{{\mathrm{x}},n} - J_{0,11}^ \ast {\kern 1pt} x_n - J_{0,12}^ \ast {\kern 1pt} y_n - F_{0,{\mathrm{x}}}^ \ast } \right)^2} \\ {D_{\mathrm{y}}^ \ast } & = & {{1\over N}\mathop {\sum}\limits_{n = 1}^N \frac{{{\mathrm{\Delta }}t_n}}{{2\gamma ^2}}\left( {f_{{\mathrm{y,}}n} - J_{0,21}^ \ast x_n - J_{0,22}^ \ast y_n - F_{0,{\mathrm{y}}}^ \ast } \right)^2} \end{array}$$
(16)

### Codes

We provide the MatLab implementations of the key functionalities of FORMA42.

For the 1D version of FORMA, we provide the following codes: function forma1d.m, script test_forma1d.m to execute it, and set of test data forma1d.mat. This code estimates the values of k* and D* assuming that the equilibrium position is at x = 0 and implementing Eqs. (3) and (4).

For the 2D version of FORMA, we provide the following codes: function forma2d.m, script test_forma2d.m to execute it, and set of test data forma2d.mat. This code estimates the value of $$k_1^ \ast$$, $$k_2^ \ast$$, θ*, and Ω* assuming that the equilibrium position is at r0 = 0 and implementing Eqs. (7), (8), and (10).

### FORMA in three-dimensions

Following the same steps as in the previous sections, the MLE of a particle in 3D near an equilibrium position can be explicitly written as

$${\mathbf{J}}_0^ \ast = \left[ {\begin{array}{*{20}{c}} {J_{0,11}^ \ast } & {J_{0,12}^ \ast } & {J_{0,13}^ \ast } \\ {J_{0,21}^ \ast } & {J_{0,22}^ \ast } & {J_{0,23}^ \ast } \\ {J_{0,31}^ \ast } & {J_{0,32}^ \ast } & {J_{0,33}^ \ast } \end{array}} \right] = \left( {\widetilde {\mathbf{r}}^{\mathrm{T}}\widetilde {\mathbf{r}}} \right)^{ - 1}\widetilde {\mathbf{r}}^{\mathrm{T}}{\mathbf{f}},$$
(17)

where f and $$\widetilde {\mathbf{r}}$$ are the corresponding 3D extensions of Eqs. (14) and (15). The estimated particle diffusivity along each axis can be calculated from the residual error of the MLE

$$\begin{array}{*{20}{c}} {D_{\mathrm{x}}^ {\ast} } & = & {{1\over N}\mathop {\sum}\limits_{n = 1}^N \frac{{\Delta t_n}}{{2\gamma ^2}}\left( {f_{{\mathrm{x}},n} - J_{0,11}^ {\ast} {\kern 1pt} x_n - J_{0,12}^ {\ast} y_n - J_{0,13}^ \ast z_n} \right)^2,} \\ {D_{\mathrm{y}}^ {\ast} } & = & {{1\over N}\mathop {\sum}\limits_{n = 1}^N \frac{{\Delta t_n}}{{2\gamma ^2}}\left( {f_{{\mathrm{y}},n} - J_{0,21}^ {\ast} x_n - J_{0,22}^ {\ast} y_n - J_{0,23}^ {\ast} z_n} \right)^2,} \\ {D_{\mathrm{z}}^ {\ast} } & = & {{1\over N}\mathop {\sum}\limits_{n = 1}^N \frac{{\Delta t_n}}{{2\gamma ^2}}\left( {f_{{\mathrm{z}},n} - J_{0,31}^ {\ast} {\kern 1pt} x_n - J_{0,32}^ {\ast} y_n - J_{0,33}^ {\ast} z_n} \right)^2.} \end{array}$$
(18)

Using Brownian simulations, we were able to prove the performance of this method in 3D. The data in the Supplementary Table 1 show the results of the analysis of an hypothetic optical trap with defined properties along the three axis.