for i in range(numRuns): # take data dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') mean_A = np.mean(dataA) mean_B = np.mean(dataB) # save waveforms wvout.write('A\n' + ', '.join(map(str, dataA)) + '\n\n') wvout.write('B\n' + ', '.join(map(str, dataB)) + '\n\n') # do the FT spectrumA = np.fft.fft(np.array(dataA), nSamples) spectrumB = np.fft.fft(np.array(dataB), nSamples) freqs = np.fft.fftfreq(nSamples, sampling_interval) f_B = calc_frequency(freqs, spectrumB) f_A = calc_frequency(freqs, spectrumA) print("FrequencyA = %f Hz" % f_A) print("FrequencyB = %f Hz" % f_B) # save the datapoint fout.write( '{f_in:.4f}\t{mean_A:.5f}\t{f_A:.4f}\t{mean_B:.5f}\t{f_B:.4f}\n'. format(f_in=freq, mean_A=mean_A, f_A=f_A, mean_B=mean_B, f_B=f_B)) # plot the real signal while ax.lines: ax.lines.pop() ax.plot(t, dataA, label='A', color='C0') ax.plot(t, dataB, label='B', color='C1')
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 spectrum = np.fft.fft(np.array(dataA), nSamples) fhz = calc_frequency(freqs, spectrum) print('Frequency: %f Hz' % fhz) va_line.set_ydata(dataA) f_line.set_ydata(abs(spectrum)) plt.draw() ps.stop() ps.close() plt.show()
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 t = np.linspace(0, sampling_interval * nSamples, num=nSamples) fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12, 8)) set_as_time(ax, fontsize=fontsize) ax.plot(t, dataA, label='A') ax.plot(t, dataB, label='B') ax.legend(fontsize=fontsize) # plot the FT'ed signal # set_as_freq(ax1) # ax1.plot(freqs, abs(spectrum), label='A') # ax1.plot(freqs, abs(spectrumB), label='B')
from utils.analysis_utils import calc_frequency import matplotlib.pyplot as plt import numpy as np with open('data/fourier.csv') as fin: lines = fin.readlines() lines = [[float(x) for x in line.split(',')] for line in lines] data = zip(*lines) freqs = list(data[0]) spectrum = list(data[1]) print(freqs[0:6]) print(spectrum[0:6]) print('Frequency = %f Hz' % calc_frequency(freqs, spectrum)) # frequency(freqs, spectrum)
# read signal dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') # replot lineA.set_ydata(dataA) lineB.set_ydata(dataB) plt.pause(0.01) # save the output waveforms wvout.write(', '.join(map(str, dataB)) + '\n') # measure the frequency of A spectrum = np.fft.fft(np.array(dataA), nSamples) freqs = np.fft.fftfreq(nSamples, sampling_interval) f_measured = calc_frequency(freqs, spectrum) # measure the means meanA = np.mean(dataA) meanB = np.mean(dataB) at_this_phase.append(meanB) # save the processed data print('FrequencyA = %f Hz;\tmeanA = %f V;\tmeanB = %f V' % (f_measured, meanA, meanB)) fout.write('%d\t%.5f\t%d\t%.5f\t%.5f\t%.5f\n' % ((fid * len(phase_shifts) + phid) * numRuns + run, f, phase, f_measured, meanA, meanB)) # output results at this phase mean_at_this_phase = np.mean(at_this_phase)
# do the runs for run in range(nRuns): # measure dataA = getData(ps, nSamples, channel='A') dataB = getData(ps, nSamples, channel='B') meanA = np.mean(dataA) meanB = np.mean(dataB) sigA = np.std(dataA) sigB = np.std(dataB) # do the FT spectrumA = np.fft.fft(np.array(dataA), nSamples) spectrumB = np.fft.fft(np.array(dataB), nSamples) freqA = calc_frequency(freqs, spectrumA) freqB = calc_frequency(freqs, spectrumB) print("FrequencyA = %.4e Hz;\tv_A = %f +/- %f V" % (freqA, meanA, sigA)) print("FrequencyB = %.4e Hz;\tv_B = %f +/- %f V" % (freqB, meanB, sigB)) fout.write('%.3f\t%.4f\t%.5f\t%.5f\t%.4f\t%.5f\t%.5f\n' % (v, freqA, meanA, sigA, freqB, meanB, sigB)) wvout.write('expected voltage = %.3f V\n' % v) wvout.write('A\n' + ', '.join(map(str, dataA)) + '\n\n') wvout.write('B\n' + ', '.join(map(str, dataB)) + '\n\n') # replot realtime lineA.set_ydata(dataA) lineB.set_ydata(dataB) specA.set_ydata(spectrumA) specB.set_ydata(spectrumB) plt.pause(0.01)