title: How to implement continuous time high/low pass filter in python?
body: <p>I have a application that recieves incoming signals with a fixed frequency. I have been trying to implement a filter for this incoming signal without having to save N timesteps and performing a filtering-function on that. What I would like to do is akin to a one-dimensional Kalman filter where I update my current state with the new observation. I am no mathematician, and thus the Wikipedia pages regarding if this is possible is completely impenetrable to me. Furthermore, the StackOverflow answers (I've found) in this domain only regards if you have a section of N timesteps of signal available and how to perform a filtering on that, and such filtering I can do without a problem.</p>
  
  <p>I've provided some dummy code below that illustrates the types of functions I have been trying to write. </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  def high_pass(new, previous, cutoff=20):
      # Howto?
      return 0
  
  def low_pass(new, previous, cutofff=20):
      # Howto?
      return 0
  
  def continuous_filter(vs):
      prev_highpass, prev_lowpass = 0, 0
      for v in vs:
          prev_highpass = high_pass(v, prev_highpass)
          prev_lowpass = low_pass(v, prev_lowpass)
          yield prev_highpass, prev_lowpass
  
  
  np.random.seed(21)
  sec_duration = 10.0
  time_resolution = 1e3
  dt = 1/time_resolution
  steps = int(sec_duration * time_resolution)
  signal = np.sum([np.sin(np.linspace(0, np.random.randint(10, 100), steps)) * np.random.random() for _ in range(3)], axis=0)
  
  filt_signals = np.array([[high, low] for high, low in continuous_filter(signal)])
  
  plt.plot(signal, label="Input signal")
  plt.plot(filt_signals[:, 0], label="High-pass")
  plt.plot(filt_signals[:, 1], label="Low pass")
  plt.legend()
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XGxlz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XGxlz.png" alt="enter image description here"></a></p>
  
  <p>Anyone that can tell me if it is possible? I have been looking at the SciPy <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.TransferFunction.html" rel="nofollow noreferrer">documentation</a> but I dont understand it.</p>