Smooth a Simulated Particle Trajectory
Use a combination of BlockMap and TrimmedMean to smooth out data from a particle trajectory.
Simulate a stochastic path by adding noise to an exact trajectory.
In[1]:=
exact[u_] := {u Cos[u], u Sin[u]}
noise[u_] := RandomReal[CauchyDistribution[0, 1], 2]
data = Table[exact[u] + noise[u], {u, 0, 6 \[Pi], 1/100}];
In[2]:=
ListPlot[data, AspectRatio -> Automatic]
Out[2]=
Smooth the simulated trajectory with BlockMap using a moving TrimmedMean to eliminate possible outliers.
In[3]:=
smooth[r_] := BlockMap[TrimmedMean, data, r, 1]
Increase the window size to get a smoother trajectory.
In[4]:=
Table[ListPlot[smooth[r],
AspectRatio -> Automatic], {r, {25, 50, 100, 200}}]
Out[4]=