From 0d7cf5596d8d6c0bb2cee13b041925d16970b6bb Mon Sep 17 00:00:00 2001 From: Ciro Carandente Date: Fri, 20 Oct 2023 16:23:29 +0200 Subject: [PATCH] feat(gaussian_window): added gaussian window --- lib/stft.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/stft.dart b/lib/stft.dart index d4462e5..2a2e50a 100644 --- a/lib/stft.dart +++ b/lib/stft.dart @@ -120,6 +120,23 @@ extension Window on Float64List { return 0.42 - 0.5 * math.cos(t) + 0.08 * math.cos(2 * t); }); } + + static Float64List gaussian( + int size, { + double alpha = 0.25, + }) { + final res = Float64List(size); + final samplingPeriods = (size - 1) * 0.5; + + // standard deviation is alpha * size/2 + final standardDeviation = (alpha * (size - 1)) * 0.5; + for (int i = 0; i < size; i++) { + final x = -0.5 * math.pow((i - samplingPeriods) / standardDeviation, 2); + res[i] = math.exp(x); + } + + return res; + } } /// Performs STFTs (Short-time Fourier Transforms).