def triangleWave2(center=0 * V, amplitude=1 * V, frequency=10 * Hz, steps=30, loopForever=True, withTimer=False, DAC=SQUID): """Generate a triangle waveform, suitable for looping.""" steplen = (1 / frequency) / 4 / steps voltages = linspace(center, center + amplitude, steps)\ + linspace(center + amplitude, center - amplitude, steps*2)\ + linspace(center - amplitude, center, steps) cmds = [[setDACvoltage2(DAC, 1, v), delay(steplen)] for v in voltages] seq = [ START, #switchDAC(DAC, 1, slow=True), delay(10*us), cmds, #switchDAC(DAC, 1), delay(10*us), ] if withTimer: seq.extend([INIT_TIMER, STOP_TIMER]) if not loopForever: seq.append(END) return flatten(seq)
def triangleWave( center=0 * V, amplitude=1 * V, frequency=250 * Hz, steps=30, loopForever=True, withTimer=False, DAC=SQUID ): """Generate a triangle waveform, suitable for looping.""" steplen = (1 / frequency) / 4 / steps voltages = ( linspace(center, center + amplitude, steps) + linspace(center + amplitude, center - amplitude, steps * 2) + linspace(center - amplitude, center, steps) ) cmds = [[setDACvoltage2(DAC, 1, v), delay(steplen)] for v in voltages] seq = [START, switchDAC(DAC, 1, slow=True), delay(10 * us), cmds, switchDAC(DAC, 1), delay(10 * us)] if withTimer: seq.extend([INIT_TIMER, STOP_TIMER]) if not loopForever: seq.append(END) return flatten(seq)
def freq_sweep_save(self, c, name='untitled'): """Initiate a frequency sweep. The data will be saved to the data vault in the current directory for this context. Note that the default directory in the data vault is the root directory, so you should cd before trying to save. """ dev = self.selectedDevice(c) resp = yield dev.query('SENS:FREQ:STAR?; STOP?') fstar, fstop = [float(f) for f in resp.split(';')] sweeptime, npoints = yield self.startSweep(dev, 'LIN') if sweeptime > 1: sweeptime *= self.sweepFactor(c) yield util.wakeupCall(sweeptime) sparams = yield self.getSweepData(dev, c['meas']) freq = util.linspace(fstar, fstop, npoints) freq = [T.Value(f, 'Hz') for f in freq] for s in sparams: for i, cplx in enumerate(s): s[i] = T.Complex(cplx) f = numpy.array(freq) s = 20 * numpy.log10(abs(numpy.array(sparams))) phases = numpy.angle(numpy.array(sparams)) data = numpy.vstack((f, s, phases)).T data = data.astype('float64') dv = self.client.data_vault power = yield self.power(c) bw = yield self.bandwidth(c) independents = ['frequency [Hz]'] dependents = [(Sij, 'log mag', 'dB') for Sij in c['meas']] + [(Sij, 'phase', 'dB') for Sij in c['meas']] p = dv.packet() p.new(name, independents, dependents) p.add(data) p.add_comment('Autosaved by PNA server.') p.add_parameter('power', power) p.add_parameter('bandwidth', bw) yield p.send(context=c.ID) returnValue(data)
def power_sweep_phase(self, c): """Initiate a power sweep.""" dev = self.selectedDevice(c) resp = yield dev.query('SOUR:POW:STAR?; STOP?') pstar, pstop = [float(p) for p in resp.split(';')] sweeptime, npoints = yield self.startSweep(dev, 'POW') if sweeptime > 1: sweeptime *= self.sweepFactor(c) yield util.wakeupCall(sweeptime) power = util.linspace(pstar, pstop, npoints) power = [T.Value(p, 'dBm') for p in power] phase = yield self.getSweepDataPhase(dev, c['meas']) returnValue((power, phase))
def freq_sweep_save(self, c, name='untitled'): """Initiate a frequency sweep. The data will be saved to the data vault in the current directory for this context. Note that the default directory in the data vault is the root directory, so you should cd before trying to save. """ dev = self.selectedDevice(c) resp = yield dev.query('SENS:FREQ:STAR?; STOP?') fstar, fstop = [float(f) for f in resp.split(';')] sweeptime, npoints = yield self.startSweep(dev, 'LIN') if sweeptime > 1: sweeptime *= self.sweepFactor(c) yield util.wakeupCall(sweeptime) sparams = yield self.getSweepData(dev, c['meas']) freq = util.linspace(fstar, fstop, npoints) freq = [T.Value(f, 'Hz') for f in freq] for s in sparams: for i, cplx in enumerate(s): s[i] = T.Complex(cplx) f = numpy.array(freq) s = 20*numpy.log10(abs(numpy.array(sparams))) phases = numpy.angle(numpy.array(sparams)) data = numpy.vstack((f, s, phases)).T data = data.astype('float64') dv = self.client.data_vault power = yield self.power(c) bw = yield self.bandwidth(c) independents = ['frequency [Hz]'] dependents = [(Sij, 'log mag', 'dB') for Sij in c['meas']]+[(Sij, 'phase', 'dB') for Sij in c['meas']] p = dv.packet() p.new(name, independents, dependents) p.add(data) p.add_comment('Autosaved by PNA server.') p.add_parameter('power', power) p.add_parameter('bandwidth', bw) yield p.send(context=c.ID) returnValue(data)
def power_sweep(self, c): """Initiate a power sweep.""" dev = self.selectedDevice(c) resp = yield dev.query('SOUR:POW:STAR?; STOP?') pstar, pstop = [float(p) for p in resp.split(';')] sweeptime, npoints = yield self.startSweep(dev, 'POW') if sweeptime > 1: sweeptime *= self.sweepFactor(c) yield util.wakeupCall(sweeptime) sparams = yield self.getSweepData(dev, c['meas']) power = util.linspace(pstar, pstop, npoints) power = [T.Value(p, 'dBm') for p in power] for s in sparams: for i, c in enumerate(s): s[i] = T.Complex(c) returnValue((power, sparams))
def freq_sweep(self, c): """Initiate a frequency sweep.""" dev = self.selectedDevice(c) length = yield dev.query("DSPN? 0") length = int(length) print length data = yield dev.query("DSPB? 0") print len(data) if len(data) != length*4: raise Exception("Lengths don't match, dude! %d isn't equal to %d" % (len(data), length*4)) print "unpacking..." data = [unpack('<f', data[i*4:i*4+4])[0] for i in range(length)] #Calculate frequencies from current span resp = yield dev.query('FSTR?0') fs = T.Value(float(resp), 'Hz') resp = yield dev.query('FEND?0') fe = T.Value(float(resp), 'Hz') freq = util.linspace(fs, fe, length) returnValue(zip(freq, data))