dsp/window: add Values.TransformTo window functions and example

This commit is contained in:
Dan Kortschak
2021-01-08 18:18:09 +10:30
parent 1c2011e56d
commit 676e41577b
3 changed files with 100 additions and 2 deletions

View File

@@ -118,3 +118,42 @@ func ExampleValues() {
//
// dst: [0.000000 0.164595 0.324699 0.475947 0.614213 0.735724 0.837166 0.915773 0.969400 0.996584 0.996584 0.969400 0.915773 0.837166 0.735724 0.614213 0.475947 0.324699 0.164595 0.000000]
}
func ExampleValues_TransformTo_gabor() {
src := []float64{1, 2, 1, 0, -1, -1, -2, -2, -1, -1,
0, 1, 1, 2, 1, 0, -1, -2, -1, 0}
// Create a Gaussian Window lookup table for 4 samples.
gaussian := window.NewValues(window.Gaussian{0.5}.Transform, 4)
// Prepare a destination.
dst := make([]float64, 8)
// Apply the transformation to the src, placing it in dst.
for i := 0; i < len(src)-len(gaussian); i++ {
gaussian.TransformTo(dst[0:len(gaussian)], src[i:i+len(gaussian)])
// To perform the Gabor transform, we would calculate
// the FFT on dst for each iteration.
fmt.Printf("FFT(%f)\n", dst)
}
// Output:
//
// FFT([0.135335 1.601475 0.800737 0.000000 0.000000 0.000000 0.000000 0.000000])
// FFT([0.270671 0.800737 0.000000 -0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([0.135335 0.000000 -0.800737 -0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([0.000000 -0.800737 -0.800737 -0.270671 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.135335 -0.800737 -1.601475 -0.270671 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.135335 -1.601475 -1.601475 -0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.270671 -1.601475 -0.800737 -0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.270671 -0.800737 -0.800737 0.000000 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.135335 -0.800737 0.000000 0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([-0.135335 0.000000 0.800737 0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([0.000000 0.800737 0.800737 0.270671 0.000000 0.000000 0.000000 0.000000])
// FFT([0.135335 0.800737 1.601475 0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([0.135335 1.601475 0.800737 0.000000 0.000000 0.000000 0.000000 0.000000])
// FFT([0.270671 0.800737 0.000000 -0.135335 0.000000 0.000000 0.000000 0.000000])
// FFT([0.135335 0.000000 -0.800737 -0.270671 0.000000 0.000000 0.000000 0.000000])
// FFT([0.000000 -0.800737 -1.601475 -0.135335 0.000000 0.000000 0.000000 0.000000])
}