Files
2026-10-29 17:29:41 +01:00

50 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package calc
import "math"
// Hann modifies seq in place by the Hann window and returns the result.
// See https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
// and https://www.recordingblogs.com/wiki/hann-window for details.
//
// The Hann window is a high-resolution window.
//
// The sequence weights are
//
// w[k] = 0.5*(1 - cos(2*π*k/(N-1))),
//
// for k=0,1,...,N-1 where N is the length of the window.
//
// Spectral leakage parameters: ΔF_0 = 4, ΔF_0.5 = 1.5, K = 2, ɣ_max = -31.5, β = -6.
func Hann(dst, src []float64) {
k := 2 * math.Pi / float64(len(src)-1)
for i := range src {
dst[i] = src[i] * (0.5 * (1 - math.Cos(k*float64(i))))
}
}
// Hamming modifies seq in place by the Hamming window and returns the result.
// See https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
// and https://www.recordingblogs.com/wiki/hamming-window for details.
//
// The Hamming window is a high-resolution window. Among K=2 windows it has
// the highest ɣ_max.
//
// The sequence weights are
//
// w[k] = 25/46 - 21/46 * cos(2*π*k/(N-1)),
//
// for k=0,1,...,N-1 where N is the length of the window.
//
// Spectral leakage parameters: ΔF_0 = 4, ΔF_0.5 = 1.33, K = 2, ɣ_max = -42, β = -5.37.
func Hamming(dst, src []float64) {
const (
a0 = 0.54
a1 = 0.46
)
k := 2 * math.Pi / float64(len(src)-1)
for i := range src {
dst[i] = src[i] * (a0 - a1*math.Cos(k*float64(i)))
}
}