code: def notch_filter(
      x,
      Fs,
      freqs,
      filter_length="auto",
      notch_widths=None,
      trans_bandwidth=1,
      method="fir",
      iir_params=None,
      mt_bandwidth=None,
      p_value=0.05,
      picks=None,
      n_jobs=None,
      copy=True,
      phase="zero",
      fir_window="hamming",
      fir_design="firwin",
      pad="reflect_limited",
      *,
      verbose=None,
  ):
      r"""Notch filter for the signal x.
  
      Applies a zero-phase notch filter to the signal x, operating on the last
      dimension.
  
      Parameters
      ----------
      x : array
          Signal to filter.
      Fs : float
          Sampling rate in Hz.
      freqs : float | array of float | None
          Frequencies to notch filter in Hz, e.g. np.arange(60, 241, 60).
          Multiple stop-bands can only be used with method='fir'
          and method='spectrum_fit'. None can only be used with the mode
          'spectrum_fit', where an F test is used to find sinusoidal components.
      %(filter_length_notch)s
      notch_widths : float | array of float | None
          Width of the stop band (centred at each freq in freqs) in Hz.
          If None, freqs / 200 is used.
      trans_bandwidth : float
          Width of the transition band in Hz.
          Only used for ``method='fir'`` and ``method='iir'``.
      %(method_fir)s
          'spectrum_fit' will use multi-taper estimation of sinusoidal
          components. If freqs=None and method='spectrum_fit', significant
          sinusoidal components are detected using an F test, and noted by
          logging.
      %(iir_params)s
      mt_bandwidth : float | None
          The bandwidth of the multitaper windowing function in Hz.
          Only used in 'spectrum_fit' mode.
      p_value : float
          P-value to use in F-test thresholding to determine significant
          sinusoidal components to remove when method='spectrum_fit' and
          freqs=None. Note that this will be Bonferroni corrected for the
          number of frequencies, so large p-values may be justified.
      %(picks_nostr)s
          Only supported for 2D (n_channels, n_times) and 3D
          (n_epochs, n_channels, n_times) data.
      %(n_jobs_fir)s
      copy : bool
          If True, a copy of x, filtered, is returned. Otherwise, it operates
          on x in place.
      %(phase)s
      %(fir_window)s
      %(fir_design)s
      %(pad_fir)s
          The default is ``'reflect_limited'``.
      %(verbose)s
  
      Returns
      -------
      xf : array
          The x array filtered.
  
      See Also
      --------
      filter_data
      resample
  
      Notes
      -----
      The frequency response is (approximately) given by::
  
          1-|----------         -----------
            |          \       /
        |H| |           \     /
            |            \   /
            |             \ /
          0-|              -
            |         |    |    |         |
            0        Fp1 freq  Fp2       Nyq
  
      For each freq in freqs, where ``Fp1 = freq - trans_bandwidth / 2`` and
      ``Fs2 = freq + trans_bandwidth / 2``.
  
      References
      ----------
      Multi-taper removal is inspired by code from the Chronux toolbox, see
      www.chronux.org and the book "Observed Brain Dynamics" by Partha Mitra
      & Hemant Bokil, Oxford University Press, New York, 2008. Please
      cite this in publications if method 'spectrum_fit' is used.
      """
      x = _check_filterable(x, "notch filtered", "notch_filter")
      iir_params, method = _check_method(
          method, iir_params, ["spectrum_fit"]
      )
  
      if freqs is not None:
          freqs = np.atleast_1d(freqs)
      elif method != "spectrum_fit":
          raise ValueError(
              "freqs=None can only be used with method " "spectrum_fit"
          )
  
      # Only have to deal with notch_widths for non-autodetect
      if freqs is not None:
          if notch_widths is None:
              notch_widths = freqs / 200.0
          elif np.any(notch_widths < 0):
              raise ValueError("notch_widths must be >= 0")
          else:
              notch_widths = np.atleast_1d(notch_widths)
              if len(notch_widths) == 1:
                  notch_widths = notch_widths[0] * np.ones_like(freqs)
              elif len(notch_widths) != len(freqs):
                  raise ValueError(
                      "notch_widths must be None, scalar, or the "
                      "same length as freqs"
                  )
  
      if method in ("fir", "iir"):
          # Speed this up by computing the fourier coefficients once
          tb_2 = trans_bandwidth / 2.0
          lows = [
              freq - nw / 2.0 - tb_2
              for freq, nw in zip(freqs, notch_widths)
          ]
          highs = [
              freq + nw / 2.0 + tb_2
              for freq, nw in zip(freqs, notch_widths)
          ]
          xf = filter_data(
              x,
              Fs,
              highs,
              lows,
              picks,
              filter_length,
              tb_2,
              tb_2,
              n_jobs,
              method,
              iir_params,
              copy,
              phase,
              fir_window,
              fir_design,
              pad=pad,
          )
      elif method == "spectrum_fit":
          xf = _mt_spectrum_proc(
              x,
              Fs,
              freqs,
              notch_widths,
              mt_bandwidth,
              p_value,
              picks,
              n_jobs,
              copy,
              filter_length,
          )
  
      return xf
  
imports: from collections import Counter
  from copy import deepcopy
  from functools import partial
  from math import gcd
  import numpy
  from scipy import fft, signal
  from scipy.stats import f
  from ._fiff.pick import _picks_to_idx
  from ._ola import _COLA
  from .cuda import _fft_multiply_repeated, _fft_resample, _setup_cuda_fft_multiply_repeated, _setup_cuda_fft_resample, _smart_pad
  from .parallel import parallel_func
  from .utils import _check_option, _check_preload, _ensure_int, _pl, _validate_type, logger, sum_squared, verbose, warn
label_desc: Use image node_id 17 for calling a global function with example usage: notch_filter(x, Fs, freqs, filter_length, notch_widths, trans_bandwidth, method, iir_params, mt_bandwidth, p_value, picks, n_jobs, copy, phase, fir_window, fir_design, pad) and returns: xf