diff --git a/dsp/window/window_parametric.go b/dsp/window/window_parametric.go index cc110647..f1624fd2 100644 --- a/dsp/window/window_parametric.go +++ b/dsp/window/window_parametric.go @@ -147,23 +147,10 @@ func (v Values) Transform(seq []float64) []float64 { return seq } -// ValuesComplex is an arbitrary complex window function. -type ValuesComplex []complex128 - -// NewValuesComplex returns a ValuesComplex of length n with weights corresponding -// to the provided window function. -func NewValuesComplex(window func([]complex128) []complex128, n int) ValuesComplex { - v := make(ValuesComplex, n) - for i := range v { - v[i] = 1 - } - return window(v) -} - -// Transform applies the weights in the receiver to seq in place, returning the -// result. If v is nil, Transform is a no-op, otherwise the length of v must -// match the length of seq. -func (v ValuesComplex) Transform(seq []complex128) []complex128 { +// TransformComplex applies the weights in the receiver to seq in place, returning +// the result. If v is nil, TransformComplex is a no-op, otherwise the length of v +// must match the length of seq. +func (v Values) TransformComplex(seq []complex128) []complex128 { if v == nil { return seq } @@ -171,7 +158,8 @@ func (v ValuesComplex) Transform(seq []complex128) []complex128 { panic("window: length mismatch") } for i, w := range v { - seq[i] *= w + sv := seq[i] + seq[i] = complex(w*real(sv), w*imag(sv)) } return seq } diff --git a/dsp/window/window_test.go b/dsp/window/window_test.go index 1bda1887..18bfeacb 100644 --- a/dsp/window/window_test.go +++ b/dsp/window/window_test.go @@ -202,7 +202,7 @@ func TestWindowsComplex(t *testing.T) { src[i] = complex(1, 1) } - dst = NewValuesComplex(test.fnCmplx, len(src)).Transform(src) + dst = NewValues(test.fn, len(src)).TransformComplex(src) if !equalApprox(dst, test.want, tol) { t.Errorf("unexpected result for lookup window function %q:\ngot:%#.6v\nwant:%#.6v", test.name, dst, test.want) }