Search code examples
simulationpythonmodeling

Modeling a linear system with Python


I would like to simulate/model a closed-loop, linear, time-invariant system (specifically a locked PLL approximation) with python.

Each sub-block within the model has a known transfer function which is given in terms of complex frequency H(s) = K / ( s * tau + 1 ). Using the model, I would like to see how the system response as well as the noise response is affected as parameters (e.g. the VCO gain) are changed. This would involve using Bode plots and root-locus plots.

How can I do this with Python?


Solution

  • According to http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.bode.html you can now use this:

    from scipy import signal
    import matplotlib.pyplot as plt
    
    s1 = signal.lti([1], [1, 1])
    w, mag, phase = signal.bode(s1)
    
    plt.figure()
    plt.semilogx(w, mag)    # bode magnitude plot
    plt.figure()
    plt.semilogx(w, phase)  # bode phase plot
    plt.show()