import generador_placa_audio import time # %% tiempo_medicion = 1 sample_rate = 10000 device = 'Dev7' canales = ['ai1', 'ai6'] stream = generador_placa_audio.write(duracion=tiempo_medicion, tipo='random', amplitud=0., f_signal=10, noise=False) time.sleep(0.25) time_vec, med = adquisicion_con_placa.medir(device, canales, sample_rate, tiempo_medicion) stream.stop_stream() plt.plot(time_vec, med[0]) plt.plot(time_vec, med[1]) # %% samples_per_channel = int(sample_rate * tiempo_medicion) with nidaqmx.Task() as task: ai_channel = task.ai_channels.add_ai_voltage_chan( '{}/{}'.format(device, canales[0]), ) task.timing.cfg_samp_clk_timing(sample_rate, samps_per_chan=samples_per_channel) # ai_channel.ai_resolution = 2 print(ai_channel.ai_resolution) # ai_channel.ai
canales = ['ai0'] fungen_perturb.write('output1 on') fungen_control.write('output1 on') fungen_control.write('VOLT % f' % 0.02) fungen_control.write('FREQ % f' % 0.000001) fungen_perturb.write('VOLT:OFFS % f' % 4) fungen_perturb.write('FREQ % f' % 0.000001) #fungen_perturb.write('VOLT % f' % 0.02) #fungen_perturb.write('FREQ % f' % 0.000001) tension_led = np.linspace(0, 8, num=100) tension_fotodiodo = np.zeros_like(tension_led) error_fotodiodo = np.zeros_like(tension_led) for index, offset in enumerate(tension_led): fungen_control.write('VOLT:OFFS % f' % offset) time_vec, med = adquisicion_con_placa.medir(device, canales, sample_rate=1000, duracion=1) tension_fotodiodo[index] = np.mean(med) error_fotodiodo[index] = np.std(med) fungen_control.write('output1 off') fig = plt.figure() ax = fig.add_subplot(111) ax.plot(tension_led, tension_fotodiodo) ax.set_xlabel('Tension led perturbacion (V)') ax.set_ylabel('Tension R fotodiodo (V)') #fig.savefig('calibracion_led-fotodiodo_luzprendida_perturbprendido4V.png') #np.savetxt('calibracion_ledperturbacion-fotodiodo_luzprendida_perturbprendido4V.dat', np.transpose([tension_led, tension_fotodiodo])) # %% #kps = [1, 5, 10, 20, 40, 70, 100] kps = [25, 40]
#min_vals = [-5.0, -0.5, -5.0, -0.5, -5.0, -0.5, -5.0, -5.0] #max_vals = list(-np.array(min_vals)) for canales_a_borrar in range(0,7): canales = ['ai1','ai0','ai7','ai2','ai3','ai4','ai5','ai6'] min_vals = [-5.0, -0.5, -5.0, -0.5, -5.0, -0.5, -5.0, -5.0] max_vals = list(-np.array(min_vals)) if canales_a_borrar < len(canales) - 1: for i in range(canales_a_borrar): canales.pop(1) min_vals.pop(1) max_vals.pop(1) else: raise ValueError('No borrar tantos canales') sample_rate = int(250000/len(canales)) time_vec, med = adquisicion_con_placa.medir(device, canales, sample_rate, tiempo_medicion)#, min_vals = min_vals, max_vals = max_vals) corr = signal.correlate(med[0], med[-1], mode='full') delay = (np.argmax(corr)/sample_rate)%max(time_vec) fig, ax = plt.subplots(1, figsize=(6, 4)) ax.plot(time_vec, med[0], label = 'Canal 1') ax.plot(time_vec, med[-1], label = 'Canal 6') ax.legend() ax.set_title('{} canales, Delay: {}s'.format(len(canales), delay)) fig.tight_layout() # # fname = '{}/freqgen{}Hz_srate{}_{}canales_consaltosdeganancia.dat'.format(folder, frecuencia, sample_rate, len(canales)) # coment = 'Medimos una señal de {}Hz en {} canales a fs {} con saltos de ganancia'.format(frecuencia, len(canales), sample_rate) # if not os.path.isfile(fname): # np.savetxt(fname, np.transpose([time_vec, med[0], med[-1]]), delimiter = ',', header = 'tiempo (s), tension (V)', footer=coment) # fig.savefig('{}/{}Hz_{}canales.png'.format(folder, frecuencia, len(canales)))