8.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:24:07.110679+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 330f92c33efc913c |
Windows
Documentation: FftSharp.Windows Module
1. Purpose
This module provides a suite of window functions used in spectral analysis (e.g., before applying the FFT) to mitigate spectral leakage. Each window class implements a specific mathematical formulation to taper the signal at its edges, reducing discontinuities introduced by the finite-length FFT. The classes inherit from an abstract Window base class and implement the IWindow interface, offering a consistent API for generating window coefficients of a given size. These windows are intended for use in signal processing pipelines where accurate frequency-domain representation is required.
2. Public Interface
All window classes are concrete, non-abstract subclasses of Window and implement IWindow. Each defines a public constructor (with optional parameters for tunable windows) and overrides Name, Description, and the protected windowValue(int index, int size) method. The base Window class (not shown in source) is assumed to expose a public method (e.g., Generate(int size)) that populates an array by calling windowValue for each index.
-
BartlettName:"Bartlett–Hann"Description: Triangular (2nd-order B-spline), convolution of two half-sized rectangular windows.windowValue(index, size):1 - |(index - size/2) / (size/2)|
-
CosineName:"Cosine"Description: Simple sine-shaped window (sin(π·i/(N−1))), reaches zero at edges; discouraged for practical use.windowValue(index, size):Math.Sin(index * Math.PI / (size - 1))
-
WelchName:"Welch"Description: Parabolic window, better frequency response than Bartlett below π, but with a distinct bump above π; used for antialiasing/resampling.windowValue(index, size):1 - ((index - (size-1)/2) / ((size-1)/2))²
-
RectangularName:"Rectangular"Description: Boxcar/Dirichlet window (all ones); preserves transients but causes high spectral leakage.windowValue(index, size):1
-
HanningName:"Hanning"Description: Sinusoidal window touching zero at edges; low leakage, good for general use.windowValue(index, size):0.5 - 0.5 * cos(2π·i / size)
-
HammingName:"Hamming"Description: Sinusoidal window not zero at edges; designed to cancel the largest sidelobe.windowValue(index, size):0.54 - 0.46 * cos(2π·i / size)
-
FlatTopName:"FlatTop"Description: Partially negative-valued window; minimal scalloping loss, ideal for amplitude measurement. Inherits fromBlackmanwith fixed coefficients.- Constructor:
FlatTop()callsbase(0.2810639, 0.5208972, 0.1980399) - Uses
Blackman.windowValuewith those coefficients:
A - B·cos(2π·i/size) + C·cos(4π·i/size)
-
BlackmanName:"Blackman"Description: Three-term cosine window; exact coefficients null 3rd/4th sidelobes.- Constructors:
Blackman()— uses default coefficients (A=0.42659071,B=0.49656062,C=0.07684867)Blackman(double a, double b, double c)— custom coefficients
windowValue(index, size):A - B·cos(2π·i/size) + C·cos(4π·i/size)
-
BlackmanHarrisName:"Blackman-Harris"Description: Four-term cosine window; wide main lobe but strong sidelobe suppression.- Constructors:
BlackmanHarris()— uses default coefficients (A=0.35875,B=0.48829,C=0.14128,D=0.01168)BlackmanHarris(double a, double b, double c, double d)— custom coefficients
windowValue(index, size):A - B·cos(2π·i/size) + C·cos(4π·i/size) - D·cos(6π·i/size)
-
TukeyName:"Tukey"Description: Flat center with cosine taper at edges; controlled byAlpha(0–1). Ideal for transient analysis.- Constructors:
Tukey()—Alpha = 0.5Tukey(double alpha = 0.5)
windowValue(index, size):- If
index < edgeSizePointsorindex > size - edgeSizePoints:(1 - cos(index * 2π / (Alpha * size))) / 2 - Else:
1 - Where
edgeSizePoints = (int)(size * Alpha / 2)
- If
-
KaiserName:"Kaiser-Bessel"Description: Tunable viaBeta; balances main lobe width, sidelobe height, and distance.- Constructors:
Kaiser()—Beta = 15Kaiser(double beta)
windowValue(index, size):I0(Beta * sqrt(1 - ((index - (size-1)/2) / ((size-1)/2))²)) / I0(Beta)I0(double x): Modified Bessel function of the first kind (order 0), implemented via piecewise series.
3. Invariants
- All windows are symmetric about
index = (size - 1) / 2. This is evident from the use of(index - center)in all formulas. - Window values are computed for indices
0 ≤ index < size. - For all windows except
Rectangular,windowValue(0, size) == windowValue(size - 1, size). - For
Hanning,Hamming,Blackman,BlackmanHarris, andFlatTop, the window is periodic with periodsizein the cosine argument (i.e.,cos(2π·i/size)). Tukeyuses integer truncation foredgeSizePoints, which may cause asymmetry for oddsizeand non-integersize * Alpha / 2.Kaiserwindow is defined only forsize > 1; division by zero occurs ifsize == 1(sincealpha = (size-1)/2 = 0).
4. Dependencies
- Internal: All classes depend on the abstract base class
Windowand interfaceIWindow(not shown), which define the contract for window generation (e.g., a public method likedouble[] Generate(int size)). - External:
Systemnamespace (forMath,Abs,Cos,Sin,Exp,Sqrt,Pow).FlatTopinherits fromBlackman, reusing itswindowValueimplementation with fixed coefficients.
- Inferred usage: These classes are likely consumed by an FFT processing pipeline (e.g.,
FftSharp.Fftor similar) that applies windowing before forward FFT and/or after inverse FFT.
5. Gotchas
Cosinewindow naming: Despite the class name,windowValuecomputessin(π·i/(N−1)), not a cosine. This is likely intentional (sine is a shifted cosine), but the name may mislead.Bartlettvs. standard Bartlett: The description says "Bartlett–Hann", but the formula matches the standard Bartlett (triangular) window, not the Bartlett–Hann (which combines triangular and cosine terms). This may be a documentation or naming error.Tukeyedge handling: For non-integersize * Alpha / 2,edgeSizePointstruncates, causing asymmetric tapering whensizeis odd andAlphais not tuned to avoid this.Kaiserdivision by zero: Ifsize == 1,alpha = 0, leading to division by zero in((index - alpha) / alpha)². This case is not guarded.FlatTopinheritance:FlatTopinherits fromBlackmanand hardcodes coefficients, butBlackman’s constructor is notprotected, soFlatTopmust callbase(...)explicitly. This tight coupling makesFlatTopinflexible (e.g., no custom coefficients).- Missing
IWindowimplementation: The source does not show theIWindowinterface orWindowbase class, so the exact public API (e.g., method names, return types) is inferred. - No validation of
size: AllwindowValuemethods assumesize > 1. Forsize == 1,WelchandKaiserinvolve division by zero;Tukey’sedgeSizePointsbecomes 0, but the logic may still hold.
None identified beyond the above.