1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| # -*- coding:Utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
def signal( maxi, mini, final, att, nb_per, nb_pts):
t = np.linspace(0, 2*np.pi*nb_per, nb_per*nb_pts)
a = np.log(att) / (2.0*np.pi*nb_per)
y = np.sin(t) * np.exp(-a*t)
y[y>0] *= np.abs(maxi - final)
y[y<0] *= np.abs(final - mini)
return t, y + final
if __name__ == '__main__':
v_final = 20
t, s = signal( maxi=100, mini=0, final=v_final, att=1000, nb_per=20, nb_pts=32)
moy = np.ones_like(s) * np.mean(s)
final = np.ones_like(s) * v_final
plt.plot( t, s, t, moy, t, final)
plt.show() |
Partager