summaryrefslogtreecommitdiff
path: root/hamming.awk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--hamming.awk29
1 files changed, 29 insertions, 0 deletions
diff --git a/hamming.awk b/hamming.awk
new file mode 100644
index 0000000..30140a5
--- /dev/null
+++ b/hamming.awk
@@ -0,0 +1,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.
+
+a1EGIN {
+
+ 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] = 0.5*a0 - 0.5*a1*cos((2*pi*n)/(N - 1))
+ sum_w += w[n]
+ }
+ printf("%f %f\n", w[n], w[n]/sum_w)
+ }
+
+}