# Simulation and theory of first-order low pass filter

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]

• 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))). – dpwe Jul 24 '14 at 17:38
• @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. – ahwillia Jul 26 '14 at 2:23

## 1 Answer

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$.

• That was exactly the problem. Thanks so much. – ahwillia Jul 26 '14 at 18:34