diff options
| author | wukong <wukong@longaeva> | 2026-04-10 23:46:12 -0700 |
|---|---|---|
| committer | wukong <wukong@longaeva> | 2026-04-10 23:46:12 -0700 |
| commit | 4c4eb1bd8f003b3b57707badd2dd089ed193a896 (patch) | |
| tree | 15b62907fffd70c46a9b4369df93ab33c6aa88ac /fir_window_hamming.awk | |
| parent | e7d1781578e846a7b1d634cd43c8fab00a67b883 (diff) | |
renamed fir window generators;
minor edits to whitespace and comments for more consistent style;
Diffstat (limited to 'fir_window_hamming.awk')
| -rw-r--r-- | fir_window_hamming.awk | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/fir_window_hamming.awk b/fir_window_hamming.awk new file mode 100644 index 0000000..5660754 --- /dev/null +++ b/fir_window_hamming.awk @@ -0,0 +1,41 @@ +#!/usr/bin/awk -f
+
+### fir_window_hamming.awk
+# generate a Hamming 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.
+
+
+# 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*atan2(1,1)
+
+ 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
+ }
+ }
+}
+
|
