%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%22psd2%3E%3D0.0.5%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()%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%20Measurements%20in%20stabilography%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%20We%20will%20inspect%20a%20public%20force-platform%20recording%2C%20remove%20its%20mean%2C%20and%20compute%20variability%2C%20path%20length%2C%20speed%2C%20area%20and%20spectral%20measures.%20Distinguish%20COP%20from%20body%20COM%2C%20and%20keep%20duration%2C%20sampling%20and%20filtering%20consistent%20before%20comparing%20trials.%0A%0A%20%20%20%20Try%20the%20distributed%20**Exercises**%20before%20opening%20their%20collapsed%20worked%20solutions.%20Then%20use%20the%20**Checkpoint%20questions**%20and%20attempt%20the%20**Problems**%20independently%3B%20their%20panels%20contain%20final%20answers%20only.%20Predict%20the%20effect%20of%20a%20parameter%20change%20before%20running%20it%2C%20and%20check%20units%20and%20limiting%20cases.%0A%0A%20%20%20%20**Opening%20challenge.**%20Two%20COP%20recordings%20have%20the%20same%20standard%20deviation.%20Can%20one%20travel%20a%20much%20longer%20total%20path%2C%20and%20would%20that%20alone%20prove%20worse%20balance%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%23%23%20Python%20setup%0A%0A%20%20%20%20The%20dependency%20declaration%20at%20the%20top%20of%20this%20file%20lists%20the%20packages%20used%20by%20this%20guide.%20Marimo%20runs%20cells%20in%20dependency%20order.%20Run%20the%20notebook%20in%20an%20editor%20to%20use%20its%20displays%20and%20controls%3B%20the%20computational%20examples%20below%20explain%20their%20inputs%20before%20using%20them.%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%20Posturography%20is%20a%20general%20term%20for%20all%20techniques%20concerned%20with%20quantifying%20postural%20sway%20of%20a%20standing%20person.%0A%0A%20%20%20%20Typically%20in%20posturography%2C%20instead%20of%20measuring%20the%20actual%20sway%20of%20each%20segment%2C%20measurements%20of%20the%20whole%20body%20sway%20have%20been%20used.%20The%20displacements%20of%20center%20of%20pressure%20(COP)%20and%20of%20the%20vertical%20projection%20(on%20the%20horizontal%20plane)%20of%20the%20center%20of%20gravity%20(COGv)%20are%20the%20most%20common%20measures%20of%20body%20sway%20(however%2C%20keep%20in%20mind%20that%20the%20COP%20displacement%20is%20not%20an%20actual%20measurement%20of%20postural%20sway%20of%20the%20body%20or%20of%20any%20of%20its%20segments).%20While%20the%20COP%20displacement%20can%20be%20easily%20measured%20with%20a%20force%20plate%2C%20the%20direct%20measurement%20of%20the%20COGv%20is%20more%20complicated%20and%20typically%20subject%20to%20a%20larger%20error.%20The%20measurement%20of%20the%20COGv%20is%20computed%20by%20measuring%20the%20position%20of%20each%20body%20segment%20combined%20with%20the%20mass%20of%20each%20segment.%20More%20commonly%2C%20the%20COGv%20displacement%20is%20determined%20indirectly%20from%20the%20COP%20displacement%20and%20different%20methods%20are%20available%20for%20such%2C%20which%20produce%20similar%20results%20(Lafond%20et%20al.%202004).%20%20See%20the%20notebook%20%5BThe%20inverted%20pendulum%20model%20of%20the%20human%20standing%20posture%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fip_model.py)%20for%20a%20description%20and%20code%20of%20one%20of%20these%20methods.%0A%0A%20%20%20%20It%20is%20possible%20to%20quantify%20a%20certain%20property%20of%20a%20phenomenon%2C%20like%20the%20postural%20control%20during%20upright%20standing%2C%20without%20any%20underlying%20scientific%20theory%20on%20what%20generated%20that%20property%20and%20what%20the%20implication%20of%20that%20measurement%20for%20the%20understanding%20of%20the%20phenomenon%20is.%20Sometimes%2C%20this%20is%20the%20only%20approach%20to%20start%20with.%20However%2C%20as%20our%20knowledge%20on%20the%20phenomenon%20advances%2C%20the%20need%20for%20a%20scientific%20theory%20or%20a%20hypothesis%20to%20interpret%20the%20results%20in%20a%20more%20meaningful%20way%20becomes%20evident.%20It%20is%20relatively%20easy%20to%20perform%20many%20measurements%20of%20the%20body%20sway%20during%20upright%20standing%3B%20far%20more%20difficult%20is%20to%20interpret%20those%20measurements%20to%20understand%20what%20they%20mean.%0A%0A%20%20%20%20The%20most%20widespread%20empirical%20interpretation%20of%20typical%20measurements%20of%20posture%20sway%20is%20that%20more%20sway%20means%20more%20instability%20which%20is%20seen%20as%20an%20indication%20of%20a%20deteriorated%20postural%20control%20system.%20This%20rationale%20is%20based%20on%20many%20experiments%20on%20aging%20and%20pathological%20conditions%20that%2C%20indeed%2C%20have%20observed%20increased%20sway%20in%20those%20conditions.%20However%2C%20bear%20in%20mind%20that%20it%20might%20not%20always%20be%20the%20case.%0A%0A%20%20%20%20Selecting%20which%20measurement%20will%20be%20used%20to%20quantify%20a%20certain%20characteristic%20of%20the%20postural%20control%20depends%20on%20which%20experiment%20we%20design%20and%20which%20task%20the%20individual%20under%20evaluation%20is%20performing.%20In%20this%20sense%2C%20posturography%20has%20been%20divided%20into%20two%20experimental%20paradigms%3A%20dynamic%20and%20static%20posturography.%20In%20static%20posturography%2C%20the%20individual%20is%20typically%20trying%20to%20stay%20as%20quiet%20as%20possible%20while%20his%20or%20her%20sway%20is%20measured%2C%20and%20no%20perturbation%20is%20applied%20during%20the%20task.%20In%20dynamic%20posturography%2C%20a%20momentary%20perturbation%20is%20applied%20and%20how%20the%20subject%20responded%20to%20that%20perturbation%20is%20measured.%0A%0A%20%20%20%20Let's%20show%20some%20of%20the%20most%20common%20measures%20of%20postural%20sway%2C%20more%20typically%20employed%20in%20static%20posturography.%0A%0A%20%20%20%20The%20data%20are%20a%20trial%20of%20the%20public%20data%20set%20of%20human%20balance%20evaluations%20of%20Santos%20and%20Duarte%20(2016)%3A%20the%20center%20of%20pressure%20of%20a%2027-year-old%20woman%20standing%20still%20for%2060%20s%20with%20her%20eyes%20open%20on%20a%20rigid%20surface%20(trial%20BDS00013)%2C%20measured%20with%20a%20force%20platform%20at%20100%20Hz.%20The%20full%20data%20set%20is%20available%20at%20%5BPhysioNet%5D(https%3A%2F%2Fphysionet.org%2Fcontent%2Fhbedb%2F1.0.0%2F)%20and%20at%20%5BGitHub%5D(https%3A%2F%2Fgithub.com%2Fdemotu%2Fdatasets%2Ftree%2Fmaster%2FBDS).%20The%20COP%20in%20the%20anterior-posterior%20direction%20(ap)%20is%20positive%20to%20the%20front%2C%20and%20in%20the%20medio-lateral%20direction%20(ml)%2C%20positive%20to%20the%20right.%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%20numpy%20as%20np%0A%20%20%20%20%23%20'%25matplotlib%20inline'%20command%20supported%20automatically%20in%20marimo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%0A%20%20%20%20return%20np%2C%20plt%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20repo_file)%3A%0A%20%20%20%20import%20pandas%20as%20pd%20%20%23%20use%20Pandas%20to%20read%20data%20from%20a%20website%0A%20%20%20%20fileUrl%20%3D%20repo_file('BDS%2Fdata%2FBDS00013.txt'%2C%20base_url%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fdemotu%2Fdatasets%2Fmaster%2F%22)%0A%20%20%20%20data%20%3D%20pd.read_csv(fileUrl%2C%20sep%3D'%5Ct')%20%20%23%20Pandas%20dataframe%0A%20%20%20%20COP%20%3D%20data%5B%5B'COPx%5Bcm%5D'%2C%20'COPy%5Bcm%5D'%5D%5D.to_numpy()%20%20%23%20ap%20and%20ml%20directions%2C%20in%20cm%0A%20%20%20%20freq%20%3D%201%20%2F%20np.mean(np.diff(data%5B'Time%5Bs%5D'%5D))%20%20%23%20sampling%20frequency%2C%20Hz%0A%20%20%20%20print('COP%20shape%3A%20'%2C%20COP.shape)%0A%20%20%20%20print(f'Sampling%20frequency%3A%20%7Bfreq%3A.0f%7D%20Hz%2C%20first-to-last%20duration%3A%20%7B(COP.shape%5B0%5D%20-%201)%20%2F%20freq%3A.2f%7D%20s')%0A%20%20%20%20return%20COP%2C%20freq%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20def%20cop_plot(freq%2C%20COP%2C%20units%3D'cm')%3A%0A%20%20%20%20%20%20%20%20'''%0A%20%20%20%20%20%20%20%20Plot%20COP%20data%20from%20postural%20sway%20measurement.%0A%20%20%20%20%20%20%20%20'''%0A%20%20%20%20%20%20%20%20import%20matplotlib.gridspec%20as%20gridspec%0A%20%20%20%20%20%20%20%20t%20%3D%20np.arange(COP.shape%5B0%5D)%20%2F%20freq%0A%20%20%20%20%20%20%20%20plt.rc('axes'%2C%20labelsize%3D16%2C%20%20titlesize%3D16)%0A%20%20%20%20%20%20%20%20plt.rc('xtick'%2C%20labelsize%3D12)%0A%20%20%20%20%20%20%20%20plt.rc('ytick'%2C%20labelsize%3D12)%0A%20%20%20%20%20%20%20%20plt.figure(figsize%3D(10%2C%204))%0A%20%20%20%20%20%20%20%20gs%20%3D%20gridspec.GridSpec(1%2C%202%2C%20width_ratios%3D%5B2%2C%201%5D)%20%0A%20%20%20%20%20%20%20%20ax1%20%3D%20plt.subplot(gs%5B0%5D)%0A%20%20%20%20%20%20%20%20ax1.plot(t%2C%20COP%5B%3A%2C0%5D%2C%20lw%3D2%2C%20color%3D%5B0%2C%200%2C%201%2C%201%5D%2C%20label%3D'ap')%0A%20%20%20%20%20%20%20%20ax1.plot(t%2C%20COP%5B%3A%2C1%5D%2C%20lw%3D2%2C%20color%3D%5B1%2C%200%2C%200%2C%201%5D%2C%20label%3D'ml')%0A%20%20%20%20%20%20%20%20ax1.set_xlim(%5Bt%5B0%5D%2C%20t%5B-1%5D%5D)%0A%20%20%20%20%20%20%20%20ax1.grid()%0A%20%20%20%20%20%20%20%20ax1.locator_params(axis%3D'both'%2C%20nbins%3D5)%0A%20%20%20%20%20%20%20%20ax1.set_xlabel('Time%20%5Bs%5D')%0A%20%20%20%20%20%20%20%20ax1.set_ylabel('COP%20%5B%25s%5D'%20%25units)%0A%20%20%20%20%20%20%20%20ax1.set_title('Stabilogram')%0A%20%20%20%20%20%20%20%20ax1.legend(fontsize%3D12%2C%20loc%3D'best'%2C%20framealpha%3D.5)%0A%20%20%20%20%20%20%20%20ax2%20%3D%20plt.subplot(gs%5B1%5D)%0A%20%20%20%20%20%20%20%20ax2.plot(COP%5B%3A%2C1%5D%2C%20COP%5B%3A%2C0%5D%2C%20lw%3D2%2C%20color%3D'g')%0A%20%20%20%20%20%20%20%20ax2.set_xlabel('COP%20ml%20%5B%25s%5D'%20%25units)%0A%20%20%20%20%20%20%20%20ax2.set_ylabel('COP%20ap%20%5B%25s%5D'%20%25units)%0A%20%20%20%20%20%20%20%20ax2.set_title('Statokinesigram')%0A%20%20%20%20%20%20%20%20if%200%3A%20%20%23%20plot%20the%20axes%20with%20the%20same%20colors%20of%20the%20COP%20data%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.xaxis.label.set_color('red')%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.spines%5B'bottom'%5D.set_color('red')%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.tick_params(axis%3D'x'%2C%20colors%3D'red')%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.yaxis.label.set_color('blue')%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.spines%5B'left'%5D.set_color('blue')%0A%20%20%20%20%20%20%20%20%20%20%20%20ax2.tick_params(axis%3D'y'%2C%20colors%3D'blue')%0A%20%20%20%20%20%20%20%20ax2.grid()%0A%20%20%20%20%20%20%20%20ax2.locator_params(axis%3D'both'%2C%20nbins%3D5)%0A%20%20%20%20%20%20%20%20plt.tight_layout()%0A%20%20%20%20%20%20%20%20plt.show()%0A%0A%20%20%20%20return%20(cop_plot%2C)%0A%0A%0A%40app.cell%0Adef%20_(COP%2C%20cop_plot%2C%20freq)%3A%0A%20%20%20%20%23%20plot%20data%0A%20%20%20%20cop_plot(freq%2C%20COP)%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%20Data%20detrend%0A%0A%20%20%20%20The%20mean%20value%20of%20the%20COP%20(or%20COGv)%20displacement%20is%20dependent%20where%20the%20individual%20stood%20on%20the%20force%20plate%20or%20in%20the%20space%20and%20usually%20has%20no%20particular%20interest%20to%20the%20understanding%20of%20postural%20sway.%20So%2C%20a%20typical%20procedure%20in%20the%20analysis%20of%20postural%20sway%20is%20to%20remove%20the%20mean%20value%20of%20the%20data.%20Related%20to%20that%2C%20the%20presence%20of%20a%20trend%20(a%20slow%20fluctuation)%20in%20the%20signal%20might%20also%20affect%20some%20of%20the%20measurements.%20Someone%20might%20argue%20that%20the%20trend%20itself%20could%20give%20valuable%20information%20about%20the%20signal%20(see%20Duarte%20and%20Zatsiorsky%2C%202000)%2C%20but%20the%20problem%20is%20that%20most%20of%20the%20measurements%20one%20uses%20to%20describe%20a%20signal%20assumes%20that%20the%20signal%20is%20stationary.%20A%20signal%20is%20stationary%20if%20its%20statistical%20properties%20(such%20as%20mean%20and%20variance)%20do%20not%20change%20across%20time.%20So%2C%20to%20detrend%20the%20data%20might%20be%20necessary%20in%20certain%20cases.%20Another%20way%20to%20remove%20a%20trend%20in%20the%20data%20is%20to%20apply%20a%20high%20pass%20filter%20to%20the%20data%20with%20a%20cut-off%20frequency%20related%20to%20the%20period%20of%20data%20acquisition%20(Witt%20et%20al.%2C%201998).%0A%0A%20%20%20%20Removing%20the%20mean%20or%20a%20trend%20does%20not%20guarantee%20stationarity.%20Weak%20stationarity%20also%20requires%20finite%20variance%20and%20an%20autocovariance%20that%20depends%20on%20lag%20rather%20than%20absolute%20time.%20Inspect%20the%20record%20and%20state%20the%20preprocessing%20used%20before%20comparing%20sway%20measures.%0A%0A%20%20%20%20Let's%20see%20a%20simple%20function%20for%20data%20detrend%20in%20Python%20and%20use%20it%20to%20remove%20the%20mean%20of%20the%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(COP)%3A%0A%20%20%20%20from%20scipy.signal%20import%20detrend%0A%20%20%20%20COP_1%20%3D%20detrend(COP%2C%20axis%3D0%2C%20type%3D'constant')%0A%20%20%20%20return%20(COP_1%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**Exercise%201%20%E2%80%94%20Remove%20an%20offset.**%20A%20COP%20series%20is%20%24(10%2C11%2C9)%24%20cm.%20Find%20its%20demeaned%20values%20and%20range.%20Does%20subtracting%20the%20mean%20change%20its%20path%20length%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%20The%20mean%20is%2010%20cm%2C%20so%20the%20demeaned%20values%20are%20%24(0%2C1%2C-1)%24%20cm%20and%20range%20remains%202%20cm.%20Path%20length%20is%20%24%7C1-0%7C%2B%7C-1-1%7C%3D3%24%20cm%20before%20and%20after%20demeaning%3A%20constant%20translations%20do%20not%20affect%20differences.%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%20Measurements%20of%20spatial%20variability%0A%0A%20%20%20%20Standard%20deviation%2C%20RMS%2C%20range%20(or%20amplitude)%2C%20and%20total%20path%20(or%20total%20displacement)%20are%20commonly%20employed%20to%20describe%20the%20spatial%20variability%20of%20some%20measurement%20of%20postural%20sway.%20For%20the%20data%20represented%20by%20%24x%24%2C%20these%20variables%20are%20defined%20as%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbar%7Bx%7D%20%5C%3B%20(mean)%20%3D%20%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi%3D1%7D%5E%7BN%7D%20x_i%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20SD%20%3D%20%5Csqrt%7B%5Cfrac%7B1%7D%7BN-1%7D%5Csum_%7Bi%3D1%7D%5E%7BN%7D%20(x_i%20-%20%5Cbar%7Bx%7D)%5E2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20RMS%20%3D%20%5Csqrt%7B%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi%3D1%7D%5E%7BN%7D%20x_i%5E2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Range%20%3D%20max%5Bx%5D%20-%20min%5Bx%5D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Total%20%5C%3A%20path%20%3D%20%5Csum_%7Bi%3D1%7D%5E%7BN-1%7D%20%7C%20x_%7Bi%2B1%7D-x_i%20%7C%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(COP_1%2C%20np)%3A%0A%20%20%20%20m%20%3D%20np.mean(COP_1%2C%20axis%3D0)%0A%20%20%20%20sd%20%3D%20np.std(COP_1%2C%20axis%3D0%2C%20ddof%3D1)%0A%20%20%20%20rms%20%3D%20np.sqrt(np.mean(COP_1%20**%202%2C%20axis%3D0))%0A%20%20%20%20rang%20%3D%20np.max(COP_1%2C%20axis%3D0)%20-%20np.min(COP_1%2C%20axis%3D0)%0A%20%20%20%20tpath%20%3D%20np.sum(np.abs(np.diff(COP_1%2C%20axis%3D0))%2C%20axis%3D0)%0A%20%20%20%20unit%20%3D%20'cm'%0A%20%20%20%20print('Measurements%20of%20spatial%20variability')%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%5E16%7D'.format('Variable'%2C%20'Direction'))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%5E8%7D%20%7B2%3A%5E5%7D'.format(''%2C%20'ap'%2C%20'ml'))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E3%7D'.format('Mean%3A'%2C%20m%5B0%5D%2C%20m%5B1%5D%2C%20unit))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E3%7D'.format('SD%3A'%2C%20sd%5B0%5D%2C%20sd%5B1%5D%2C%20unit))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E3%7D'.format('RMS%3A'%2C%20rms%5B0%5D%2C%20rms%5B1%5D%2C%20unit))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E3%7D'.format('Range%3A'%2C%20rang%5B0%5D%2C%20rang%5B1%5D%2C%20unit))%0A%20%20%20%20print('%7B0%3A12%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E3%7D'.format('Total%20path%3A'%2C%20tpath%5B0%5D%2C%20tpath%5B1%5D%2C%20unit))%0A%20%20%20%20return%20(unit%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**Exercise%202%20%E2%80%94%20Distinguish%20RMS%20and%20sample%20SD.**%20For%20demeaned%20samples%20%24(0%2C1%2C-1)%24%20cm%2C%20calculate%20RMS%20and%20sample%20SD.%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%20RMS%20uses%20denominator%20N%3A%20%24%5Csqrt%7B2%2F3%7D%3D0.8165%24%20cm.%20Sample%20SD%20uses%20N%E2%88%921%3A%20%24%5Csqrt%7B2%2F2%7D%3D1%24%20cm.%20They%20are%20close%20for%20large%20N%2C%20but%20are%20not%20identical%20under%20these%20definitions.%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%20Mean%20velocity%20(or%20mean%20speed)%0A%0A%20%20%20%20The%20mean%20speed%20variable%20expresses%20the%20the%20average%20velocity%20of%20the%20COP%20displacement%20computed%20simply%20as%20the%20total%20path%20variable%20(the%20total%20displacement)%20divided%20by%20the%20total%20period.%20This%20variable%20is%20usually%20referred%20as%20velocity%20but%20as%20it%20a%20scalar%2C%20it%20should%20in%20fact%20be%20named%20speed.%3Cbr%3E%0A%20%20%20%20The%20mean%20resultant%20speed%20is%20the%20speed%20calculated%20in%20the%20vectorial%20form%20considering%20each%20direction%20(the%20square%20root%20of%20the%20sum%20of%20the%20squared%20speed%20in%20each%20direction).%20For%20the%20data%20represented%20by%20*x*%20and%20*y*%2C%20these%20variables%20are%20defined%20as%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Mean%20%5C%3A%20speed%20%3D%20%5Cfrac%7B1%7D%7BT%7D%5Csum_%7Bi%3D1%7D%5E%7BN-1%7D%20%7C%20x_%7Bi%2B1%7D-x_i%20%7C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Mean%20%5C%3A%20resultant%20%5C%3A%20speed%20%3D%20%5Cfrac%7B1%7D%7BT%7D%5Csum_%7Bi%3D1%7D%5E%7BN-1%7D%20%5Csqrt%7B(%20x_%7Bi%2B1%7D-x_i%20)%5E2%20%2B%20(%20y_%7Bi%2B1%7D-y_i%20)%5E2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24T%3D(N-1)%2Ff_s%24%20is%20the%20observed%20first-to-last%20sample%20duration.%20The%20norm%20of%20the%20two%20directional%20mean%20speeds%20is%20generally%20smaller%20than%20the%20mean%20resultant%20speed%3A%20averaging%20and%20taking%20a%20vector%20norm%20do%20not%20commute%20when%20movement%20direction%20varies.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(COP_1%2C%20freq%2C%20np%2C%20unit)%3A%0A%20%20%20%20T%20%3D%20(COP_1.shape%5B0%5D%20-%201)%20%2F%20freq%20%20%23%20span%20of%20the%20N-1%20observed%20increments%2C%20s%0A%20%20%20%20mvel%20%3D%20np.sum(np.abs(np.diff(COP_1%2C%20axis%3D0))%2C%20axis%3D0)%20%2F%20T%0A%20%20%20%20mvelr%20%3D%20np.sum(np.abs(np.sqrt(np.sum(np.diff(COP_1%2C%20axis%3D0)%20**%202%2C%20axis%3D1)))%2C%20axis%3D0)%20%2F%20T%0A%20%20%20%20print('%7B0%3A15%7D%20%7B1%3A%5E16%7D'.format('Variable'%2C%20'Direction'))%0A%20%20%20%20print('%7B0%3A15%7D%20%7B1%3A%5E8%7D%20%7B2%3A%5E5%7D'.format(''%2C%20'ap'%2C%20'ml'))%0A%20%20%20%20print('%7B0%3A15%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E6.2f%7D%20%7B3%3A%3E5%7D'.format('Mean%20velocity%3A'%2C%20mvel%5B0%5D%2C%20mvel%5B1%5D%2C%20unit%20%2B%20'%2Fs'))%0A%20%20%20%20print('')%0A%20%20%20%20print('%7B0%3A22%7D%20%7B1%3A%3E6.2f%7D%20%7B2%3A%3E5%7D'.format('Mean%20resultant%20velocity%3A'%2C%20mvelr%2C%20unit%20%2B%20'%2Fs'))%0A%20%20%20%20return%20(mvel%2C)%0A%0A%0A%40app.cell%0Adef%20_(mvel%2C%20np%2C%20unit)%3A%0A%20%20%20%20print('Euclidean%20norm%20of%20directional%20mean%20speeds%20(not%20mean%20resultant%20speed)%3A')%0A%20%20%20%20print('%7B0%3A%3E6.2f%7D%20%7B1%3A%3E5%7D'.format(np.sqrt(np.sum(mvel%20**%202))%2C%20unit%2B'%2Fs'))%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%20%E2%80%94%20Read%20speed%20from%20an%20out-and-back%20path.**%20At%20times%200%2C%201%20and%202%20s%2C%20COP%20positions%20are%20%24(0%2C0)%2C(1%2C0)%2C(0%2C0)%24%20cm.%20Find%20mean%20resultant%20speed%20and%20mean%20velocity.%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%20Total%20path%20is%202%20cm%20over%202%20s%2C%20so%20mean%20speed%20is%201%20cm%2Fs.%20Net%20displacement%20is%20zero%2C%20so%20mean%20velocity%20is%20%24(0%2C0)%24%20cm%2Fs.%20Repeated%20reversals%20can%20make%20path%20large%20without%20increasing%20the%20overall%20spread.%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%20Area%0A%0A%20%20%20%20Another%20measurement%20of%20postural%20sway%20is%20to%20compute%20the%20area%20that%20encompasses%20the%20COPap%20versus%20COPml%20data%20using%20a%20curve%20in%20a%20plane%20(e.g.%2C%20a%20circle%20or%20ellipse)%20or%20a%20polygon%20(e.g.%2C%20a%20rectangle).%20A%20common%20method%20for%20such%20is%20to%20compute%20a%20prediction%20ellipse%2C%20which%20is%20found%20by%20fitting%20an%20ellipse%20to%20the%20data%20using%20concepts%20from%20the%20statistical%20procedure%20known%20as%20principal%20component%20analysis.%20Under%20the%20bivariate-normal%20model%20and%20independent-sampling%20assumptions%20used%20in%20its%20construction%2C%20a%2095%25%20prediction%20ellipse%20targets%2095%25%20coverage%20for%20a%20new%20observation.%20COP%20samples%20are%20temporally%20correlated%2C%20so%20the%20fitted%20ellipse%20is%20usually%20best%20treated%20as%20a%20descriptive%20spatial%20measure%3B%20nominal%20coverage%20is%20not%20guaranteed%20for%20this%20time%20series.%20For%20more%20details%2C%20see%20%5BPrediction%20ellipse%20and%20ellipsoid%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fprediction_ellipse_ellipsoid.py).%0A%0A%20%20%20%20The%20function%20%60hyperellipsoid.py%60%20(see%20%5BPrediction%20ellipse%20and%20ellipsoid%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fprediction_ellipse_ellipsoid.py))%20calculates%20the%20ellipse%20area%2C%20some%20related%20parameters%2C%20and%20plots%20the%20results%20for%20a%20given%20multivariate%20random%20variable.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%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.cell%0Adef%20_(repo_file)%3A%0A%20%20%20%20import%20sys%0A%20%20%20%20sys.path.insert(0%2C%20str(repo_file('functions%2Fhyperellipsoid.py').parent))%20%20%23%20add%20to%20pythonpath%0A%20%20%20%20from%20hyperellipsoid%20import%20hyperellipsoid%0A%0A%20%20%20%20return%20(hyperellipsoid%2C)%0A%0A%0A%40app.cell%0Adef%20_(COP_1%2C%20hyperellipsoid)%3A%0A%20%20%20%20(area%2C%20axes%2C%20angles%2C%20center%2C%20R)%20%3D%20hyperellipsoid(COP_1%5B%3A%2C%201%5D%2C%20COP_1%5B%3A%2C%200%5D%2C%20units%3D'cm')%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%20%E2%80%94%20Interpret%20an%20ellipse.**%20Two%20ellipses%20have%20semiaxes%20(2%2C1)%20cm%20and%20(4%2C0.5)%20cm.%20Compare%20their%20areas%20and%20explain%20why%20area%20alone%20is%20incomplete.%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%20Both%20have%20area%20%24%5Cpi%20ab%3D2%5Cpi%24%20cm%C2%B2.%20Their%20anisotropy%20differs%3A%20one%20is%20much%20more%20elongated.%20Area%20does%20not%20retain%20orientation%2C%20direction-specific%20variability%20or%20temporal%20ordering.%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%20Frequency%20analysis%0A%0A%20%20%20%20Frequency%20analysis%20refers%20to%20estimate%20the%20frequency%20content%20of%20a%20signal.%20Let's%20use%20standard%20Fourier%20analysis%20and%20the%20related%20power%20spectral%20analysis%20to%20estimate%20some%20frequency%20characteristics%20of%20the%20COP%20displacement.%20The%20function%20%60psd2%60%20from%20the%20Python%20package%20%5Bpsd2%5D(https%3A%2F%2Fpypi.org%2Fproject%2Fpsd2%2F)%20(see%20how%20it%20works%20in%20the%20notebook%20%5BFourier%20transform%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Ffourier_transform.py))%20estimates%20the%20power%20spectral%20density%20with%20Welch's%20method%2C%20using%20the%20%60scipy.signal.welch%60%20function%2C%20estimates%20some%20frequency%20characteristics%2C%20and%20plots%20the%20results.%0A%0A%20%20%20%20Let's%20use%20%60psd2%60%20to%20estimate%20the%20frequency%20characteristics%20of%20the%20COP%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(COP_1%2C%20freq)%3A%0A%20%20%20%20from%20psd2%20import%20psd2%0A%20%20%20%20(fp_ap%2C%20mf_ap%2C%20fmax_ap%2C%20Ptot_ap%2C%20_F%2C%20P_ap)%20%3D%20psd2(COP_1%5B%3A%2C%200%5D%2C%20fs%3Dfreq%2C%20scales%3D'linear'%2C%20xlim%3D%5B0%2C%202%5D%2C%20units%3D'cm')%0A%20%20%20%20return%20(psd2%2C)%0A%0A%0A%40app.cell%0Adef%20_(COP_1%2C%20freq%2C%20psd2)%3A%0A%20%20%20%20(fp_ml%2C%20mf_ml%2C%20fmax_ml%2C%20Ptot_ml%2C%20_F%2C%20P_ml)%20%3D%20psd2(COP_1%5B%3A%2C%201%5D%2C%20fs%3Dfreq%2C%20xlim%3D%5B0%2C%202%5D%2C%20units%3D'cm')%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%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%20Checkpoint%20questions%0A%0A%20%20%20%201.%20What%20does%20demeaning%20preserve%3F%0A%20%20%20%202.%20Which%20duration%20matches%20N%20samples%20separated%20by%201%2Ffs%3F%0A%20%20%20%203.%20Does%20a%20nominal%2095%25%20ellipse%20guarantee%2095%25%20future%20coverage%20for%20autocorrelated%20nonstationary%20COP%3F%0A%20%20%20%204.%20Why%20can%20high-frequency%20noise%20strongly%20increase%20path%20speed%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.%20Differences%2C%20path%20length%2C%20range%20and%20covariance.%202.%20First-to-last%20timestamp%20duration%20is%20(N%E2%88%921)%2Ffs.%203.%20No%3B%20the%20probability%20interpretation%20depends%20on%20distributional%20and%20sampling%20assumptions.%204.%20Many%20rapid%20sample-to-sample%20changes%20accumulate%20into%20path%20length.%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%201.%20A%20trajectory%20moves%20through%20(0%2C0)%2C%20(3%2C4)%2C%20(6%2C0)%20cm%20at%200%2C%201%20and%202%20s.%20Give%20path%20length%2C%20mean%20resultant%20speed%20and%20mean%20velocity.%0A%0A%20%20%20%202.%20An%20ellipse%20has%20semiaxes%201.5%20and%200.8%20cm.%20Give%20area.%0A%0A%20%20%20%203.%20A%20100%20Hz%20record%20contains%206000%20samples.%20Give%20its%20first-to-last%20duration.%0A%0A%20%20%20%204.%20Two%20traces%20have%20equal%20SD%20but%20different%20sampling%20rates%20and%20filtering.%20Can%20their%20raw%20COP%20path%20speeds%20be%20directly%20ranked%20as%20balance%20quality%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%20Final%20answers%20to%20Problems%0A%0A%20%20%20%201.%2010%20cm%3B%205%20cm%2Fs%3B%20(3%2C0)%20cm%2Fs.%0A%0A%20%20%20%202.%20%241.2%5Cpi%5Capprox3.770%24%20cm%C2%B2.%0A%0A%20%20%20%203.%2059.99%20s.%0A%0A%20%20%20%204.%20No%3B%20acquisition%20and%20processing%20must%20be%20made%20comparable%2C%20and%20clinical%20or%20functional%20meaning%20requires%20the%20task%20context.%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%20Use%20%5BKineticsFundamentalConcepts%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fkinetics_fundamental_concepts.py)%20to%20connect%20this%20guide%20with%20the%20surrounding%20mechanics%20and%20modeling%20material.%20Return%20to%20the%20assumptions%20behind%20each%20equation%20when%20applying%20it%20to%20a%20new%20experiment.%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%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20%5BMIT%20OpenCourseWare%5D(https%3A%2F%2Focw.mit.edu%2Fcourses%2Fres-6-007-signals-and-systems-spring-2011%2Fvideo_galleries%2Fvideo-lectures%2F)%20%E2%80%94%20Signals%20and%20Systems%3A%20the%20Fourier-series%2C%20filtering%20and%20sampling%20lectures%20explain%20the%20frequency%20analysis%20and%20processing%20choices%20used%20here.%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-%20Duarte%20M%2C%20Zatsiorsky%20VM%20(2000)%20%5BOn%20the%20fractal%20properties%20of%20natural%20human%20standing%5D(https%3A%2F%2Fpubmed.ncbi.nlm.nih.gov%2F10754215).%20Neuroscience%20Letters%2C%20283%2C%20173-176.%0A%0A%20%20%20%20-%20Lafond%2C%20D.%2C%20M.%20Duarte%2C%20et%20al.%20(2004).%20%5BComparison%20of%20three%20methods%20to%20estimate%20the%20center%20of%20mass%20during%20balance%20assessment%5D(https%3A%2F%2Fpubmed.ncbi.nlm.nih.gov%2F15275850).%20J.%20Biomech.%2037(9)%3A%201421-1426.%0A%0A%20%20%20%20-%20Santos%20DA%2C%20Duarte%20M%20(2016)%20%5BA%20public%20data%20set%20of%20human%20balance%20evaluations%5D(https%3A%2F%2Fdoi.org%2F10.7717%2Fpeerj.2648).%20PeerJ%2C%204%2C%20e2648.%0A%0A%20%20%20%20-%20Witt%20A%2C%20Kurths%20J%2C%20Pikovsky%20A%20(1998)%20%5BTesting%20stationarity%20in%20time%20series%5D(http%3A%2F%2Fjournals.aps.org%2Fpre%2Fabstract%2F10.1103%2FPhysRevE.58.1800).%20Physical%20Review%20E%2C%2058%2C%201800-1810.%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
572d633e386e54edaca6edba3248f87e