summaryrefslogtreecommitdiff
path: root/hamming.awk
blob: b0482999c4fbb55c7a88e84004b1d75d2050c6d9 (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
31
#!/usr/bin/awk -f

### hamming.awk
# generate a Hamming window
# https://en.wikipedia.org/wiki/Window_function provides a few values for the
# 'a0' and 'a1' parameters of the raised cosine.

BEGIN {
    OMFT = "%.18g"
    N = ARGV[1]
    pi = 4*(4*atan2(1,5) - atan2(1,239))

    #a0 = (25.0/46.0)
    #a1 = (21.0/46.0)

    ### optimal values for equal-ripple
    a0 = 0.53836
    a1 = 0.46164

    ### R.W. Hamming, "Digital Filters"
    # H = "0.23 0.54 0.23"

    for (n=0; n<N; n++) {
        if (N > 1) {
            w[n] = a0 - a1*cos((2*pi*n)/(N - 1))
            sum_w += w[n]
        }
        print 2.0*(w[n])/(N + 1)
    }

}