torch.kaiser_window
function kaiser_window(window_length: number, options?: KaiserWindowOptions): Tensorfunction kaiser_window(window_length: number, periodic: boolean, beta: number, options?: KaiserWindowOptions): TensorKaiser window: tunable window with parametric control over frequency/sidelobe tradeoff.
The only window function with a tunable parameter (beta) that lets you dial in the exact frequency resolution vs side lobe suppression trade-off you need. Parametric design makes it supremely flexible. Essential for:
- Custom spectral analysis: Tailor window to your specific frequency requirements
- Signal-dependent processing: Adapt window to signal characteristics
- Research and optimization: Explore frequency/sidelobe trade-offs systematically
- Filter design: Create optimal FIR filters with minimal ripple
- Multi-resolution analysis: Use different beta for different frequency bands
- Educational exploration: Understanding window parameter effects
- Production systems: Best choice when requirements are well-defined
Beta parameter effects:
- β=0: Rectangular window (no taper)
- β=5: ~40 dB side lobe suppression (intermediate)
- β=8.6: ~50 dB side lobe suppression (good)
- β=12.0: ~60 dB side lobe suppression (excellent, default)
- β=15: ~70 dB side lobe suppression (exceptional)
- Higher β = lower side lobes but wider main lobe
Mathematical basis: Uses modified Bessel function I0 for optimal frequency characteristics. Parameterization discovered through rigorous frequency domain analysis.
- Only tunable window: Kaiser is the only common window with a parameter
- Bessel function: Uses I0 (modified Bessel of 1st kind, order 0)
- Beta recommendations: 5-15 for most applications
- Default beta=12: Good default that approximates Blackman performance
- Beta=0 = Rectangular: No tapering, full side lobe leakage
- Main lobe width: Decreases as beta increases (worse resolution)
- Side lobe level: ≈ -20*beta dB (rule of thumb)
- Beta effects: Small changes in beta cause large spectral differences
- Computational cost: Bessel function I0 is more expensive than cosine windows
- Beta too high: Excessively wide main lobe wastes frequency resolution
- Beta too low: Poor side lobe suppression reduces dynamic range
- Periodic vs symmetric: Different formulas; periodic (default) for STFT
Parameters
window_lengthnumber- Size of the window (number of samples)
optionsKaiserWindowOptionsoptional- Kaiser window options: -
beta: Shape parameter controlling side lobe suppression (default: 12.0) - Recommended values: 5-15 (outside this range, use simpler windows) -periodic: If true, uses N+1 in computation (default: true) -dtype: Output data type (default: 'float32') -device: Where to place tensor (default: 'webgpu')
Returns
Tensor– 1D tensor of shape [window_length] with values in [0, 1]Examples
// Default Kaiser window (beta=12.0)
const window = torch.kaiser_window(10);
// [0, 0.198, 0.576, 0.899, 0.988, 0.988, 0.899, 0.576, 0.198, 0]
// Good balance of frequency resolution and side lobe suppression// Tuning side lobe suppression: exploring beta values
const signal = torch.randn(4096);
const betas = [5, 8.6, 12, 15]; // Increasing suppression
for (const b of betas) {
const window = torch.kaiser_window(4096, { beta: b });
const windowed = signal.mul(window);
const spectrum = torch.abs(torch.fft(windowed));
// Plot spectrum to see side lobe level changes with beta
console.log(`Beta=${b}: sidelobe ~${-20*b} dB`);
}// Low beta for better frequency resolution (cost: higher side lobes)
const window_narrow = torch.kaiser_window(2048, { beta: 5 });
// Use when frequencies are close but interference is weak
// Main lobe narrower than blackman, but higher side lobes// High beta for excellent side lobe suppression (cost: worse frequency resolution)
const window_clean = torch.kaiser_window(2048, { beta: 15 });
// Use when interference from far-away frequencies is strong
// Main lobe wider but side lobes at -300 dB (near numerical limits)// Comparing Kaiser with other windows at different beta values
const n = 512;
const windows = {
kaiser_5: torch.kaiser_window(n, { beta: 5 }), // Like Hamming
kaiser_8p6: torch.kaiser_window(n, { beta: 8.6 }), // Between Hamming & Blackman
kaiser_12: torch.kaiser_window(n, { beta: 12 }), // Like Blackman
kaiser_15: torch.kaiser_window(n, { beta: 15 }) // Better than Blackman
};
// Show how kaiser can replicate other windows with appropriate beta// Optimal beta for filter design with specific ripple requirement
const desired_ripple = 50; // dB ripple in passband/stopband
const beta = desired_ripple / 20; // Approximate relationship
const window = torch.kaiser_window(101, { beta }); // FIR filter length
// Use as window for filter coefficients to achieve desired rippleSee Also
- PyTorch torch.kaiser_window(window_length, periodic=True, beta=12.0, dtype=None, layout=torch.strided, device=None, requires_grad=False)
- hann_window - Similar to Kaiser with β≈5
- blackman_window - Similar to Kaiser with β≈12
- hamming_window - Similar to Kaiser with β≈4
- bartlett_window - Simpler triangular alternative (no parameter)