code: def _construct_fir_filter(
      sfreq, freq, gain, filter_length, phase, fir_window, fir_design
  ):
      """Filter signal using gain control points in the frequency domain.
  
      The filter impulse response is constructed from a Hann window (window
      used in "firwin2" function) to avoid ripples in the frequency response
      (windowing is a smoothing in frequency domain).
  
      If x is multi-dimensional, this operates along the last dimension.
  
      Parameters
      ----------
      sfreq : float
          Sampling rate in Hz.
      freq : 1d array
          Frequency sampling points in Hz.
      gain : 1d array
          Filter gain at frequency sampling points.
          Must be all 0 and 1 for fir_design=="firwin".
      filter_length : int
          Length of the filter to use. Must be odd length if phase == "zero".
      phase : str
          If 'zero', the delay for the filter is compensated (and it must be
          an odd-length symmetric filter). If 'linear', the response is
          uncompensated. If 'zero-double', the filter is applied in the
          forward and reverse directions. If 'minimum', a minimum-phase
          filter will be used.
      fir_window : str
          The window to use in FIR design, can be "hamming" (default),
          "hann", or "blackman".
      fir_design : str
          Can be "firwin2" or "firwin".
  
      Returns
      -------
      h : array
          Filter coefficients.
      """
      assert freq[0] == 0
      if fir_design == "firwin2":
          fir_design = signal.firwin2
      else:
          assert fir_design == "firwin"
          fir_design = partial(_firwin_design, sfreq=sfreq)
      # issue a warning if attenuation is less than this
      min_att_db = 12 if phase == "minimum" else 20
  
      # normalize frequencies
      freq = np.array(freq) / (sfreq / 2.0)
      if freq[0] != 0 or freq[-1] != 1:
          raise ValueError(
              f"freq must start at 0 and end an Nyquist ({sfreq / 2.0}), got {freq}"
          )
      gain = np.array(gain)
  
      # Use overlap-add filter with a fixed length
      N = _check_zero_phase_length(filter_length, phase, gain[-1])
      # construct symmetric (linear phase) filter
      if phase == "minimum":
          h = fir_design(N * 2 - 1, freq, gain, window=fir_window)
          h = signal.minimum_phase(h)
      else:
          h = fir_design(N, freq, gain, window=fir_window)
      assert h.size == N
      att_db, att_freq = _filter_attenuation(h, freq, gain)
      if phase == "zero-double":
          att_db += 6
      if att_db < min_att_db:
          att_freq *= sfreq / 2.0
          warn(
              f"Attenuation at stop frequency {att_freq:0.2f} Hz is only {att_db:0.2f} "
              "dB. Increase filter_length for higher attenuation."
          )
      return h
  
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 8 for calling a global function with example usage: _construct_fir_filter(sfreq, freq, gain, filter_length, phase, fir_window, fir_design) and returns: h