From de174200ea9ae88f66b1a190b79b79e2e9deb5c4 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Tue, 25 Oct 2016 08:03:38 +0200 Subject: [PATCH] Window: periodic versions of Hamming, Hann, Cosine and Lanczos windows --- src/Numerics/Window.cs | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/Numerics/Window.cs b/src/Numerics/Window.cs index 3eb237ea..13bf6fb2 100644 --- a/src/Numerics/Window.cs +++ b/src/Numerics/Window.cs @@ -35,6 +35,7 @@ namespace MathNet.Numerics { /// /// Hamming window. Named after Richard Hamming. + /// Symmetric version, useful e.g. for filter design purposes. /// public static double[] Hamming(int width) { @@ -51,8 +52,28 @@ namespace MathNet.Numerics return w; } + /// + /// Hamming window. Named after Richard Hamming. + /// Periodic version, useful e.g. for FFT purposes. + /// + public static double[] HammingPeriodic(int width) + { + const double a = 0.53836; + const double b = -0.46164; + + double phaseStep = (2.0*Math.PI)/width; + + var w = new double[width]; + for (int i = 0; i < w.Length; i++) + { + w[i] = a + b*Math.Cos(i*phaseStep); + } + return w; + } + /// /// Hann window. Named after Julius von Hann. + /// Symmetric version, useful e.g. for filter design purposes. /// public static double[] Hann(int width) { @@ -66,8 +87,25 @@ namespace MathNet.Numerics return w; } + /// + /// Hann window. Named after Julius von Hann. + /// Periodic version, useful e.g. for FFT purposes. + /// + public static double[] HannPeriodic(int width) + { + double phaseStep = (2.0*Math.PI)/width; + + var w = new double[width]; + for (int i = 0; i < w.Length; i++) + { + w[i] = 0.5 - 0.5*Math.Cos(i*phaseStep); + } + return w; + } + /// /// Cosine window. + /// Symmetric version, useful e.g. for filter design purposes. /// public static double[] Cosine(int width) { @@ -81,8 +119,25 @@ namespace MathNet.Numerics return w; } + /// + /// Cosine window. + /// Periodic version, useful e.g. for FFT purposes. + /// + public static double[] CosinePeriodic(int width) + { + double phaseStep = Math.PI/width; + + var w = new double[width]; + for (int i = 0; i < w.Length; i++) + { + w[i] = Math.Sin(i*phaseStep); + } + return w; + } + /// /// Lanczos window. + /// Symmetric version, useful e.g. for filter design purposes. /// public static double[] Lanczos(int width) { @@ -96,6 +151,22 @@ namespace MathNet.Numerics return w; } + /// + /// Lanczos window. + /// Periodic version, useful e.g. for FFT purposes. + /// + public static double[] LanczosPeriodic(int width) + { + double phaseStep = 2.0/width; + + var w = new double[width]; + for (int i = 0; i < w.Length; i++) + { + w[i] = Trig.Sinc(i*phaseStep - 1.0); + } + return w; + } + /// /// Gauss window. ///