Skip to content

Impulse

timecave.data_generation.time_series_functions.scaled_unit_impulse_function_ts(number_samples, idx, constant=1)

Generate time series array based on a scaled unit impulse function with specified index.

This function creates a binary indicator time series array of given length where only the sample at the specified index is marked as 1 and the rest as 0. The binary array is then scaled by a constant factor.

Parameters:

Name Type Description Default
number_samples int

The total number of samples in the time series array.

required
idx int

The index at which the impulse occurs, marked as 1.

required
constant float

A scaling constant to multiply the array by.

1

Returns:

Type Description
ndarray

A scaled time series array where only the sample at the specified index is marked as 1 and the rest as 0.

Examples:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from timecave.data_generation.time_series_functions import scaled_unit_impulse_function_ts
>>> ts = scaled_unit_impulse_function_ts(1000, 250, 20);
>>> _ = plt.plot(np.arange(0, ts.shape[0]), ts);
>>> plt.show();

impulse

Source code in timecave/data_generation/time_series_functions.py
def scaled_unit_impulse_function_ts(
    number_samples: int, idx: int, constant: float = 1
) -> np.ndarray:
    """
    Generate time series array based on a scaled unit impulse function with specified index.

    This function creates a binary indicator time series array of given length where
    only the sample at the specified index is marked as 1 and the rest as 0.
    The binary array is then scaled by a constant factor.

    Parameters
    ----------
    number_samples : int
        The total number of samples in the time series array.

    idx : int
        The index at which the impulse occurs, marked as 1.

    constant : float, default=1
        A scaling constant to multiply the array by.

    Returns
    -------
    np.ndarray
        A scaled time series array where only the sample at the specified index is marked as 1 and the rest as 0.

    Examples
    --------
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from timecave.data_generation.time_series_functions import scaled_unit_impulse_function_ts
    >>> ts = scaled_unit_impulse_function_ts(1000, 250, 20);
    >>> _ = plt.plot(np.arange(0, ts.shape[0]), ts);
    >>> plt.show();

    ![impulse](../../../images/Impulse.png)
    """
    _check_number_samples(number_samples)
    return constant * indicator_ts(number_samples, idx, idx)