
import numpy as np
import matplotlib.pyplot as plt
from analog_0_1 import Device,AnalogInput,AnalogOutput

device = Device(-1)
device.open()
output = AnalogOutput(device)
analog = AnalogInput(device)
analog.channels([0,1],[5,5])

duree = 0.001
freq = 1/(2*duree)
Ne = 8000
fEchant = freq*Ne
samples = np.zeros(Ne)
samples[Ne//2:Ne] = 1
amp = 0.5
output.waveform(0,samples,freq,amp,periods=1,repeat=1)
longueur = int(2*duree*fEchant)
time = analog.sampling(fEchant,longueur)
analog.analogTrigger(0,amp/2,position=duree*0.5)
output.start(0)
voltage = analog.record()
output.stop(0)
Ve = voltage[0,:]
Vs = voltage[1,:]
plt.figure()
plt.plot(time*1e3,Ve,label="Ve")
plt.plot(time*1e3,Vs,label="Vs")
plt.xlabel("t (ms)",fontsize=16)
plt.ylabel("u (V)",fontsize=16)
plt.legend(loc="upper right",fontsize=16)
plt.ylim(-0.6,0.6)
plt.grid()
plt.show()
            