Déphasage de la réponse d'un oscillateur¶

Cette petite animation permet de visualiser une fonction de transfert complexe pour un oscillateur harmonique, et comment sela se traduit par un déphasage visualisé sur la composante réelle.

In [1]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from IPython.display import Image
In [2]:
def gen():
    for ot in np.linspace(0,6*np.pi,100):
        yield f*np.cos(ot), f*np.sin(ot), A*np.cos(ot+phi), A*np.sin(ot+phi), ot
In [3]:
def init():
    axes[0].set_ylim(-2, 2)
    axes[0].set_xlim(-2, 2)
    axes[0].set_xlabel('x')
    axes[0].set_ylabel('y')
    axes[0].set_aspect('equal')
    axes[0].grid()
    
    axes[1].set_ylim(-2, 2)
    axes[1].set_xlim(0, 6*np.pi)
    axes[1].set_xlabel('temps')
    axes[1].grid()
        
    axes[1].legend()
    return linef, lineA, projf, projA, pointf, pointA, exitation, response

def func(data):
    fx, fy, Ax, Ay, ot = data
    fx_.append(fx)
    Ax_.append(Ax)
    ang.append(ot)
    
    exitation.set_data(ang, fx_)
    response.set_data(ang, Ax_)
    linef.set_data([0, fx], [0, fy])
    lineA.set_data([0, Ax], [0, Ay])
    projf.set_data([0, fx], [0.03, 0.03])
    projA.set_data([0, Ax], [-0.03, -0.03])
    pointf.set_data([fx], [fy])
    pointA.set_data([Ax], [Ay])
    return linef, lineA, projf, projA, pointf, pointA, exitation, response
In [4]:
fig, axes = plt.subplots(1,2,figsize=(13,5))
#time_text = axes[0].text(0.05, 0.8, '', transform=axes[0].transAxes)

#Plot layout setup
f = 1.2
A = 1.7
phi = np.pi/6
linef, = axes[0].plot([], [], 'r-', lw=2)
lineA, = axes[0].plot([], [], 'b-', lw=2)
projf, = axes[0].plot([], [], 'r-', lw=3)
projA, = axes[0].plot([], [], 'b-', lw=3)

#circle_line, = axes[0].plot([], [], 'g', lw=3)
pointf, = axes[0].plot([], [], 'ro', ms=5)
pointA, = axes[0].plot([], [], 'bo', ms=5)

exitation, = axes[1].plot([], [], 'r-', lw=3, label='Excitation')
response, = axes[1].plot([], [], 'b-', lw=3, label='Réponse')

circle1 = plt.Circle((0, 0), 1, color='r',fill=False)
axes[0].add_artist(circle1)


fx_, fy_ = [], []
Ax_, Ay_ = [], []
ang = []
    
plt.ioff()

plt.rcParams['animation.html'] = 'html5'

animation = FuncAnimation(fig, func, gen, init_func=init, blit=True, interval=1./18*2500, cache_frame_data=False)

animation
Out[4]:
Your browser does not support the video tag.
No description has been provided for this image
In [ ]: