import numpy as np import matplotlib.pyplot as plt # on fabrique un signal sinusoïdal exponentiellement amorti tau = 10. f0 = 1. omega0 = 2*np.pi*f0 t = np.arange(0.,50.,0.01) x = np.sin(omega0*t)*np.exp(-t/tau) # on l'affiche plt.figure() plt.plot(t,x) plt.xlabel("t") plt.ylabel("x") plt.show() # on calcule la transformée de Fourier, puis le spectre tf = np.fft.fft(x) f = np.fft.fftfreq(n=t.shape[-1], d=np.mean(np.diff(t))) psd = np.square(np.abs(tf)) psdn = psd/psd.max() # on affiche le spectre plt.figure() plt.plot(f, psdn) plt.xlabel("f") plt.ylabel("TF[x]") plt.xlim(0.,2.) plt.show()