dsp/window: revert tukey
MODIFY
AUTHORS
AUTHORS
@@ -12,7 +12,6 @@ Alexander Egurnov <alexander.egurnov@gmail.com>
Andrei Blinnikov <goofinator@mail.ru>
Bill Gray <wgray@gogray.com>
Bill Noon <noon.bill@gmail.com>
-Brandon Dube <brandon.dube@jpl.nasa.gov> <brandon@retrorefractions.com>
Brendan Tracey <tracey.brendan@gmail.com>
Brent Pedersen <bpederse@gmail.com>
Chad Kunde <kunde21@gmail.com>

MODIFY
CONTRIBUTORS
CONTRIBUTORS
@@ -20,7 +20,6 @@ Andrei Blinnikov <goofinator@mail.ru>
Andrew Brampton <brampton@gmail.com>
Bill Gray <wgray@gogray.com>
Bill Noon <noon.bill@gmail.com>
-Brandon Dube <brandon.dube@jpl.nasa.gov> <brandon@retrorefractions.com>
Brendan Tracey <tracey.brendan@gmail.com>
Brent Pedersen <bpederse@gmail.com>
Chad Kunde <kunde21@gmail.com>

MODIFY
dsp/window/window_complex.go
dsp/window/window_complex.go
@@ -6,7 +6,7 @@ package window
import "math"
-// RectangularComplex modifies seq in place by the Rectangular window and returns the result.
+// Rectangular modifies seq in place by the Rectangular window and returns the result.
// See https://en.wikipedia.org/wiki/Window_function#Rectangular_window and
// https://www.recordingblogs.com/wiki/rectangular-window for details.
//

MODIFY
dsp/window/window_test.go
dsp/window/window_test.go
@@ -12,11 +12,6 @@ import (
"gonum.org/v1/gonum/floats/scalar"
)
-const (
- gaussWin = iota
- tukeyWin
-)
-
var windowTests = []struct {
name string
fn func([]float64) []float64
@@ -118,53 +113,31 @@ var windowTests = []struct {
},
}
-var monoParamWindowTests = []struct {
+var gausWindowTests = []struct {
name string
- param float64
- winType int
+ sigma float64
want []float64
}{
{
- name: "Gaussian", param: 0.3, winType: gaussWin,
+ name: "Gaussian", sigma: 0.3,
want: []float64{
0.006645, 0.018063, 0.043936, 0.095634, 0.186270, 0.324652, 0.506336, 0.706648, 0.882497, 0.986207,
0.986207, 0.882497, 0.706648, 0.506336, 0.324652, 0.186270, 0.095634, 0.043936, 0.018063, 0.006645},
},
{
- name: "Gaussian", param: 0.5, winType: gaussWin,
+ name: "Gaussian", sigma: 0.5,
want: []float64{
0.164474, 0.235746, 0.324652, 0.429557, 0.546074, 0.666977, 0.782705, 0.882497, 0.955997, 0.995012,
0.995012, 0.955997, 0.882497, 0.782705, 0.666977, 0.546074, 0.429557, 0.324652, 0.235746, 0.164474,
},
},
{
- name: "Gaussian", param: 1.2, winType: gaussWin,
+ name: "Gaussian", sigma: 1.2,
want: []float64{
0.730981, 0.778125, 0.822578, 0.863552, 0.900293, 0.932102, 0.958357, 0.978532, 0.992218, 0.999132,
0.999132, 0.992218, 0.978532, 0.958357, 0.932102, 0.900293, 0.863552, 0.822578, 0.778125, 0.730981,
},
},
- {
- name: "Tukey", param: 1, winType: tukeyWin,
- want: []float64{ // copied from Hann
- 0.006155, 0.054496, 0.146447, 0.273005, 0.421783, 0.578217, 0.726995, 0.853553, 0.945503, 0.993844,
- 0.993844, 0.945503, 0.853553, 0.726995, 0.578217, 0.421783, 0.273005, 0.146447, 0.054496, 0.006155,
- },
- },
- {
- name: "Tukey", param: 0, winType: tukeyWin,
- want: []float64{ // copied from rectangular
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- },
- },
- {
- name: "Tukey", param: 0.5, winType: tukeyWin,
- want: []float64{
- 0.000000, 0.105430, 0.377257, 0.700847, 0.939737, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
- 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 0.939737, 0.700847, 0.377257, 0.105429, 0.000000,
- },
- },
}
func TestWindows(t *testing.T) {
@@ -195,21 +168,20 @@ func TestWindows(t *testing.T) {
}
}
-func TestMonoParametricWindows(t *testing.T) {
+func TestGausWindows(t *testing.T) {
t.Parallel()
const tol = 1e-6
- for _, test := range monoParamWindowTests {
- t.Run(fmt.Sprintf("%s (param=%.1f)", test.name, test.param), func(t *testing.T) {
+ for _, test := range gausWindowTests {
+ t.Run(fmt.Sprintf("%s (sigma=%.1f)", test.name, test.sigma), func(t *testing.T) {
src := make([]float64, 20)
for i := range src {
src[i] = 1
}
- type transformer interface {
- Transform([]float64) []float64
- }
- trans := []transformer{Gaussian{test.param}, Tukey{test.param}}[test.winType]
- dst := trans.Transform(src)
+
+ gaussian := Gaussian{test.sigma}
+
+ dst := gaussian.Transform(src)
if !floats.EqualApprox(dst, test.want, tol) {
t.Errorf("unexpected result for window function %q:\ngot:%#.6v\nwant:%#v", test.name, dst, test.want)
}
@@ -218,7 +190,7 @@ func TestMonoParametricWindows(t *testing.T) {
src[i] = 1
}
- dst = NewValues(trans.Transform, len(src)).Transform(src)
+ dst = NewValues(gaussian.Transform, len(src)).Transform(src)
if !floats.EqualApprox(dst, test.want, tol) {
t.Errorf("unexpected result for lookup window function %q:\ngot:%#.6v\nwant:%#.6v", test.name, dst, test.want)
}
@@ -258,15 +230,14 @@ func TestGausWindowComplex(t *testing.T) {
t.Parallel()
const tol = 1e-6
- for _, test := range monoParamWindowTests {
- if test.winType == gaussWin {
- t.Run(fmt.Sprintf("%sComplex (sigma=%.1f)", test.name, test.param), func(t *testing.T) {
+ for _, test := range gausWindowTests {
+ t.Run(fmt.Sprintf("%sComplex (sigma=%.1f)", test.name, test.sigma), func(t *testing.T) {
src := make([]complex128, 20)
for i := range src {
src[i] = complex(1, 1)
}
- gaussian := GaussianComplex{test.param}
+ gaussian := GaussianComplex{test.sigma}
dst := gaussian.Transform(src)
if !equalApprox(dst, test.want, tol) {
@@ -284,7 +255,6 @@ func TestGausWindowComplex(t *testing.T) {
})
}
}
-}
func equalApprox(seq1 []complex128, seq2 []float64, tol float64) bool {
if len(seq1) != len(seq2) {

dsp/window: revert tukey