def bandstop_filter(X, y, sfreq, bandwidth, freqs_to_notch):
    """Apply a band-stop filter with desired bandwidth at the desired frequency
    position.

    Suggested e.g. in [1]_ and [2]_

    Parameters
    ----------
    X : torch.Tensor
        EEG input example or batch.
    y : torch.Tensor
        EEG labels for the example or batch.
    sfreq : float
        Sampling frequency of the signals to be filtered.
    bandwidth : float
        Bandwidth of the filter, i.e. distance between the low and high cut
        frequencies.
    freqs_to_notch : array-like | None
        Array of floats of size ``(batch_size,)`` containing the center of the
        frequency band to filter out for each sample in the batch. Frequencies
        should be greater than ``bandwidth/2 + transition`` and lower than
        ``sfreq/2 - bandwidth/2 - transition`` (where ``transition = 1 Hz``).

    Returns
    -------
    torch.Tensor
        Transformed inputs.
    torch.Tensor
        Transformed labels.

    References
    ----------
    .. [1] Cheng, J. Y., Goh, H., Dogrusoz, K., Tuzel, O., & Azemi, E. (2020).
       Subject-aware contrastive learning for biosignals. arXiv preprint
       arXiv:2007.04871.
    .. [2] Mohsenvand, M. N., Izadi, M. R., & Maes, P. (2020). Contrastive
       Representation Learning for Electroencephalogram Classification. In
       Machine Learning for Health (pp. 238-253). PMLR.
    """
    if bandwidth == 0:
        return X, y
    transformed_X = X.clone()
    for c, (sample, notched_freq) in enumerate(zip(transformed_X, freqs_to_notch)):
        sample = sample.cpu().numpy().astype(np.float64)
        transformed_X[c] = torch.as_tensor(
            notch_filter(
                sample,
                Fs=sfreq,
                freqs=notched_freq,
                method="fir",
                notch_widths=bandwidth,
                verbose=False,
            )
        )
    return transformed_X, y
Apply a band-stop filter with desired bandwidth at the desired frequency
    position.

    Suggested e.g. in [1]_ and [2]_

    Parameters
    ----------
    X : torch.Tensor
        EEG input example or batch.
    y : torch.Tensor
        EEG labels for the example or batch.
    sfreq : float
        Sampling frequency of the signals to be filtered.
    bandwidth : float
        Bandwidth of the filter, i.e. distance between the low and high cut
        frequencies.
    freqs_to_notch : array-like | None
        Array of floats of size ``(batch_size,)`` containing the center of the
        frequency band to filter out for each sample in the batch. Frequencies
        should be greater than ``bandwidth/2 + transition`` and lower than
        ``sfreq/2 - bandwidth/2 - transition`` (where ``transition = 1 Hz``).

    Returns
    -------
    torch.Tensor
        Transformed inputs.
    torch.Tensor
        Transformed labels.

    References
    ----------
    .. [1] Cheng, J. Y., Goh, H., Dogrusoz, K., Tuzel, O., & Azemi, E. (2020).
       Subject-aware contrastive learning for biosignals. arXiv preprint
       arXiv:2007.04871.
    .. [2] Mohsenvand, M. N., Izadi, M. R., & Maes, P. (2020). Contrastive
       Representation Learning for Electroencephalogram Classification. In
       Machine Learning for Health (pp. 238-253). PMLR.
    
braindecode/augmentation/functional.py