NxSignal.Windows (NxSignal v0.4.0)

Copy Markdown View Source

Common window functions.

Summary

Functions: Windowing

Bartlett triangular window.

Blackman window.

Hamming window.

Hann window.

Creates a Kaiser window of size window_length.

Rectangular window.

Triangular window.

Functions: Windowing

bartlett(n, opts \\ [])

Bartlett triangular window.

See also: triangular/1

Options

  • :type - the output type for the window. Defaults to {:f, 32}
  • :name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.bartlett(3)
#Nx.Tensor<
  f32[3]
  [0.0, 0.6666667, 0.6666666]
>

blackman(n, opts \\ [])

Blackman window.

Options

  • :is_periodic - If true, produces a periodic window, otherwise produces a symmetric window. Defaults to true
  • :type - the output type for the window. Defaults to {:f, 32}
  • :name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.blackman(5, is_periodic: false)
#Nx.Tensor<
  f32[5]
  [-1.4901161e-8, 0.34000003, 0.99999994, 0.34000003, -1.4901161e-8]
>

iex> NxSignal.Windows.blackman(5, is_periodic: true)
#Nx.Tensor<
  f32[5]
  [-1.4901161e-8, 0.20077012, 0.84922993, 0.84922993, 0.20077012]
>

iex> NxSignal.Windows.blackman(6, is_periodic: true, type: {:f, 32})
#Nx.Tensor<
  f32[6]
  [-1.4901161e-8, 0.13, 0.63, 0.99999994, 0.63, 0.13]
>

hamming(n, opts \\ [])

Hamming window.

Options

  • :is_periodic - If true, produces a periodic window, otherwise produces a symmetric window. Defaults to true
  • :type - the output type for the window. Defaults to {:f, 32}
  • :name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.hamming(5, is_periodic: true)
#Nx.Tensor<
  f32[5]
  [0.08000001, 0.3978522, 0.9121479, 0.9121479, 0.3978522]
>
iex> NxSignal.Windows.hamming(5, is_periodic: false)
#Nx.Tensor<
  f32[5]
  [0.08000001, 0.54, 1.0, 0.54, 0.08000001]
>

hann(n, opts \\ [])

Hann window.

Options

  • :is_periodic - If true, produces a periodic window, otherwise produces a symmetric window. Defaults to true
  • :type - the output type for the window. Defaults to {:f, 32}
  • :name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.hann(5, is_periodic: false)
#Nx.Tensor<
  f32[5]
  [0.0, 0.5, 1.0, 0.5, 0.0]
>
iex> NxSignal.Windows.hann(5, is_periodic: true)
#Nx.Tensor<
  f32[5]
  [0.0, 0.34549153, 0.90450853, 0.90450853, 0.34549153]
>

kaiser(n, opts \\ [])

Creates a Kaiser window of size window_length.

The Kaiser window is a taper formed by using a Bessel function.

Options

  • :is_periodic - If true, produces a periodic window, otherwise produces a symmetric window. Defaults to true
  • :type - the output type for the window. Defaults to {:f, 32}
  • :beta - Shape parameter for the window. As beta increases, the window becomes more focused in frequency domain. Defaults to 12.0.
  • :eps - Epsilon value to avoid division by zero. Defaults to 1.0e-7.
  • :axis_name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.kaiser(4, beta: 12.0, is_periodic: true)
#Nx.Tensor<
  f32[4]
  [5.277619e-5, 0.21566667, 1.0, 0.21566667]
>

iex> NxSignal.Windows.kaiser(5, beta: 12.0, is_periodic: true)
#Nx.Tensor<
  f32[5]
  [5.277619e-5, 0.10171464, 0.792937, 0.792937, 0.10171464]
>

iex> NxSignal.Windows.kaiser(4, beta: 12.0, is_periodic: false)
#Nx.Tensor<
  f32[4]
  [5.277619e-5, 0.5188395, 0.5188395, 5.277619e-5]
>

rectangular(n, opts \\ [])

Rectangular window.

Useful for when no window function should be applied.

Options

  • :type - the output type. Defaults to s64

Examples

iex> NxSignal.Windows.rectangular(5)
#Nx.Tensor<
  s64[5]
  [1, 1, 1, 1, 1]
>

iex> NxSignal.Windows.rectangular(5, type: :f32)
#Nx.Tensor<
  f32[5]
  [1.0, 1.0, 1.0, 1.0, 1.0]
>

triangular(n, opts \\ [])

Triangular window.

See also: bartlett/1

Options

  • :n - The window length. Mandatory option.
  • :type - the output type for the window. Defaults to {:f, 32}
  • :name - the axis name. Defaults to nil

Examples

iex> NxSignal.Windows.triangular(3)
#Nx.Tensor<
  f32[3]
  [0.5, 1.0, 0.5]
>