code: def emg_linear_envelope(emg, sampling_rate=1000, freqs=[10, 400], lfreq=4):
      r
      emg = emg_tkeo(emg)
  
      if np.size(freqs) == 2:
          # band-pass filter
          b, a = scipy.signal.butter(2, np.array(freqs)/(sampling_rate/2.), btype = 'bandpass')
          emg = scipy.signal.filtfilt(b, a, emg)
      if np.size(lfreq) == 1:
          # full-wave rectification
          envelope = abs(emg)
          # low-pass Butterworth filter
          b, a = scipy.signal.butter(2, np.array(lfreq)/(sampling_rate/2.), btype = 'low')
          envelope = scipy.signal.filtfilt(b, a, envelope)
  
      return (envelope)
docs: r"""Calculate the linear envelope of a signal.
  
      Parameters
      ----------
      emg : array
          raw EMG signal.
      sampling_rate : int
          Sampling rate (samples/second).
      freqs : list [fc_h, fc_l], optional
              cutoff frequencies for the band-pass filter (in Hz).
      lfreq : number, optional
              cutoff frequency for the low-pass filter (in Hz).
  
      Returns
      -------
      envelope : array
          linear envelope of the signal.
  
      Notes
      -----
  
      *Authors*
  
      - Marcos Duarte
  
  
  
      *See Also*
  
      See this notebook [1]_.
  
      References
      ----------
      .. [1] https://github.com/demotu/BMC/blob/master/notebooks/Electromyography.ipynb