summaryrefslogtreecommitdiff
path: root/hamming.sh
blob: b466325b38345fa4c7d7fbb1971f5ab92d77efac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

### hamming.sh
# Convolve input vector with 3-element Hamming window [0.23, 0.54, 0.23]
# note: bash built-in $(( )) construct only supports integer arithmetic
# floating point operations will require another language such as awk, perl,
# python, etc.

### 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