summaryrefslogtreecommitdiff
path: root/hamming.awk
blob: c8530035a6a51af3f2890ce902960fc3ed53f008 (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
### 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 {

    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]
        }
        printf("%g  %g\n", w[n], 2.0*(w[n])/(N + 1))
    }

}