Browse Source

Window: periodic versions of Hamming, Hann, Cosine and Lanczos windows

pull/445/head
Christoph Ruegg 10 years ago
parent
commit
de174200ea
  1. 71
      src/Numerics/Window.cs

71
src/Numerics/Window.cs

@ -35,6 +35,7 @@ namespace MathNet.Numerics
{
/// <summary>
/// Hamming window. Named after Richard Hamming.
/// Symmetric version, useful e.g. for filter design purposes.
/// </summary>
public static double[] Hamming(int width)
{
@ -51,8 +52,28 @@ namespace MathNet.Numerics
return w;
}
/// <summary>
/// Hamming window. Named after Richard Hamming.
/// Periodic version, useful e.g. for FFT purposes.
/// </summary>
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;
}
/// <summary>
/// Hann window. Named after Julius von Hann.
/// Symmetric version, useful e.g. for filter design purposes.
/// </summary>
public static double[] Hann(int width)
{
@ -66,8 +87,25 @@ namespace MathNet.Numerics
return w;
}
/// <summary>
/// Hann window. Named after Julius von Hann.
/// Periodic version, useful e.g. for FFT purposes.
/// </summary>
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;
}
/// <summary>
/// Cosine window.
/// Symmetric version, useful e.g. for filter design purposes.
/// </summary>
public static double[] Cosine(int width)
{
@ -81,8 +119,25 @@ namespace MathNet.Numerics
return w;
}
/// <summary>
/// Cosine window.
/// Periodic version, useful e.g. for FFT purposes.
/// </summary>
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;
}
/// <summary>
/// Lanczos window.
/// Symmetric version, useful e.g. for filter design purposes.
/// </summary>
public static double[] Lanczos(int width)
{
@ -96,6 +151,22 @@ namespace MathNet.Numerics
return w;
}
/// <summary>
/// Lanczos window.
/// Periodic version, useful e.g. for FFT purposes.
/// </summary>
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;
}
/// <summary>
/// Gauss window.
/// </summary>

Loading…
Cancel
Save