code: def _firwin_design(N, freq, gain, window, sfreq):
      """Construct a FIR filter using firwin."""
      assert freq[0] == 0
      assert len(freq) > 1
      assert len(freq) == len(gain)
      assert N % 2 == 1
      h = np.zeros(N)
      prev_freq = freq[-1]
      prev_gain = gain[-1]
      if gain[-1] == 1:
          h[N // 2] = 1  # start with "all up"
      assert prev_gain in (0, 1)
      for this_freq, this_gain in zip(freq[::-1][1:], gain[::-1][1:]):
          assert this_gain in (0, 1)
          if this_gain != prev_gain:
              # Get the correct N to satistify the requested transition bandwidth
              transition = (prev_freq - this_freq) / 2.0
              this_N = int(round(_length_factors[window] / transition))
              this_N += 1 - this_N % 2  # make it odd
              if this_N > N:
                  raise ValueError(
                      f"The requested filter length {N} is too short for the requested "
                      f"{transition * sfreq / 2.0:0.2f} Hz transition band, which "
                      f"requires {this_N} samples"
                  )
              # Construct a lowpass
              this_h = signal.firwin(
                  this_N,
                  (prev_freq + this_freq) / 2.0,
                  window=window,
                  pass_zero=True,
                  fs=freq[-1] * 2,
              )
              assert this_h.shape == (this_N,)
              offset = (N - this_N) // 2
              if this_gain == 0:
                  h[offset : N - offset] -= this_h
              else:
                  h[offset : N - offset] += this_h
          prev_gain = this_gain
          prev_freq = this_freq
      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 7 for calling a global function with example usage: _firwin_design(N, freq, gain, window, sfreq) and returns: h