def getdata(self, chan=1, Nr=1, Nt=1, Nmeas=10, calibration=False, seed=0): """ getdata from VNA Parameters ---------- Nmeas : number of measures chan : int channel number Nr : Number of receiver (used only when calibration ==True) Nt : Number of transmitter (used only when calibration ==True) Nmeas : Number of measurements calibration : boolean (used only for emulation) if True the measurement correspond to a dataset for calibration purpose seed : In emulated mode the data are produced from random number. seed is for reproducibility of random experiments. Examples -------- >>> from pylayers.measures.vna.E5072A import * >>> import matplotlib.pyplot as plt >>> import numpy as np >>> vna = SCPI() >>> vna.parS(param='S21',cmd='set') >>> S21 = vna.getdata() >>> vna.close() """ self.nmeas = Nmeas #ipdb.set_trace() #print "Nmeas vna",self.nmeas if not self.emulated: com = 'CALC' + str( chan ) + ':DATA:SDAT?' #This command sets/gets the corrected data array. for k in range(Nmeas): buff = '' while len(buff) != (self.Nf * 16 + 8): self.trigger(cmd='test') buff = self.read(com) #print"buffer size :",len(buff) #ipdb.set_trace() S = np.frombuffer(buff[8:self.Nf * 16 + 8], dtype='>f8') Y = S.reshape(self.Nf, 2) H = Y[:, 0] + 1j * Y[:, 1] try: tH = np.vstack((tH, H[None, :])) except: tH = H[None, :] tH = tH[:, None, None, :] else: if not calibration: np.random.seed(seed) tau = 300 + 10 * np.random.rand(Nr, Nt) h = ch.TBchannel() h.SalehValenzuela() H = h.toFD(fGHz=self.fGHz) EH = np.sum(H.y * np.conj(H.y), axis=1) / self.Nf stn = np.sqrt(EH) / 10. N = stn * (np.random.rand(Nmeas, Nr, Nt, self.Nf) + 1j * np.random.rand(Nmeas, Nr, Nt, self.Nf)) tH = H.y[:, None, None, :] + N tH = tH * np.exp( -2 * 1j * np.pi * self.fGHz[None, None, None, :] * tau[None, :, :, None]) else: np.random.seed(seed) tau = 300 + 10 * np.random.rand(Nr, Nt) tH = np.exp(-2 * 1j * np.pi * self.fGHz[None, None, None, :] * tau[None, :, :, None]) dtau = 7 * np.random.rand() tH = tH * np.exp( -2 * 1j * np.pi * self.fGHz[None, None, None, :] * dtau) return tH
buff = self.read(com) #print"buffer size :",len(buff) #ipdb.set_trace() S = np.frombuffer(buff[8:self.Nf*16+8], dtype='>f8') Y = S.reshape(self.Nf, 2) H = Y[:, 0]+1j*Y[:, 1] try: tH = np.vstack((tH, H[None,:])) except: tH = H[None,:] tH = tH[:,None,None,:] else: if not calibration: np.random.seed(seed) tau = 300 + 10*np.random.rand(Nr,Nt) h = ch.TBchannel() h.SalehValenzuela() H = h.toFD(fGHz=self.fGHz) EH = np.sum(H.y*np.conj(H.y),axis=1)/self.Nf stn = np.sqrt(EH)/10. N = stn*(np.random.rand(Nmeas,Nr,Nt,self.Nf)+1j*np.random.rand(Nmeas,Nr,Nt,self.Nf)) tH = H.y[:,None,None,:]+N tH = tH*np.exp(-2*1j*np.pi*self.fGHz[None,None,None,:]*tau[None,:,:,None]) else: np.random.seed(seed) tau = 300 + 10*np.random.rand(Nr,Nt) tH = np.exp(-2*1j*np.pi*self.fGHz[None,None,None,:]*tau[None,:,:,None]) dtau = 7*np.random.rand() tH = tH* np.exp(-2*1j*np.pi*self.fGHz[None,None,None,:]*dtau) return tH