torch.blackman_window
function blackman_window(window_length: number, options?: WindowOptions): Tensorfunction blackman_window(window_length: number, periodic: boolean, options?: WindowOptions): TensorBlackman window: excellent side lobe suppression at cost of wider main lobe.
Uses three cosine terms to achieve outstanding side lobe rejection (-58 dB). Best choice when spectral leakage is critical. Essential for:
- High-precision spectral analysis: Detecting weak signals near strong ones
- Audio mastering: Analyzing frequency content without leakage artifacts
- Biomedical signals: ECG, EEG with minimal cross-talk between frequencies
- Scientific measurements: Experimental data with unknown frequency content
- Sonar/radar: Detecting weak targets in presence of strong reflections
- Seismic analysis: Earthquake/vibration monitoring with high precision
- Astronomy: Detecting weak periodic signals in stellar observations
Blackman vs Others:
- Main lobe: Wider than Hann/Hamming (~6π/N vs ~4π/N)
- Side lobes: Much lower (-58 dB vs -32 dB for Hann)
- Choose Blackman when you need side lobe suppression more than frequency resolution
- Excellent side lobe suppression: -58 dB (vs -32 dB for Hann)
- Wider main lobe: ~6π/N (vs ~4π/N for Hann) - trade-off for better suppression
- Zero endpoints: Like Hann, reaches zero at both ends
- Three-term window: Uses three cosine terms (hence lower/slower decay)
- Smoothly tapered: Very gradual taper from center to edges
- Peak value: 1.0 at the center
- Wider main lobe: Frequencies closer than ~6π/N may not resolve
- Larger DC amplitude loss: Window reduces signal more than Hann
- Computational cost: Three cosine terms (vs one for Hann)
- Not always optimal: For weak signals, frequency resolution may matter more
Parameters
window_lengthnumber- Size of the window (number of samples)
optionsWindowOptionsoptional- Window options: -
periodic: If true, uses N in denominator (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
// Basic Blackman window
const window = torch.blackman_window(10);
// [0, 0.02, 0.199, 0.62, 0.98, 0.98, 0.62, 0.199, 0.02, 0]
// Note: zero endpoints and broader taper than Hann// High-precision spectral analysis: weak signal detection
const signal = torch.zeros(4096);
// Add weak signal at 500Hz
signal.add_(torch.sin(torch.arange(0, 4096) * 2 * Math.PI * 500 / 4096) * 0.01);
// Add strong interference at 1000Hz
signal.add_(torch.sin(torch.arange(0, 4096) * 2 * Math.PI * 1000 / 4096));
const blackman = torch.blackman_window(4096);
const windowed = signal.mul(blackman);
const spectrum = torch.abs(torch.fft(windowed));
// Blackman suppresses leakage from 1000Hz interference into 500Hz bin// Audio mastering: detecting subtle harmonics
const audio = torch.randn(65536); // Audio sample
const window = torch.blackman_window(65536);
const windowed = audio.mul(window);
const spectrum = torch.abs(torch.fft(windowed));
// Clean spectrum without leakage artifacts// Comparing frequency resolution vs side lobe trade-off
const freq_content = torch.sin(torch.arange(0, 4096) * 2 * Math.PI * 100 / 4096);
const windows = {
hann: torch.hann_window(4096),
hamming: torch.hamming_window(4096),
blackman: torch.blackman_window(4096)
};
// Blackman has widest peak (lower resolution) but lowest side lobes
for (const [name, w] of Object.entries(windows)) {
const windowed = freq_content.mul(w);
const spectrum = torch.abs(torch.fft(windowed));
// Plot to visualize resolution vs suppression trade-off
}// Seismic data analysis: detecting weak earthquakes
const seismic_trace = torch.randn(200000); // Seismic recording
const blackman = torch.blackman_window(200000, { periodic: true });
const processed = seismic_trace.mul(blackman);
// Minimal spectral leakage allows detection of small magnitude eventsSee Also
- PyTorch torch.blackman_window(window_length, periodic=True, dtype=None, layout=torch.strided, device=None, requires_grad=False)
- hann_window - Compromise between Hamming and Blackman
- hamming_window - Sharper peak, higher side lobes
- bartlett_window - Simpler triangular alternative
- kaiser_window - Tunable for custom frequency/sidelobe trade-off