import matplotlib.pyplot as plt import numpy as np from utils.pico_utils import open_pico, configure_channel, configure_sampling, getData ps = open_pico() configure_channel(ps, 'A') configure_channel(ps, 'B') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 1) dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') ps.stop() ps.close() dataTimeAxis = np.arange(nSamples) * sampling_interval # Uncomment following for call to .show() to not block # plt.ion() fig, ax = plt.subplots() ax.plot(dataTimeAxis, dataA, label="A") ax.plot(dataTimeAxis, dataB, label="B") # ax.grid(True, which='major') ax.set_title("Picoscope 2000 waveforms") ax.set_ylabel("Voltage (V)") ax.set_xlabel("Time (ms)") ax.legend() plt.show()
fout = open(data_dir + name_root + '_wv.csv', 'w') # send cuty cycle to arduino print("Sending stuff to ARDUINO") send_command(duty_cycle=pwm) # fire up the scope print("\n\n") ps = open_pico() configure_channel(ps, 'A') configure_channel(ps, 'B') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 1.0 / frequency, multiplicity=mult) t = np.linspace(0, sampling_interval * nSamples, num=nSamples) plt.ion() fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12, 8)) set_as_time(ax, fontsize=fontsize) for i in range(numRuns): dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') fout.write('run %d\n' % i) fout.write('A\n' + ', '.join(map(str, dataA)) + '\n\n') fout.write('B\n' + ', '.join(map(str, dataB)) + '\n\n')
phase_diff = float(raw_input('Enter phase difference (deg): ')) nRuns = int(raw_input('Number of runs: ')) half_p_us = 5e5 / frequency # in microseconds # send half-period to arduino print("Sending to ARDUINO") send_command(half_p=half_p_us, phase_diff=phase_diff) # set up scope print("\n\n") ps = open_pico() configure_channel(ps, 'A') configure_channel(ps, 'B') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 2 * half_p_us / 1e6) # initialise the x axes t = np.linspace(0, nSamples * sampling_interval, num=nSamples) freqs = np.fft.fftfreq(nSamples, sampling_interval) # set up plot -- does not work atm fig, [ax1, ax2] = plt.subplots(ncols=1, nrows=2) va_line, = ax1.plot(t, np.zeros(nSamples)) vb_line, = ax1.plot(t, np.zeros(nSamples)) f_line, = ax2.plot(freqs, np.zeros(len(freqs))) plt.draw() for i in range(nRuns): dataA = getData(ps, nSamples, channel='A') # do the FT
name_root = def_input('Filename root:', default='deg') fout = open(data_dir+name_root+'_wv.csv', 'w') # send half-period to arduino print("Sending stuff to ARDUINO") send_command(half_p=half_p_us) # fire up the scope print("\n\n") ps = open_pico() configure_channel(ps, 'A') configure_channel(ps, 'B') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 2*half_p_us/1e6, multiplicity=mult) t = np.linspace(0, sampling_interval*nSamples, num=nSamples) for phase in phase_diffs: send_command(phase_diff=phase) sleep(1) dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') fout.write('phase difference = %d deg\n' % phase) fout.write('A\n' + ', '.join(map(str, dataA)) + '\n\n') fout.write('B\n' + ', '.join(map(str, dataB)) + '\n\n') # # do the FT # spectrum = np.fft.fft(np.array(dataA), nSamples)
mult = int(def_input('Number of cycles', default=10)) half_p_us = 5e5 / frequency # in microseconds # send half-period to arduino print("Sending stuff to ARDUINO") send_command(half_p=half_p_us, phase_diff=phase_diff) # read signal print("\n\n") ps = open_pico() configure_channel(ps, 'A') configure_channel(ps, 'B') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 2 * half_p_us / 1e6, multiplicity=mult) dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') ps.stop() ps.close() # do the FT spectrum = np.fft.fft(np.array(dataA), nSamples) spectrumB = np.fft.fft(np.array(dataB), nSamples) freqs = np.fft.fftfreq(nSamples, sampling_interval) print("FrequencyA = %f Hz" % calc_frequency(freqs, spectrum)) print("FrequencyB = %f Hz" % calc_frequency(freqs, spectrumB)) # plot the real signal
pwm_vals = np.arange(0, 255, step_size) # voltages = np.linspace(0.05, 5, num=100) data_dir = def_input('Data directory', default='data/pwm/') name_root = def_input('Filename root', default='pwm') fout = open(data_dir + name_root + '.tsv', 'w') wvout = open('%swaveforms/%s_wv.csv' % (data_dir, name_root), 'w') fout.write('expected V\tf_A (Hz)\tV_A\tsigma_V_A\tf_B (Hz)\tV_B\tsigma_V_B\n') # fire up the scope ps = open_pico() configure_channel(ps, 'A') ps.setSimpleTrigger('A', 1.0, 'Falling', timeout_ms=100, enabled=True) (sampling_interval, nSamples, maxSamples) = configure_sampling(ps, 1.0/frequency, multiplicity=mult) # set up the plot plt.ion() fig, [ax, ax1] = plt.subplots(nrows=2, ncols=1, figsize=(12,9)) set_as_time(ax, fontsize=fontsize) set_as_freq(ax1, fontsize=fontsize) ax.set_ylim(top=7, bottom=-2) ax1.set_xlim(left=-4*frequency, right=4*frequency) ax1.set_ylim(top=1e4, bottom=-10) # make default plots t = np.linspace(0, sampling_interval*nSamples, num=nSamples) freqs = np.fft.fftfreq(nSamples, sampling_interval) dataA = np.zeros(len(t))