summaryrefslogtreecommitdiff
path: root/hamming.sh
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2018-06-05 22:34:51 -0700
committerwukong <wukong@longaeva>2018-06-05 22:34:51 -0700
commit8f263e859e0970ce87b77addc80dec28e8fc7e82 (patch)
treeb0bdc392230c9960f5e5f5b3dea979405334628f /hamming.sh
re-init
Diffstat (limited to '')
-rw-r--r--hamming.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/hamming.sh b/hamming.sh
new file mode 100644
index 0000000..fdd6ba6
--- /dev/null
+++ b/hamming.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+### hamming.sh
+# Convolve input vector with 3-element Hamming window [0.23, 0.54, 0.23]
+# note: bash built-in $(( )) constructs only support integer arithmetic
+# floating point operation will require another language such as awk, perl, or
+# python.
+
+### input vector as array
+X=($1)
+echo ${#X[@]}
+
+### Hamming window vector
+H=(0.23 0.54 0.23)
+echo ${#H[@]}
+
+### length of output
+L=$(( ${#X[@]} + ${#H[@]} - 1 ))
+
+### iterate over both vectors
+for N in $( seq 0 1 $L ) ; do
+ for M in $( seq 0 1 $(( ${#H[@]} - 1 )) ) ; do
+ if [ $(( $N >= $M )) ] ; then
+ printf "N=$N\tM=$M\tN-M=$(( $N - $M ))\n"
+ else
+ continue
+ fi
+ done
+done
+