#!/usr/bin/awk -f ### fir_window_hamming.awk # generate a Hamming raised cosine FIR window # R.W. Hamming, 'Digital Filters': H = '0.23 0.54 0.23' # https://en.wikipedia.org/wiki/Window_function provides a few values for the # 'a0' and 'a1' parameters of the raised cosine. # note: the forms provided from wikipedia do not give expected results and # appear to show inconsistency between raised cosine variations. need to # cross-check these forms against DSP/signaling texts. # Hamming window (raised cosine) function hamming(n) { # optimal values for equal-ripple #a0 = 0.53836 #a1 = 0.46164 a0 = (25.0/46.0) a1 = (21.0/46.0) return a0 + a1*cos((pi*n)/M) } BEGIN { ARGV[1] ? N = ARGV[1] : N = 0 ARGV[2] ? OFMT = "%." ARGV[2] "g" : OFMT = "%g" # window interval goes from -M to M M = 0.5*(N - 1) pi = 4.0*atan2(1.0, 1.0) for (n=-M; n<=M; n++) { if (N > 1 && M > 0) { w[n] = hamming(n) print n + M, w[n]/M } else { print n + M, 1.0 } } }