import numpy as np
import matplotlib.pyplot  as plt
f1,f2,f3=2000.,3000.,6000.
Ne=1000
fe=10000.
Te=1/fe
Ta=Te*Ne
C=np.array([1/Ne]+[2/Ne for k in range(Ne//2)])
#C=[1/Ne]
#for i in range (Ne//2): C.append(2/Ne)   ne donne pas un tableau
def s(t):
    return np.cos(2*np.pi*f1*t+np.pi/2)+np.cos(2*np.pi*f2*t-np.pi/3)+0.8*np.cos(2*np.pi*f3*t-np.pi/4)

    
t_ech=np.linspace(0,Ta-Te,Ne)
#t_ech=np.array([n*Te for n in range(Ne)])# marche aussi bien que la ligne précédente
s_ech=s(t_ech)
spec=abs(np.fft.rfft(s_ech)*C)
#speccmplx=np.fft.rfft(s_ech)*C
f=np.fft.rfftfreq(Ne,Te)


#plt.plot (t_ech,s_ech)
plt.figure(1)
plt.plot(f,spec,-0.1,1.2)

plt.show()
