summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-01-22 18:41:37 +0100
committerTobias Klauser <tklauser@distanz.ch>2013-01-22 18:41:37 +0100
commit0c30772d808bec56b65c33c2bb08452187fd464d (patch)
treed929504a7a460985485a67e19ac9f6cd5d5e1395 /scripts
parentd2e67dad03ff980fc872b71192b695c5d249d509 (diff)
scripts/random-muscle-activation.py: Revert to fixed smoothing method
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/random-muscle-activation.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/scripts/random-muscle-activation.py b/scripts/random-muscle-activation.py
index 2af82b5..870fee3 100755
--- a/scripts/random-muscle-activation.py
+++ b/scripts/random-muscle-activation.py
@@ -26,6 +26,7 @@ DEFAULT_YDMAX = 0.5
WINDOWS = [ 'flat', 'hanning', 'hamming', 'bartlett', 'blackman' ]
WINDOW_LEN = 11
+DEFAULT_WINDOW = 'blackman'
def usage():
print("""usage: {} [OPTION...] FILE...
@@ -33,21 +34,19 @@ def usage():
Generate random muscle activation data in CSV.
options:
- -f force overwrite of existing file
- -n N set number of data points to N (default: {})
- -p plot data after generating it
- -s WIN smoothen the data using WIN window function
- WIN should be one of {}
- -i N set minimum initial y value to N (default: {})
- -I N set maximum initial y value to N (default: {})
- -x N set minimum x value to N (default: {})
- -X N set maximum x value to N (default: {})
- -y N set minimum y value to N (default: {})
- -Y N set maximum y value to N (default: {})
- -d N set minimum y change value to N (default: {})
- -D N set maximum y change value to N (default: {})""".format(
+ -f force overwrite of existing file
+ -n N set number of data points to N (default: {})
+ -p plot data after generating it
+ -s smoothen the data using blackman window function
+ -i N set minimum initial y value to N (default: {})
+ -I N set maximum initial y value to N (default: {})
+ -x N set minimum x value to N (default: {})
+ -X N set maximum x value to N (default: {})
+ -y N set minimum y value to N (default: {})
+ -Y N set maximum y value to N (default: {})
+ -d N set minimum y change value to N (default: {})
+ -D N set maximum y change value to N (default: {})""".format(
os.path.basename(sys.argv[0]), DEFAULT_N,
- ", ".join(WINDOWS),
DEFAULT_YMIN, DEFAULT_YMAX,
DEFAULT_XMIN, DEFAULT_XMAX,
DEFAULT_YMIN, DEFAULT_YMAX,
@@ -71,7 +70,7 @@ def generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax, imin, imax
return act
# based on scipy.org/Cookbook/SignalSmooth
-def smoothen(x, window='hanning', window_len=11):
+def smoothen(x, window=DEFAULT_WINDOW, window_len=WINDOW_LEN):
"""
smoothen signal using a window with requested size
@@ -107,7 +106,7 @@ def smoothen(x, window='hanning', window_len=11):
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], "fn:ps:i:I:x:X:y:Y:d:D:h")
+ opts, args = getopt.getopt(sys.argv[1:], "fn:psi:I:x:X:y:Y:d:D:h")
except getopt.GetoptError as err:
print(str(err))
usage()
@@ -115,7 +114,7 @@ def main():
do_overwrite = False
do_plot = False
- window = None
+ do_smooth = False
N = DEFAULT_N
imin = DEFAULT_YMIN
imax = DEFAULT_YMAX
@@ -138,7 +137,7 @@ def main():
elif o == '-p':
do_plot = True
elif o == '-s':
- window = a
+ do_smooth = True
elif o == '-i':
try:
imin = float(a)
@@ -243,9 +242,16 @@ def main():
for a in args:
with open(a, 'w') as f:
act = generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax, imin, imax)
- if window:
- sact = smoothen(act[:,1], window, WINDOW_LEN)
- sact = sact[(WINDOW_LEN - 1) / 2:-(WINDOW_LEN - 1) / 2]
+ if do_smooth:
+ all_in_range = False
+ n = 0
+ while not all_in_range:
+ print("Smooth pass " + str(n))
+ sact = smoothen(act[:,1], DEFAULT_WINDOW, WINDOW_LEN)
+ sact = sact[(WINDOW_LEN - 1) / 2:-(WINDOW_LEN - 1) / 2]
+ if sact.min() >= ymin and sact.max() <= ymax:
+ all_in_range = True
+ n += 1
plt.plot(act[:,1])
plt.plot(sact)
plt.legend(['original', 'smoothened'])