I am trying to teach myself some signal processing and control theory. I'm currently working through THIS tutorial. I've started an ipython notebook to keep my notes in.

Unfortunately, something is wrong with my very first simulation of a simple first-order low pass filter. The differential equation is $$\dot{x} = \omega_0(u-x)$$ where $u(t)$ is a sinusoidal input. My understanding is that this system is described by the transfer function: $$G(s) = \frac{x(s)}{u(s)} = \frac{1}{1+s/\omega_0}$$ I am interested in using this transfer function to calculate the amplitude and phase lag of $x(t)$. To do this, we evaluate $G$ at $s=i\omega$: $$|G(i\omega)| = \frac{|x(t)|}{|u(t)|} = \frac{1}{\sqrt{1+\omega^2/\omega_0^2}}$$ $$\arg G(i\omega) = \text{phase lag} = -\tan^{-1}\frac{\omega}{\omega_0}$$ Are the above equations correct? Is my interpretation of them correct? Because when I numerically simulate the above differential equation in python, I get results that do not agree. Particularly, the blue dots and red dots should line up with the black lines in my plots. In other words, I have been unable to reproduce Fig. 3 in this tutorial

The ode is so simple, I don't see how I could have messed up the simulation. You can see my code in the links above. Thanks in advance for any comments/suggestions. (P.S. I hope I picked the right stackexchange site for this question, let me know if I got it wrong).

Update: I have tried decreasing the time step for the numerical integration routine, but this does not improve the fit. The code is still available at the same url: [Click here for code]

  • $\begingroup$ Your analysis of the magnitude and phase response is correct, I think. I don't know about odeint(), but it seems like you're trying to simulate a continuous-time system with discrete time samples (every 30ms). This is going to cause some errors; what happens if you sample 10 or 100x more densely? (t = np.linspace(0,30,int(1e4))). $\endgroup$
    – dpwe
    Commented Jul 24, 2014 at 17:38
  • $\begingroup$ @dpwe -- Just tried what you suggested and saw little to no change (I even went up to 1e5 samples). Thanks for the thought. Code link is updated above. $\endgroup$ Commented Jul 26, 2014 at 2:23

1 Answer 1


I think, the reason for the difference between both results could be the difference between the angular frequency $\omega=2\pi f$ and the "normal" frequency $f$. That means: In the time domain you have defined the frequency $f$, but after processing you (perhaps?) have interpreted the results as $\omega$.

  • $\begingroup$ That was exactly the problem. Thanks so much. $\endgroup$ Commented Jul 26, 2014 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.