diff options
Diffstat (limited to '')
| -rw-r--r-- | fir_window.awk | 6 | ||||
| -rw-r--r-- | fir_window_gaussian.awk | 4 | ||||
| -rw-r--r-- | fir_window_hamming.awk | 4 | ||||
| -rw-r--r-- | fir_window_vonhann.awk | 3 | ||||
| -rw-r--r-- | sum.awk | 31 | ||||
| -rw-r--r-- | sum1.awk | 43 | ||||
| -rw-r--r-- | sum2.awk | 29 | ||||
| -rw-r--r-- | sum3.awk | 39 | ||||
| -rw-r--r-- | sum4.awk | 49 | ||||
| -rw-r--r-- | sum_col.awk | 47 |
10 files changed, 87 insertions, 168 deletions
diff --git a/fir_window.awk b/fir_window.awk index 076e5df..d5ad86c 100644 --- a/fir_window.awk +++ b/fir_window.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk -f
-### hamming.awk
-# generate a Hamming window
+### fir_window.awk
+# generate a 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.
@@ -43,7 +43,7 @@ BEGIN { # window interval goes from -M to M
M = 0.5*(N - 1)
- pi = 4*atan2(1,1)
+ pi = 4.0*atan2(1.0, 1.0)
for (n=-M; n<=M; n++) {
if (N > 1 && M > 0) {
diff --git a/fir_window_gaussian.awk b/fir_window_gaussian.awk index 14ebc48..cf2dd12 100644 --- a/fir_window_gaussian.awk +++ b/fir_window_gaussian.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk -f
### fir_window_gaussian.awk
-# generate a Gaussian window
+# generate a Gaussian FIR window
# https://en.wikipedia.org/wiki/Window_function
@@ -21,7 +21,7 @@ BEGIN { # window interval goes from -M to M
M = 0.5*(N - 1)
- pi = 4*atan2(1,1)
+ pi = 4.0*atan2(1.0, 1.0)
for (n=0; n<N; n++) {
if (N > 1 && M > 0) {
diff --git a/fir_window_hamming.awk b/fir_window_hamming.awk index 51eb0d8..95bd827 100644 --- a/fir_window_hamming.awk +++ b/fir_window_hamming.awk @@ -1,7 +1,7 @@ #!/usr/bin/awk -f
### fir_window_hamming.awk
-# generate a Hamming window
+# 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.
@@ -29,7 +29,7 @@ BEGIN { # window interval goes from -M to M
M = 0.5*(N - 1)
- pi = 4.0*atan2(1.0,1.0)
+ pi = 4.0*atan2(1.0, 1.0)
for (n=-M; n<=M; n++) {
if (N > 1 && M > 0) {
diff --git a/fir_window_vonhann.awk b/fir_window_vonhann.awk index 3c831c7..d4b010e 100644 --- a/fir_window_vonhann.awk +++ b/fir_window_vonhann.awk @@ -1,6 +1,7 @@ #!/usr/bin/awk -f
### fir_window_vonhann.awk
+# generate a vonHann raised cosine FIR window
# https://en.wikipedia.org/wiki/Window_function provides a few values for the
# 'a0' and 'a1' parameters of the raised cosine.
@@ -20,7 +21,7 @@ BEGIN { # window interval goes from -M to M
M = 0.5*(N - 1)
- pi = 4*atan2(1,1)
+ pi = 4.0*atan2(1.0, 1.0)
for (n=-M; n<=M; n++) {
if (N > 1 && M > 0) {
@@ -0,0 +1,31 @@ +#!/usr/bin/awk -f
+
+### sum.awk
+# calculate sum of serialized input
+
+
+BEGIN {
+ OFS = FS
+ sign = "[+-]?"
+ decimal = "[0-9]+[.]?[0-9]*"
+ fraction = "[.][0-9]+"
+ exponent = "([Ee]" sign "[0-9]+)?"
+ number = "^" sign "(" decimal "|" fraction ")" exponent "$"
+}
+
+
+NF > 0 {
+ for (n=1; n<=NF; n++) {
+ if ($n ~ number) {
+ count += 1
+ sum += $n
+ }
+ }
+}
+
+
+END {
+ print "sum", "count"
+ print sum, count
+}
+
diff --git a/sum1.awk b/sum1.awk deleted file mode 100644 index 9266789..0000000 --- a/sum1.awk +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/awk -f - -### sum1.awk, print column sums -# input: rows of numbers -# output: sum of each column -# missing entries are treated as zeros - - -function isnum(n) { - sign = "[+-]?" - decimal = "[0-9]+[.]?[0-9]*" - fraction = "[.][0-9]+" - exponent = "([Ee]" sign "[0-9]+)?" - number = "^" sign "(" decimal "|" fraction ")" exponent "$" - return n ~ number -} - - -BEGIN { - OFS = FS -} - - -NR == 1 { - for (i=1; i<=NF; i++) - isnum($i) ? header[i] = "col" i : header[i] = $i -} - - -NF > 0 { - (NF > nf_max) ? nf_max = NF : nf_max = nf_max - for (i=1; i<=NF; i++) - sum[i] += $i -} - - -END { - for (i=1; i<=nf_max; i++) { - printf(OFMT, sum[i]) - printf((i < nf_max) ? OFS : ORS) - } -} - diff --git a/sum2.awk b/sum2.awk deleted file mode 100644 index 4fcf3b6..0000000 --- a/sum2.awk +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/awk -f - -### sum2.awk, print column sums -# check that each line has the same number of fields as line one - - -BEGIN { - OFS = FS -} - - -NR == 1 { - for (i=1; i<=NF; i++) - isnum($i) ? header[i] = "col" i : header[i] = $i -} - - -NF > 0 { - (NF > nf_max) ? nf_max = NF : nf_max = nf_max - for (i=1; i<=NF; i++) - sum[i] += $i -} - - -END { - for (i=1; i<=nf_max; i++) - printf(OFMT "%s", sum[i], i < nf_max ? OFS : ORS) -} - diff --git a/sum3.awk b/sum3.awk deleted file mode 100644 index 7f11a49..0000000 --- a/sum3.awk +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/awk -f - -### sum3.awk, print sums of numeric columns -# input: rows of integers and strings -# output: sums of numeric columns -# assumes every line has same layout - - -function isnum(n) { - return n ~ /^[+-]?[0-9]+$/ -} - - -BEGIN { - OFS = FS -} - - -NR == 1 { - for (i=1; i<=NF; i++) - numcol[i] = isnum($i) -} - - -NF > 0 { - (NF > nf_max) ? nf_max = NF : nf_max = nf_max - for (i=1; i<=NF; i++) - if (numcol[i]) - sum[i] += $i -} - - -END { - for (i=1; i<=nf_max; i++) { - printf(numcol[i] ? sum[i] : "--") - printf(i < nf_max ? OFS : ORS) - } -} - diff --git a/sum4.awk b/sum4.awk deleted file mode 100644 index 3e61843..0000000 --- a/sum4.awk +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/awk -f - -### sum4.awk, print sums of numeric columns -# input: rows of integers and strings -# output: sums of numeric columns - - -function isnum(n) { - sign = "[+-]?" - decimal = "[0-9]+[.]?[0-9]*" - fraction = "[.][0-9]+" - exponent = "([Ee]" sign "[0-9]+)?" - number = "^" sign "(" decimal "|" fraction ")" exponent "$" - return n ~ number -} - - -BEGIN { - OFS = FS -} - - -NR == 1 { - for (i=1; i<=NF; i++) - isnum($i) ? header[i] = "col" i : header[i] = $i -} - - -NF > 0 { - (NF > nf_max) ? nf_max = NF : nf_max = nf_max - for (i=1; i<=NF; i++) { - if ($i == header[i]) - continue - if (isnum($i)) { - count[i]++ - sum[i] += $i - } - } -} - - -END { - for (i=1; i<=nf_max; i++) { - printf((header[i]) ? header[i] OFS : OFS) - printf((count[i]) ? count[i] OFS sum[i] : OFS) - printf(ORS) - } -} - diff --git a/sum_col.awk b/sum_col.awk new file mode 100644 index 0000000..f08ec06 --- /dev/null +++ b/sum_col.awk @@ -0,0 +1,47 @@ +#!/usr/bin/awk -f + +### sum_col.awk +# sum columns of numerical data +# input: delimited data as text +# output: list of univariate summary stats + + +BEGIN { + OFS = FS + sign = "[+-]?" + decimal = "[0-9]+[.]?[0-9]*" + fraction = "[.][0-9]+" + exponent = "([Ee]" sign "[0-9]+)?" + number = "^" sign "(" decimal "|" fraction ")" exponent "$" +} + + +# read column headers +NR == 1 { + for (n=1; n<=NF; n++) + ($n ~ number) ? header[n] = "col" n : header[n] = $n +} + + +# iterate over columns +NF > 0 { + (NF > nf_max) ? nf_max = NF : nf_max = nf_max + for (n=1; n <= NF; n++) { + if ($n ~ number) { + count[n] += 1 + sum[n] += $n + } + } +} + + +END { + print "col", "sum", "count" + for (n=1; n<=nf_max; n++) { + if (header[n]) + print header[n], sum[n], count[n] + else + print "col" n, sum[n], count[n] + } +} + |
