Created
June 3, 2023 22:12
-
-
Save mrrezaie/3c6847e899ec680b99cb05a7608af679 to your computer and use it in GitHub Desktop.
Apply filter and time-normalize STO/MOT files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by Mohammadreza Rezaie [kernalnt@gmail.com] | |
import org.opensim.utils as utils | |
import os | |
folder = utils.FileUtils.getInstance().browseForFolder('Choose a dirctory where STO/MOT files are located',0) | |
if folder==None: | |
print('Nothing was selected') | |
else: | |
print(folder) | |
for name in os.listdir(folder): | |
if (name.endswith('.sto') or name.endswith('.mot')) and ('N101' not in name): | |
fileName = os.path.join(folder,name) | |
outputName = os.path.join(folder,name[:-4]+'_N101.sto') | |
print(fileName) | |
# read file | |
file = modeling.Storage(fileName) | |
# get first and last time frames | |
t0 = file.getFirstTime() | |
t1 = file.getLastTime() | |
# add pad to the signal and apply Butterworth filter | |
file.pad(20) # add pad, n: 20 | |
file.lowpassIIR(14) # cut-off frequency: 14 Hz | |
file.crop(t0,t1) # remove pad | |
# resample (normalize) to 101 points (0-100%) | |
dt = float(t1-t0)/(101 - 1) # time interval | |
file.resampleLinear(dt) | |
file.print(outputName) | |
print('FINISHED!!!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment