%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%22marimo%3E%3D0.23.9%22%2C%20%22numpy%3E%3D2.0%22%2C%20%22matplotlib%3E%3D3.9%22%2C%20%22pandas%3E%3D2.2%22%2C%20%22scipy%3E%3D1.14%22%2C%20%22urllib3%3E%3D2.2%22%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Postural%20sway%3A%20rambling%20and%20trembling%0A%0A%20%20%20%20%3E%20Marcos%20Duarte%2C%20Renato%20Naville%20Watanabe%3Cbr%3E%0A%20%20%20%20%3E%20%5BLaboratory%20of%20Biomechanics%20and%20Motor%20Control%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br%2F)%3Cbr%3E%0A%20%20%20%20%3E%20Federal%20University%20of%20ABC%2C%20Brazil%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20use%20this%20guide%0A%0A%20%20%20%20The%20centre%20of%20pressure%20moves%20even%20while%20a%20person%20tries%20to%20stand%20still.%20Can%20we%20describe%20that%20motion%20as%20a%20moving%20reference%20plus%20deviations%20around%20it%3F%0A%0A%20%20%20%20We%20will%20examine%20the%20instant-equilibrium-point%20hypothesis%2C%20perform%20the%20decomposition%20on%20a%20public%20recording%2C%20and%20compare%20it%20with%20a%20COP%E2%80%93COG%20estimate.%20The%20batch%20examples%20retain%20subject-level%20summaries%20and%20explicit%20trial%20selection.%0A%0A%20%20%20%20Predict%20the%20result%20before%20running%20each%20example.%20Try%20the%20**Exercises**%20before%20opening%20their%20worked%20solutions.%20Finish%20with%20the%20**Checkpoint%20questions**%20and%20**Problems**%3B%20the%20latter%20provide%20final%20answers%20only.%0A%0A%20%20%20%20Open%20this%20file%20locally%20in%20marimo%2C%20on%20%5Bmarimo.app%5D(https%3A%2F%2Fmarimo.app%2F)%2C%20or%20in%20%5Bmolab%5D(https%3A%2F%2Fmolab.marimo.io%2Fnotebooks).%20Data%20come%20from%20the%20public%20Santos%E2%80%93Duarte%20balance%20dataset.%20The%20selected%20trial%20and%20metadata%20are%20downloaded%20if%20they%20are%20not%20already%20available%3B%20no%20private%20computer%20paths%20or%20automatic%20population-wide%20processing%20remain.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Python%20setup%0A%0A%20%20%20%20NumPy%20and%20pandas%20hold%20the%20recordings%3B%20SciPy%20interpolates%20the%20zero-force%20points%2C%20and%20Matplotlib%20shows%20the%20components.%20The%20data%20loader%20and%20analysis%20functions%20are%20included%20in%20this%20file.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%0A%20%20%20%20return%20mo%2C%20np%2C%20pd%2C%20plt%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20from%20notebook_resources%20import%20repo_file%0A%20%20%20%20except%20ModuleNotFoundError%20as%20_error%3A%0A%20%20%20%20%20%20%20%20if%20_error.name%20!%3D%20%22notebook_resources%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%0A%20%20%20%20%20%20%20%20raise%20ModuleNotFoundError(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22This%20notebook%20needs%20notebook_resources.py.%20Download%20it%20from%3A%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fraw.githubusercontent.com%2FBMClab%2FBMC%2Fmaster%2Ffunctions%2Fnotebook_resources.py%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Save%20it%20in%20the%20same%20folder%20as%20this%20notebook%2C%20then%20rerun%20this%20cell.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22notebook_resources%22%2C%0A%20%20%20%20%20%20%20%20)%20from%20None%0A%20%20%20%20return%20(repo_file%2C)%0A%0A%0A%40app.function%0Adef%20iep_decomp(time%2C%20force%2C%20cop%2C%20demean_force%3DTrue)%3A%0A%20%20%20%20%22%22%22Return%20the%20valid%20sample%20domain%2C%20rambling%2Ftrembling%2C%20and%20zero-force%20knots.%0A%0A%20%20%20%20A%20cubic%20interpolant%20requires%20four%20distinct%20knots.%20End%20samples%20outside%20the%0A%20%20%20%20knot%20range%20are%20excluded%20rather%20than%20extrapolated.%20A%20run%20of%20exact%20zeros%0A%20%20%20%20contributes%20its%20midpoint.%20Removing%20the%20force%20mean%20follows%20the%20original%0A%20%20%20%20tutorial%20convention%3B%20it%20is%20an%20explicit%20offset%20correction%20assumption.%0A%20%20%20%20%22%22%22%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20scipy.interpolate%20import%20CubicSpline%0A%20%20%20%20time%2C%20force%2C%20cop%20%3D%20%5Bnp.asarray(v%2C%20dtype%3Dfloat)%20for%20v%20in%20(time%2C%20force%2C%20cop)%5D%0A%20%20%20%20if%20any((v.ndim%20!%3D%201%20for%20v%20in%20(time%2C%20force%2C%20cop)))%20or%20not%20len(time)%20%3D%3D%20len(force)%20%3D%3D%20len(cop)%3A%0A%20%20%20%20%20%20%20%20raise%20ValueError('time%2C%20force%2C%20and%20cop%20must%20be%20equal-length%20one-dimensional%20arrays')%0A%20%20%20%20if%20len(time)%20%3C%204%20or%20not%20all((np.isfinite(v).all()%20for%20v%20in%20(time%2C%20force%2C%20cop)))%20or%20np.any(np.diff(time)%20%3C%3D%200)%3A%0A%20%20%20%20%20%20%20%20raise%20ValueError('Use%20finite%20samples%20with%20strictly%20increasing%20time')%0A%20%20%20%20centered%20%3D%20force%20-%20force.mean()%20if%20demean_force%20else%20force.copy()%0A%20%20%20%20if%20not%20np.any(centered)%3A%0A%20%20%20%20%20%20%20%20raise%20ValueError('A%20constant%20zero%20force%20does%20not%20identify%20discrete%20equilibrium%20points')%0A%20%20%20%20before%20%3D%20np.flatnonzero(centered%5B%3A-1%5D%20*%20centered%5B1%3A%5D%20%3C%200)%0A%20%20%20%20fraction%20%3D%20-centered%5Bbefore%5D%20%2F%20(centered%5Bbefore%20%2B%201%5D%20-%20centered%5Bbefore%5D)%0A%20%20%20%20crossings%20%3D%20time%5Bbefore%5D%20%2B%20fraction%20*%20(time%5Bbefore%20%2B%201%5D%20-%20time%5Bbefore%5D)%0A%20%20%20%20zero_edges%20%3D%20np.diff(np.r_%5BFalse%2C%20centered%20%3D%3D%200%2C%20False%5D.astype(int))%0A%20%20%20%20starts%20%3D%20np.flatnonzero(zero_edges%20%3D%3D%201)%0A%20%20%20%20stops%20%3D%20np.flatnonzero(zero_edges%20%3D%3D%20-1)%20-%201%0A%20%20%20%20knots%20%3D%20np.unique(np.r_%5Bcrossings%2C%20(time%5Bstarts%5D%20%2B%20time%5Bstops%5D)%20%2F%202%5D)%0A%20%20%20%20if%20len(knots)%20%3C%204%3A%0A%20%20%20%20%20%20%20%20raise%20ValueError('Cubic%20rambling%20decomposition%20requires%20at%20least%20four%20zero-force%20knots')%0A%20%20%20%20knot_cop%20%3D%20np.interp(knots%2C%20time%2C%20cop)%0A%20%20%20%20selected%20%3D%20(time%20%3E%3D%20knots%5B0%5D)%20%26%20(time%20%3C%3D%20knots%5B-1%5D)%0A%20%20%20%20rambling%20%3D%20CubicSpline(knots%2C%20knot_cop%2C%20extrapolate%3DFalse)(time%5Bselected%5D)%0A%20%20%20%20return%20%7B'time'%3A%20time%5Bselected%5D%2C%20'force'%3A%20centered%5Bselected%5D%2C%20'cop'%3A%20cop%5Bselected%5D%2C%20'rambling'%3A%20rambling%2C%20'trembling'%3A%20cop%5Bselected%5D%20-%20rambling%2C%20'knot_time'%3A%20knots%2C%20'knot_cop'%3A%20knot_cop%7D%0A%0A%0A%40app.function%0Adef%20cogve(COP%2C%20freq%2C%20mass%2C%20height%2C%20show%3DFalse%2C%20ax%3DNone)%3A%0A%20%20%20%20%22%22%22COGv%20estimation%20using%20COP%20data%20based%20on%20the%20inverted%20pendulum%20model.%0A%0A%20%20%20%20This%20function%20estimates%20the%20center%20of%20gravity%20vertical%20projection%20(COGv)%0A%20%20%20%20displacement%20from%20the%20center%20of%20pressure%20(COP)%20displacement%20at%20the%0A%20%20%20%20anterior-posterior%20direction%20during%20quiet%20upright%20standing.%20COP%20and%20COGv%0A%20%20%20%20displacements%20are%20measurements%20useful%20to%20quantify%20the%20postural%20sway%20of%20a%0A%20%20%20%20person%20while%20standing.%0A%0A%20%20%20%20The%20COGv%20displacement%20is%20estimated%20by%20low-pass%20filtering%20the%20COP%0A%20%20%20%20displacement%20in%20the%20frequency%20domain%20according%20to%20the%20person's%20moment%0A%20%20%20%20of%20rotational%20inertia%20as%20a%20single%20inverted%20pendulum%20%5B1%5D_.%0A%0A%20%20%20%20Parameters%0A%20%20%20%20----------%0A%20%20%20%20COP%20%20%20%20%3A%201D%20array_like%0A%20%20%20%20%20%20%20%20%20%20%20%20%20center%20of%20pressure%20data%20%5Bcm%5D%0A%20%20%20%20freq%20%20%20%3A%20float%0A%20%20%20%20%20%20%20%20%20%20%20%20%20sampling%20frequency%20of%20the%20COP%20data%0A%20%20%20%20mass%20%20%20%3A%20float%0A%20%20%20%20%20%20%20%20%20%20%20%20%20body%20mass%20of%20the%20subject%20%5Bkg%5D%0A%20%20%20%20height%20%3A%20float%0A%20%20%20%20%20%20%20%20%20%20%20%20%20height%20of%20the%20subject%20%5Bcm%5D%0A%20%20%20%20show%20%20%20%3A%20bool%2C%20optional%20(default%20%3D%20False)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20True%20(1)%20plots%20data%20and%20results%20in%20a%20matplotlib%20figure%0A%20%20%20%20%20%20%20%20%20%20%20%20%20False%20(0)%20to%20not%20plot%0A%20%20%20%20ax%20%20%20%20%20%3A%20matplotlib.axes.Axes%20instance%2C%20optional%20(default%20%3D%20None)%0A%0A%20%20%20%20Returns%0A%20%20%20%20-------%0A%20%20%20%20COGv%20%20%20%3A%201D%20array%0A%20%20%20%20%20%20%20%20%20%20%20%20%20center%20of%20gravity%20vertical%20projection%20data%20%5Bcm%5D%0A%0A%20%20%20%20References%0A%20%20%20%20----------%0A%20%20%20%20..%20%5B1%5D%20https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fip_model.py%0A%0A%20%20%20%20Examples%0A%20%20%20%20--------%0A%20%20%20%20%3E%3E%3E%20from%20cogve%20import%20cogve%0A%20%20%20%20%3E%3E%3E%20y%20%3D%20np.cumsum(np.random.randn(3000))%2F50%0A%20%20%20%20%3E%3E%3E%20cogv%20%3D%20cogve(y%2C%20freq%3D100%2C%20mass%3D70%2C%20height%3D170%2C%20show%3DTrue)%0A%20%20%20%20%22%22%22%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20scipy.signal._arraytools%20import%20odd_ext%0A%20%20%20%20import%20scipy.fftpack%0A%20%20%20%20COP%20%3D%20np.asarray(COP)%0A%20%20%20%20height%20%3D%20height%20%2F%20100%0A%20%20%20%20g%20%3D%209.8%0A%20%20%20%20hcog%20%3D%200.56%20*%20height%20-%200.039%20*%20height%0A%20%20%20%20I%20%3D%20mass%20*%200.0533%20*%20height%20**%202%20%2B%20mass%20*%20hcog%20**%202%0A%20%20%20%20w02%20%3D%20mass%20*%20g%20*%20hcog%20%2F%20I%0A%20%20%20%20COP%20%3D%20odd_ext(COP%2C%20n%3Dfreq)%0A%20%20%20%20COPm%20%3D%20np.mean(COP)%0A%20%20%20%20COP%20%3D%20COP%20-%20COPm%0A%20%20%20%20N%20%3D%20COP.size%0A%20%20%20%20COPfft%20%3D%20scipy.fftpack.fft(COP%2C%20n%3DN)%20%2F%20N%0A%20%20%20%20w%20%3D%202%20*%20np.pi%20*%20scipy.fftpack.fftfreq(n%3DN%2C%20d%3D1%20%2F%20freq)%0A%20%20%20%20TF%20%3D%20w02%20%2F%20(w02%20%2B%20w%20**%202)%0A%20%20%20%20COGv%20%3D%20np.real(scipy.fftpack.ifft(TF%20*%20COPfft)%20*%20N)%0A%20%20%20%20COGv%20%3D%20COGv%5B0%3AN%5D%0A%20%20%20%20COP%2C%20COGv%20%3D%20(COP%20%2B%20COPm%2C%20COGv%20%2B%20COPm)%0A%20%20%20%20COP%2C%20COGv%20%3D%20(COP%5Bfreq%3A-freq%5D%2C%20COGv%5Bfreq%3A-freq%5D)%0A%20%20%20%20if%20show%3A%0A%20%20%20%20%20%20%20%20plot_cogve(COP%2C%20COGv%2C%20freq%2C%20ax)%0A%20%20%20%20return%20COGv%0A%0A%0A%40app.function%0Adef%20plot_cogve(COP%2C%20COGv%2C%20freq%2C%20ax)%3A%0A%20%20%20%20%22%22%22Plot%20results%20of%20the%20cogve%20function%2C%20see%20its%20help.%22%22%22%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20except%20ImportError%3A%0A%20%20%20%20%20%20%20%20print('matplotlib%20is%20not%20available.')%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20time%20%3D%20np.linspace(0%2C%20COP.size%20%2F%20freq%2C%20COP.size)%0A%20%20%20%20%20%20%20%20if%20ax%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_%2C%20ax%20%3D%20plt.subplots(1%2C%201)%0A%20%20%20%20%20%20%20%20ax.plot(time%2C%20COP%2C%20color%3D%5B0%2C%200%2C%201%2C%200.8%5D%2C%20lw%3D2%2C%20label%3D'COP')%0A%20%20%20%20%20%20%20%20ax.plot(time%2C%20COGv%2C%20color%3D%5B1%2C%200%2C%200%2C%200.8%5D%2C%20lw%3D2%2C%20label%3D'COGv')%0A%20%20%20%20%20%20%20%20ax.legend(fontsize%3D14%2C%20loc%3D'best'%2C%20framealpha%3D0.5%2C%20numpoints%3D1)%0A%20%20%20%20%20%20%20%20ax.set_xlabel('Time%20%5Bs%5D'%2C%20fontsize%3D14)%0A%20%20%20%20%20%20%20%20ax.set_ylabel('Amplitude%20%5Bcm%5D'%2C%20fontsize%3D14)%0A%20%20%20%20%20%20%20%20ax.set_title('COGv%20estimation%20using%20the%20COP%20data'%2C%20fontsize%3D16)%0A%20%20%20%20%20%20%20%20ax.set_xlim(time%5B0%5D%2C%20time%5B-1%5D)%0A%20%20%20%20%20%20%20%20plt.grid()%0A%20%20%20%20%20%20%20%20plt.show()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20A%20hypothesis%20about%20balance%20control%0A%0A%20%20%20%20The%20rambling%E2%80%93trembling%20hypothesis%20describes%20a%20slowly%20migrating%20reference%20position%20and%20deviations%20around%20it.%20Gurfinkel%20and%20colleagues'%20slow%20support-surface%20tilts%2C%20and%20observations%20of%20sway%20during%20prolonged%20standing%2C%20motivated%20this%20interpretation.%20It%20is%20a%20model%20of%20control%2C%20not%20a%20direct%20measurement%20of%20two%20independently%20observed%20neural%20subsystems.%0A%0A%20%20%20%20The%20original%20illustrations%20show%20force%20vectors%2C%20prolonged%20standing%2C%20and%20the%20scale%20structure%20of%20sway%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20repo_file)%3A%0A%20%20%20%20mo.vstack(%5Bmo.image(src%3Drepo_file(%22images%2Fforcevectors.png%22)%2C%20width%3D600)%2C%20mo.md('Force-vector%20illustration%20during%20quiet%20standing.')%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20repo_file)%3A%0A%20%20%20%20mo.vstack(%5Bmo.image(src%3Drepo_file(%22images%2Fprolongedstanding.png%22)%2C%20width%3D600)%2C%20mo.md('Illustration%20of%20prolonged-standing%20sway.')%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20repo_file)%3A%0A%20%20%20%20mo.vstack(%5Bmo.image(src%3Drepo_file(%22images%2Ffractal.png%22)%2C%20width%3D600)%2C%20mo.md('Illustration%20of%20the%20scale%20structure%20of%20sway.')%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Define%20the%20decomposition%0A%0A%20%20%20%20At%20an%20instant%20when%20horizontal%20ground-reaction%20force%20is%20zero%2C%20horizontal%20centre-of-mass%20acceleration%20is%20zero%20under%20the%20assumed%20force%20balance.%20This%20does%20**not**%20require%20zero%20velocity%20or%20full%20static%20equilibrium.%20The%20COP%20positions%20at%20these%20instants%20are%20called%20instant%20equilibrium%20points%20(IEPs).%20A%20cubic%20spline%20through%20them%20estimates%20**rambling**%3B%20**trembling%20%3D%20COP%20%E2%88%92%20rambling**.%0A%0A%20%20%20%20The%20control%20interpretation%20proposes%20an%20intended%20body%20position%2C%20its%20migration%2C%20deviations%20from%20it%2C%20and%20restoring%20actions%20associated%20with%20apparent%20stiffness.%20The%20computed%20components%20alone%20do%20not%20establish%20that%20mechanism.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20repo_file)%3A%0A%20%20%20%20mo.image(src%3Drepo_file(%22images%2Frambtremb.png%22)%2C%20width%3D600)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%201.**%20At%20one%20instant%20the%20COP%20is%202.0%20cm%20and%20the%20estimated%20rambling%20is%201.4%20cm.%20What%20is%20trembling%3F%20Does%20zero%20horizontal%20force%20imply%20zero%20horizontal%20velocity%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%201%0A%0A%20%20%20%20Trembling%20is%20%242.0-1.4%3D0.6%24%20cm.%20Zero%20horizontal%20force%20implies%20zero%20horizontal%20acceleration%20under%20the%20model%2C%20not%20zero%20velocity.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Find%20zero-force%20instants%20between%20samples%0A%0A%20%20%20%20The%20earlier%20code%20chose%20the%20sample%20immediately%20before%20each%20sign%20change.%20Here%20we%20interpolate%20the%20crossing%20time%20within%20that%20sampling%20interval%20and%20interpolate%20COP%20at%20that%20time.%20Exact-zero%20runs%20contribute%20their%20midpoint.%20We%20keep%20only%20the%20domain%20between%20the%20first%20and%20last%20knot%2C%20avoiding%20extrapolation.%20Four%20distinct%20knots%20are%20required%20for%20the%20cubic%20interpolation.%0A%0A%20%20%20%20As%20in%20the%20original%20analysis%2C%20the%20force%20mean%20is%20removed%20before%20locating%20crossings.%20This%20treats%20the%20mean%20as%20an%20offset%3B%20assess%20that%20assumption%20for%20a%20recording%20rather%20than%20silently%20interpreting%20the%20centred%20force%20as%20the%20raw%20measurement.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%202.**%20At%20times%200%20and%200.01%20s%2C%20force%20changes%20from%20%E2%88%921%20N%20to%20%2B3%20N.%20With%20linear%20interpolation%20and%20no%20offset%20correction%2C%20when%20is%20the%20zero%20crossing%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%202%0A%0A%20%20%20%20The%20zero%20is%20one%20quarter%20of%20the%20way%20through%20the%20interval%3A%20%240.0025%24%20s.%20Choosing%20the%20earlier%20sample%20would%20shift%20the%20knot%20by%202.5%20ms.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Load%20the%20public%20trial%20information%0A%0A%20%20%20%20The%20Santos%20and%20Duarte%20dataset%20includes%20repeated%20trials%20under%20different%20visual%20and%20support-surface%20conditions.%20Select%20trials%20deliberately%3A%20each%20selection%20downloads%20a%20recording.%20The%20default%20is%20the%20single%20trial%20used%20in%20the%20original%20walkthrough%2C%20BDS00038.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20pd%2C%20repo_file)%3A%0A%20%20%20%20dataset_base%20%3D%20%22https%3A%2F%2Fraw.githubusercontent.com%2Fdemotu%2Fdatasets%2Fmaster%2F%22%0A%20%20%20%20metadata%20%3D%20pd.read_csv(repo_file(%22BDS%2FBDSinfo.txt%22%2C%20base_url%3Ddataset_base)%2C%20sep%3D%22%5Ct%22)%0A%20%20%20%20trial_choices%20%3D%20mo.ui.multiselect(options%3Dmetadata%5B%22Trial%22%5D.tolist()%2C%20value%3D%5B%22BDS00038%22%5D%2C%20label%3D%22Trials%20to%20analyse%22)%0A%20%20%20%20trial_choices%0A%20%20%20%20return%20dataset_base%2C%20metadata%2C%20trial_choices%0A%0A%0A%40app.cell%0Adef%20_(dataset_base%2C%20metadata%2C%20mo%2C%20np%2C%20pd%2C%20repo_file%2C%20trial_choices)%3A%0A%20%20%20%20selected_results%20%3D%20%7B%7D%0A%20%20%20%20for%20_trial%20in%20trial_choices.value%3A%0A%20%20%20%20%20%20%20%20_table%20%3D%20pd.read_csv(repo_file(f%22BDS%2Fdata%2F%7B_trial%7D.txt%22%2C%20base_url%3Ddataset_base)%2C%20sep%3D%22%5Ct%22)%0A%20%20%20%20%20%20%20%20_table.columns%20%3D%20%5B%22Time%22%2C%20%22Fx%22%2C%20%22Fy%22%2C%20%22Fz%22%2C%20%22Mx%22%2C%20%22My%22%2C%20%22Mz%22%2C%20%22COPx%22%2C%20%22COPy%22%5D%0A%20%20%20%20%20%20%20%20_components%20%3D%20iep_decomp(_table.Time%2C%20_table.Fx%2C%20_table.COPx)%0A%20%20%20%20%20%20%20%20_person%20%3D%20metadata.loc%5Bmetadata.Trial%20%3D%3D%20_trial%5D.iloc%5B0%5D%0A%20%20%20%20%20%20%20%20_frequency%20%3D%20int(round(1%20%2F%20np.mean(np.diff(_table.Time))))%0A%20%20%20%20%20%20%20%20_cog%20%3D%20cogve(_components%5B%22cop%22%5D%2C%20freq%3D_frequency%2C%20mass%3Dfloat(_person.Weight)%2C%20height%3Dfloat(_person.Height)%2C%20show%3DFalse)%0A%20%20%20%20%20%20%20%20selected_results%5B_trial%5D%20%3D%20%7B%22recording%22%3A%20_table%2C%20%22components%22%3A%20_components%2C%20%22person%22%3A%20_person%2C%20%22cog%22%3A%20_cog%7D%0A%20%20%20%20mo.md(f%22Analysed%20**%7Blen(selected_results)%7D**%20selected%20trial(s).%22)%0A%20%20%20%20return%20(selected_results%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Inspect%20the%20recording%20and%20its%20components%0A%0A%20%20%20%20The%20first%20selected%20trial%20is%20shown%20below.%20Compare%20horizontal%20forces%2C%20vertical%20force%2C%20the%20two%20COP%20coordinates%2C%20and%20the%20force-crossing%20knots%20before%20interpreting%20the%20decomposition.%20The%20COP%20units%20in%20this%20dataset%20are%20centimetres.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20plt%2C%20selected_results)%3A%0A%20%20%20%20if%20selected_results%3A%0A%20%20%20%20%20%20%20%20_item%20%3D%20next(iter(selected_results.values()))%0A%20%20%20%20%20%20%20%20_data%20%3D%20_item%5B%22recording%22%5D%0A%20%20%20%20%20%20%20%20_fig%2C%20_axs%20%3D%20plt.subplots(3%2C%201%2C%20figsize%3D(10%2C%207)%2C%20sharex%3DTrue)%0A%20%20%20%20%20%20%20%20_data.plot(x%3D%22Time%22%2C%20y%3D%5B%22Fx%22%2C%20%22Fy%22%5D%2C%20ax%3D_axs%5B0%5D)%0A%20%20%20%20%20%20%20%20_data.plot(x%3D%22Time%22%2C%20y%3D%22Fz%22%2C%20ax%3D_axs%5B1%5D)%0A%20%20%20%20%20%20%20%20_data.plot(x%3D%22Time%22%2C%20y%3D%5B%22COPx%22%2C%20%22COPy%22%5D%2C%20ax%3D_axs%5B2%5D)%0A%20%20%20%20%20%20%20%20_axs%5B0%5D.set_ylabel(%22Force%20%5BN%5D%22)%0A%20%20%20%20%20%20%20%20_axs%5B1%5D.set_ylabel(%22Force%20%5BN%5D%22)%0A%20%20%20%20%20%20%20%20_axs%5B2%5D.set_ylabel(%22COP%20%5Bcm%5D%22)%0A%20%20%20%20%20%20%20%20_display%20%3D%20_fig%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22Select%20at%20least%20one%20trial%20to%20display%20its%20recording.%22)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20np%2C%20plt%2C%20selected_results)%3A%0A%20%20%20%20if%20selected_results%3A%0A%20%20%20%20%20%20%20%20_item%20%3D%20next(iter(selected_results.values()))%0A%20%20%20%20%20%20%20%20_c%20%3D%20_item%5B%22components%22%5D%0A%20%20%20%20%20%20%20%20_fig%2C%20_axs%20%3D%20plt.subplots(4%2C%201%2C%20figsize%3D(10%2C%208)%2C%20sharex%3DTrue)%0A%20%20%20%20%20%20%20%20for%20_ax%2C%20_key%20in%20zip(_axs%2C%20%5B%22force%22%2C%20%22cop%22%2C%20%22rambling%22%2C%20%22trembling%22%5D)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_ax.plot(_c%5B%22time%22%5D%2C%20_c%5B_key%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20_ax.set_ylabel(_key%20%2B%20(%22%20%5BN%5D%22%20if%20_key%20%3D%3D%20%22force%22%20else%20%22%20%5Bcm%5D%22))%0A%20%20%20%20%20%20%20%20_axs%5B0%5D.plot(_c%5B%22knot_time%22%5D%2C%20np.zeros(len(_c%5B%22knot_time%22%5D))%2C%20%22.%22)%0A%20%20%20%20%20%20%20%20_axs%5B2%5D.plot(_c%5B%22knot_time%22%5D%2C%20_c%5B%22knot_cop%22%5D%2C%20%22.%22)%0A%20%20%20%20%20%20%20%20_axs%5B-1%5D.set_xlabel(%22Time%20%5Bs%5D%22)%0A%20%20%20%20%20%20%20%20_display%20%3D%20_fig%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22Select%20a%20trial%20to%20display%20the%20decomposition.%22)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%203.**%20Why%20should%20the%20spline%20not%20be%20extended%20to%20the%20recording%20endpoints%20when%20no%20IEP%20knots%20bracket%20those%20endpoints%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%203%0A%0A%20%20%20%20Beyond%20the%20knot%20range%20the%20curve%20is%20an%20extrapolation%20controlled%20by%20spline%20boundary%20behavior%2C%20not%20by%20surrounding%20IEPs.%20Restricting%20the%20analysis%20to%20the%20knot%20range%20avoids%20treating%20that%20extension%20as%20measured%20evidence.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Compare%20COP%20and%20estimated%20COG%20projection%0A%0A%20%20%20%20The%20inverted-pendulum%20model%20offers%20a%20different%20decomposition%3A%20estimated%20COG%20projection%20and%20COP%20minus%20that%20estimate.%20It%20relies%20on%20small-sway%2C%20single-link%20assumptions%20and%20anthropometric%20parameters.%20We%20use%20each%20selected%20subject's%20recorded%20height%20and%20mass%2C%20rather%20than%20the%20previous%20fixed%20height%20and%20approximate%20weight-to-mass%20conversion.%20Each%20trial%20uses%20its%20own%20valid%20time%20interval%3B%20indices%20from%20another%20trial%20are%20never%20reused.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20plt%2C%20selected_results)%3A%0A%20%20%20%20if%20selected_results%3A%0A%20%20%20%20%20%20%20%20_item%20%3D%20next(iter(selected_results.values()))%0A%20%20%20%20%20%20%20%20_c%20%3D%20_item%5B%22components%22%5D%0A%20%20%20%20%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots(figsize%3D(10%2C%203))%0A%20%20%20%20%20%20%20%20_ax.plot(_c%5B%22time%22%5D%2C%20_c%5B%22cop%22%5D%2C%20label%3D%22COP%22)%0A%20%20%20%20%20%20%20%20_ax.plot(_c%5B%22time%22%5D%2C%20_item%5B%22cog%22%5D%2C%20label%3D%22estimated%20COG%20projection%22)%0A%20%20%20%20%20%20%20%20_ax.set(xlabel%3D%22Time%20%5Bs%5D%22%2C%20ylabel%3D%22Position%20%5Bcm%5D%22)%0A%20%20%20%20%20%20%20%20_ax.legend()%0A%20%20%20%20%20%20%20%20_display%20%3D%20_fig%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22Select%20a%20trial%20to%20compare%20COP%20and%20estimated%20COG%20projection.%22)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Summarize%20repeated%20trials%20without%20counting%20them%20as%20independent%20subjects%0A%0A%20%20%20%20We%20first%20calculate%20within-trial%20sample%20SDs%2C%20then%20take%20the%20median%20across%20repeated%20trials%20for%20each%20subject%20and%20condition.%20Group%20descriptions%20use%20those%20subject-level%20summaries.%20The%20default%20single%20trial%20cannot%20support%20a%20population%20comparison.%20Excluding%20participants%20merely%20to%20balance%20group%20counts%20can%20bias%20an%20analysis%3B%20define%20exclusions%20from%20a%20justified%20study%20question%20before%20inspecting%20results.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20np%2C%20pd%2C%20selected_results)%3A%0A%20%20%20%20_rows%20%3D%20%5B%5D%0A%20%20%20%20for%20_trial%2C%20_item%20in%20selected_results.items()%3A%0A%20%20%20%20%20%20%20%20_c%20%3D%20_item%5B%22components%22%5D%0A%20%20%20%20%20%20%20%20_p%20%3D%20_item%5B%22person%22%5D%0A%20%20%20%20%20%20%20%20_rows.append(%7B%22Trial%22%3A%20_trial%2C%20%22Subject%22%3A%20_p.Subject%2C%20%22Vision%22%3A%20_p.Vision%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Surface%22%3A%20_p.Surface%2C%20%22AgeGroup%22%3A%20_p.AgeGroup%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22COP_sd%22%3A%20np.std(_c%5B%22cop%22%5D%2C%20ddof%3D1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Rambling_sd%22%3A%20np.std(_c%5B%22rambling%22%5D%2C%20ddof%3D1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Trembling_sd%22%3A%20np.std(_c%5B%22trembling%22%5D%2C%20ddof%3D1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22COGv_sd%22%3A%20np.std(_item%5B%22cog%22%5D%2C%20ddof%3D1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22COP_COGv_sd%22%3A%20np.std(_c%5B%22cop%22%5D-_item%5B%22cog%22%5D%2C%20ddof%3D1)%7D)%0A%20%20%20%20summary%20%3D%20pd.DataFrame(_rows)%0A%20%20%20%20if%20len(summary)%3A%0A%20%20%20%20%20%20%20%20subject_summary%20%3D%20summary.groupby(%5B%22Subject%22%2C%20%22Vision%22%2C%20%22Surface%22%2C%20%22AgeGroup%22%5D%2C%20as_index%3DFalse).median(numeric_only%3DTrue)%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.vstack(%5Bsummary%2C%20subject_summary%2C%20mo.download(summary.to_csv(index%3DFalse).encode()%2C%20filename%3D%22balance_summary.csv%22%2C%20label%3D%22Download%20selected-trial%20summary%22)%5D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20subject_summary%20%3D%20pd.DataFrame()%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22Select%20trials%20to%20compute%20subject%20summaries.%22)%0A%20%20%20%20_display%0A%20%20%20%20return%20(subject_summary%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20subject_summary)%3A%0A%20%20%20%20if%20len(subject_summary)%3A%0A%20%20%20%20%20%20%20%20_description%20%3D%20subject_summary.groupby(%5B%22AgeGroup%22%2C%20%22Vision%22%2C%20%22Surface%22%5D)%5B%5B%22COP_sd%22%2C%20%22Rambling_sd%22%2C%20%22Trembling_sd%22%2C%20%22COGv_sd%22%2C%20%22COP_COGv_sd%22%5D%5D.agg(%5B%22count%22%2C%20%22mean%22%2C%20%22std%22%5D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_description%20%3D%20mo.md(%22No%20selected%20subject%20summaries.%22)%0A%20%20%20%20_description%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Compare%20selected%20subject%20summaries%0A%0A%20%20%20%20The%20original%20two%20sets%20of%20group-comparison%20plots%20are%20retained%20as%20an%20optional%20display.%20Each%20dot%20represents%20one%20subject%2Fcondition%20summary%2C%20using%20the%20median%20of%20that%20subject's%20selected%20repeated%20trials.%20Panels%20separate%20support%20surfaces%2C%20colours%20identify%20age%20groups%2C%20and%20counts%20state%20how%20many%20subjects%20contributed.%20These%20are%20descriptive%20comparisons%3B%20selecting%20one%20trial%20does%20not%20establish%20a%20population%20effect.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20comparison_plots%20%3D%20mo.ui.checkbox(value%3DFalse%2C%20label%3D%22Show%20selected-subject%20comparison%20plots%22)%0A%20%20%20%20comparison_plots%0A%20%20%20%20return%20(comparison_plots%2C)%0A%0A%0A%40app.cell%0Adef%20_(comparison_plots%2C%20mo%2C%20np%2C%20plt%2C%20subject_summary)%3A%0A%20%20%20%20if%20comparison_plots.value%20and%20len(subject_summary)%3A%0A%20%20%20%20%20%20%20%20_surfaces%20%3D%20list(subject_summary%5B%22Surface%22%5D.unique())%0A%20%20%20%20%20%20%20%20_visions%20%3D%20list(subject_summary%5B%22Vision%22%5D.unique())%0A%20%20%20%20%20%20%20%20_ages%20%3D%20list(subject_summary%5B%22AgeGroup%22%5D.unique())%0A%20%20%20%20%20%20%20%20_figures%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20for%20_metrics%20in%20%5B(%22COP_sd%22%2C%20%22Rambling_sd%22%2C%20%22Trembling_sd%22)%2C%20(%22COP_sd%22%2C%20%22COGv_sd%22%2C%20%22COP_COGv_sd%22)%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_fig%2C%20_axs%20%3D%20plt.subplots(3%2C%20len(_surfaces)%2C%20squeeze%3DFalse%2C%20sharex%3DTrue%2C%20sharey%3D%22row%22%2C%20figsize%3D(5*len(_surfaces)%2C%207))%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20_column%2C%20_surface%20in%20enumerate(_surfaces)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_surface_data%20%3D%20subject_summary.loc%5Bsubject_summary.Surface%20%3D%3D%20_surface%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_row%2C%20_metric%20in%20enumerate(_metrics)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax%20%3D%20_axs%5B_row%2C%20_column%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_colour%2C%20_age%20in%20enumerate(_ages)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_subset%20%3D%20_surface_data.loc%5B_surface_data.AgeGroup%20%3D%3D%20_age%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_x%20%3D%20np.array(%5B_visions.index(v)%20for%20v%20in%20_subset.Vision%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_offset%20%3D%20(_colour%20-%20(len(_ages)-1)%2F2)*0.12%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax.scatter(_x%2B_offset%2C%20_subset%5B_metric%5D%2C%20label%3Dstr(_age)%2C%20color%3Df%22C%7B_colour%7D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax.set_ylabel(_metric.replace(%22_sd%22%2C%20%22%20SD%22)%2B%22%20%5Bcm%5D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax.set_xticks(range(len(_visions))%2C%20_visions)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax.set_title(f%22%7B_surface%7D%3A%20n%3D%7B_surface_data.Subject.nunique()%7D%20subject(s)%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20_row%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20_ax.legend(title%3D%22Age%20group%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20_fig.tight_layout()%0A%20%20%20%20%20%20%20%20%20%20%20%20_figures.append(_fig)%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.vstack(_figures)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_display%20%3D%20mo.md(%22Enable%20the%20comparison%20display%20after%20choosing%20trials.%20The%20default%20single%20trial%20is%20a%20demonstration%2C%20not%20a%20group%20study.%22)%0A%20%20%20%20_display%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%204.**%20A%20subject%20contributes%20three%20repeated%20trials.%20How%20many%20independent%20people%20are%20represented%3F%20Why%20summarize%20within%20subject%20first%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%204%0A%0A%20%20%20%20There%20is%20one%20person.%20Summarizing%20the%20repeats%20avoids%20treating%20repeated%20measurements%20from%20that%20person%20as%20three%20independent%20subjects%3B%20between-subject%20inference%20still%20requires%20an%20appropriate%20design.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Component%20amplitudes%20do%20not%20add%0A%0A%20%20%20%20The%20original%20caution%20about%20RMS%20is%20essential.%20Although%20COP%20%3D%20rambling%20%2B%20trembling%20pointwise%2C%20RMS%20amplitudes%20do%20not%20generally%20add.%20Mean-square%20values%20contain%20a%20cross%20term%3B%20variances%20contain%20twice%20the%20covariance.%20In%20the%20synthetic%20example%20below%2C%20two%20complete-cycle%20sinusoids%20are%20orthogonal%2C%20so%20their%20mean%20squares%20add%2C%20but%20their%20RMS%20values%20do%20not.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20_t%20%3D%20np.arange(100)%20%2F%20100%0A%20%20%20%20_r%20%3D%20np.sin(2*np.pi*_t)%0A%20%20%20%20_q%20%3D%200.1*np.sin(20*np.pi*_t)%0A%20%20%20%20_c%20%3D%20_r%20%2B%20_q%0A%20%20%20%20rms_example%20%3D%20%7B%22COP%22%3A%20np.sqrt(np.mean(_c**2))%2C%20%22rambling%22%3A%20np.sqrt(np.mean(_r**2))%2C%20%22trembling%22%3A%20np.sqrt(np.mean(_q**2))%7D%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots(figsize%3D(9%2C%203))%0A%20%20%20%20for%20_values%2C%20_name%20in%20%5B(_c%2C%20%22COP%22)%2C%20(_r%2C%20%22rambling%22)%2C%20(_q%2C%20%22trembling%22)%5D%3A%0A%20%20%20%20%20%20%20%20_ax.plot(_t%2C%20_values%2C%20label%3Df%22%7B_name%7D%3A%20RMS%3D%7Brms_example%5B_name%5D%3A.3f%7D%22)%0A%20%20%20%20_ax.set(xlabel%3D%22Time%20%5Bs%5D%22%2C%20ylabel%3D%22Synthetic%20amplitude%20%5Ba.u.%5D%22)%0A%20%20%20%20_ax.legend()%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%205.**%20If%20two%20uncorrelated%2C%20zero-mean%20components%20have%20variances%204%20and%201%2C%20what%20is%20the%20variance%20and%20SD%20of%20their%20sum%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%205%0A%0A%20%20%20%20The%20variance%20is%20%244%2B1%3D5%24%2C%20while%20the%20SD%20is%20%24%5Csqrt5%5Capprox2.236%24.%20Adding%20the%20component%20SDs%20would%20give%203%20and%20is%20incorrect.%20If%20covariance%20is%20nonzero%2C%20include%20twice%20that%20covariance.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Checkpoint%20questions%0A%0A%20%20%20%201.%20Is%20rambling%20a%20direct%20recording%20of%20a%20neural%20reference%20signal%3F%0A%0A%20%20%20%202.%20Does%20zero%20horizontal%20force%20mean%20the%20body%20is%20motionless%3F%0A%0A%20%20%20%203.%20Does%20decomposition%20imply%20independent%20components%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%0A%20%20%20%201.%20No%3B%20it%20is%20a%20model-derived%20estimate.%0A%20%20%20%202.%20No.%0A%20%20%20%203.%20No%3B%20correlation%20must%20be%20assessed.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Problems%0A%0A%20%20%20%20Try%20these%20independently%3B%20open%20a%20panel%20only%20to%20check%20your%20final%20answer.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Problem%201.**%20COP%20is%20%E2%88%921.2%20cm%20and%20rambling%20is%20%E2%88%920.8%20cm.%20Find%20trembling.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Answer%20to%20Problem%201%0A%0A%20%20%20%20%E2%88%920.4%20cm.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Problem%202.**%20Two%20zero-mean%20orthogonal%20sinusoids%20have%20amplitudes%201%20and%200.1.%20Give%20the%20RMS%20of%20their%20sum.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Answer%20to%20Problem%202%0A%0A%20%20%20%20%24%5Csqrt%7B0.505%7D%5Capprox0.71063%24.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Problem%203.**%20A%20recording%20has%20only%20three%20distinct%20zero-force%20knots.%20Does%20the%20supplied%20cubic%20decomposition%20run%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Answer%20to%20Problem%203%0A%0A%20%20%20%20No%3B%20it%20raises%20a%20ValueError%20requiring%20at%20least%20four%20knots.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Go%20deeper%0A%0A%20%20%20%20Compare%20preprocessing%2C%20centring%2C%20crossing%20conventions%2C%20and%20boundary%20trimming%20before%20comparing%20studies.%20The%20%5Binverted-pendulum%20guide%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fip_model.py)%20explains%20the%20COP%E2%80%93COG%20model.%0A%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20%5BMIT%20Signals%20and%20Systems%20lectures%5D(https%3A%2F%2Focw.mit.edu%2Fcourses%2Fres-6-007-signals-and-systems-spring-2011%2Fvideo_galleries%2Fvideo-lectures%2F)%20give%20the%20interpolation%20and%20signal-decomposition%20background.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20References%0A%0A%20%20%20%20-%20Gurfinkel%20et%20al.%20(1995)%2C%20Kinesthetic%20reference%20for%20human%20orthograde%20posture.%20Neuroscience%2068%2C%20229%E2%80%93243.%0A%0A%20%20%20%20-%20Santos%20and%20Duarte%20(2016)%2C%20%5BA%20public%20data%20set%20of%20human%20balance%20evaluations%5D(https%3A%2F%2Fdoi.org%2F10.7717%2Fpeerj.2648).%0A%0A%20%20%20%20-%20Zatsiorsky%20and%20Duarte%20(1999)%2C%20%5BInstant%20equilibrium%20point%20and%20its%20migration%20in%20standing%20tasks%5D(https%3A%2F%2Fdoi.org%2F10.1123%2Fmcj.3.1.28).%0A%0A%20%20%20%20-%20Zatsiorsky%20and%20Duarte%20(2000)%2C%20%5BRambling%20and%20trembling%20in%20quiet%20standing%5D(https%3A%2F%2Fdoi.org%2F10.1123%2Fmcj.4.2.185).%0A%0A%20%20%20%20-%20%5BPublic%20balance%20dataset%20and%20documentation%5D(https%3A%2F%2Fgithub.com%2Fdemotu%2Fdatasets%2Ftree%2Fmaster%2FBDS).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
f8b09b03de8f3c999ad9b5f34f85af5c