Example #1
0
def calculate_lanczos_kernel(x, a, window):
    """
    Helper function to get the actually used kernel for a specific value of
    a. Useful to analyse the behaviour of different tapers and different values
    of a.

    :type x: :class:`numpy.ndarray`
    :param x: The x values at which to calculate the kernel.
    :type a: int
    :param a: The width of the window in samples on either side.
    :type window: str
    :param window: The window used to multiply the sinc function with. One
        of ``"lanczos"``, ``"hanning"``, ``"blackman"``.

    Returns a dictionary of arrays:

    * ``"full_kernel"``: The tapered sinc function evaluated at samples ``x``.
    * ``"only_sinc"``: The sinc function evaluated at samples ``x``.
    * ``"only_taper"``: The taper function evaluated at samples ``x``.
    """
    window = window.lower()
    if window not in _LANCZOS_KERNEL_MAP:
        msg = "Invalid window. Valid windows: %s" % ", ".join(
            sorted(_LANCZOS_KERNEL_MAP.keys()))
        raise ValueError(msg)

    x = np.require(x, dtype=np.float64)
    y0 = np.zeros(x.shape, dtype=np.float64)
    y1 = np.zeros(x.shape, dtype=np.float64)
    y2 = np.zeros(x.shape, dtype=np.float64)

    clibsignal.calculate_kernel(
        x, y0, len(x), a, 0, _LANCZOS_KERNEL_MAP[window])
    clibsignal.calculate_kernel(
        x, y1, len(x), a, 1, _LANCZOS_KERNEL_MAP[window])
    clibsignal.calculate_kernel(
        x, y2, len(x), a, 2, _LANCZOS_KERNEL_MAP[window])

    ret_val = {
        "full_kernel": y0,
        "only_sinc": y1,
        "only_taper": y2
    }

    return ret_val
Example #2
0
def calculate_lanczos_kernel(x, a, window):
    """
    Helper function to get the actually used kernel for a specific value of
    a. Useful to analyse the behaviour of different tapers and different values
    of a.

    :type x: :class:`numpy.ndarray`
    :param x: The x values at which to calculate the kernel.
    :type a: int
    :param a: The width of the window in samples on either side.
    :type window: str
    :param window: The window used to multiply the sinc function with. One
        of ``"lanczos"``, ``"hanning"``, ``"blackman"``.

    Returns a dictionary of arrays:

    * ``"full_kernel"``: The tapered sinc function evaluated at samples ``x``.
    * ``"only_sinc"``: The sinc function evaluated at samples ``x``.
    * ``"only_taper"``: The taper function evaluated at samples ``x``.
    """
    window = window.lower()
    if window not in _LANCZOS_KERNEL_MAP:
        msg = "Invalid window. Valid windows: %s" % ", ".join(
            sorted(_LANCZOS_KERNEL_MAP.keys()))
        raise ValueError(msg)

    x = np.require(x, dtype=np.float64)
    y0 = np.zeros(x.shape, dtype=np.float64)
    y1 = np.zeros(x.shape, dtype=np.float64)
    y2 = np.zeros(x.shape, dtype=np.float64)

    clibsignal.calculate_kernel(
        x, y0, len(x), a, 0, _LANCZOS_KERNEL_MAP[window])
    clibsignal.calculate_kernel(
        x, y1, len(x), a, 1, _LANCZOS_KERNEL_MAP[window])
    clibsignal.calculate_kernel(
        x, y2, len(x), a, 2, _LANCZOS_KERNEL_MAP[window])

    ret_val = {
        "full_kernel": y0,
        "only_sinc": y1,
        "only_taper": y2
    }

    return ret_val