blackman_window

Function blackman_window 

pub fn blackman_window<B>(
    size: usize,
    periodic: bool,
    options: impl Into<TensorCreationOptions<B>>,
) -> Tensor<B, 1>
where B: Backend,
Expand description

Creates a 1D Blackman window tensor.

w_n = 0.42 - 0.5 * cos(2πn / N) + 0.08 * cos(4πn / N) where N = size (periodic) or N = size-1 (symmetric)

§Arguments

  • size: Size of the returned 1D window tensor.
  • periodic: If true, the window is treated as periodic (i.e., N = size). If false, the window is symmetric (i.e., N = size - 1).
  • options: Controls the output device and optional dtype. Accepts:
    • &device - uses the device’s default float dtype
    • (&device, DType::F32) - uses an explicit dtype
    • TensorCreationOptions directly for full control.

§Returns

  • A 1D tensor of shape [size] containing the window.

§Notes

  • If size == 0, the function returns an empty tensor.
  • If size == 1, the returned window contains a single value 1.0 which overrides the formula.

§Panics

Panics if size exceeds i64::MAX.

§Example

use burn_tensor::{backend::Backend, DType, signal::blackman_window};

fn example<B: Backend>() {
    // Creating a window with default dtype
    let device = B::Device::default();
    let window_tensor = blackman_window::<B>(5, true, &device);
    // Output: [0.0, 0.20077015, 0.84922993, 0.8492298, 0.2007701]

    // Creating a window with explicit dtype.
    // Note that this does not perform the computation at higher precision but it
    // widens the storage of the returned tensor to F64.
    let device = B::Device::default();
    let window_tensor_f64 = blackman_window::<B>(5, true, (&device, DType::F64));
    // Output: [0.0, 0.20077015, 0.84922993, 0.8492298, 0.2007701]
}