def filtertrace(self): binning = 0.1e-9 fsampling = 1. / binning if self.type == 'EA61' or self.type == None: f1 = 3.4e9 f2 = 4.2e9 order = 2 Exf = utils.highpass(self.Ex, fsampling, order, f1) self.Exf = utils.lowpass(Exf, fsampling, order, f2) Eyf = utils.highpass(self.Ey, fsampling, order, f1) self.Eyf = utils.lowpass(Eyf, fsampling, order, f2) Ezf = utils.highpass(self.Ez, fsampling, order, f1) self.Ezf = utils.lowpass(Ezf, fsampling, order, f2) absEf = utils.highpass(self.absE, fsampling, order, f1) self.absEf = utils.lowpass(absEf, fsampling, order, f2)
def FEfilter(self, wf): Nyfreq = wf.sampling/2 ratiofreq = float(fcut)/Nyfreq b, a = signal.butter(4, ratiofreq) y = utils.lowpass(wf.amp,wf.sampling,4,1*fcut) newwf = waveform.Waveform(wf.time,y,'fefilter') return newwf
def __init__(self, chunk_len, filter_, hq_path, cutoff, duration=None, start=8): hq, sr = u.read_audio(hq_path) # high quality target lq = u.lowpass(hq, cutoff, filter_=filter_) # low quality input # CROP song_len = lq.shape[-1] if duration is None: # save entire song test_start = 0 test_len = song_len else: test_start = start * sr # start from n th second test_len = duration * sr test_len = min(test_len, song_len - test_start) lq = lq[:, test_start:test_start + test_len] hq = hq[:, test_start:test_start + test_len] self.x_full = lq.copy() self.t_full = hq.copy() # To have equal length chunks for minibatching time_len = lq.shape[-1] n_chunks, rem = divmod(time_len, chunk_len) lq = lq[..., :-rem or None] # or None handles rem=0 hq = hq[..., :-rem or None] # adjust lengths self.x_full = self.x_full[..., :lq.shape[-1] or None] self.t_full = self.t_full[..., :lq.shape[-1] or None] # Save full samples self.lq = np.split(lq, n_chunks, axis=-1) # create a lists of chunks self.hq = np.split(hq, n_chunks, axis=-1) # create a lists of chunks
def __getitem__(self, idx): try: hq, sr = u.read_audio(self.file_list[idx]) # high-quality target # take a chunk starting at random location x_length = hq.shape[1] start_loc = random.randint(0, x_length - self.input_len - 1) hq = hq[:, start_loc:start_loc + self.input_len] # select filter randomly from the list random_filter = random.choice(self.filters) # apply low-pass filter lq = u.lowpass(hq, self.cutoff, filter_=random_filter) # low-quality input hq = torch.from_numpy(hq) # convert to torch tensor lq = torch.from_numpy(lq) # convert to torch tensor return lq, hq # input, target except: # In case of a problem, Nones are filtered out later. return None
poly = np.poly1d([slope,offset]) #fit the conv vs power: simpd = poly(simshifted) print len(time), ' ' , len(real) # deconvolution: deconv = utils.deconv(wfPD[0],wfPD[1],gain,tau) polydeconv = np.poly1d([1./slope, - offset/slope]) dec = polydeconv(deconv[1]) power = wfRF[1]**2/constant.impedance logpower = utils.watttodbm(power) decsamp = 1./(deconv[0][1] - deconv[0][0]) print decsamp fcut = 2e8 # dec = utils.lowpasshard(dec,decsamp, fcut) dec = utils.lowpass(dec,decsamp, 4, fcut) lindec = utils.dbmtowatt(dec) fft = np.fft.rfft(dec) fftfreq = np.fft.rfftfreq(len(dec),deconv[0][1] - deconv[0][0]) # plt.semilogy(fftfreq,np.absolute(fft)) # plt.plot(wfRF[0],logpower) # plt.plot(deconv[0],dec) plt.plot(wfRF[0],power) plt.plot(deconv[0],lindec) # plt.plot(time,real) # plt.plot(time,simpd) plt.show()
if count < 3: count += 1 continue else: count += 1 ls = l.split() a_t = np.append(a_t, float(ls[5])) a_ant = np.append(a_ant, int(ls[1])) a_E = np.append(a_E, float(ls[10])) binning = 0.1e-9 fsampling = 1. / binning amp = a_E[(a_ant == 1)] lpcut = 4.2e9 hpcut = 3.4e9 lpfiltered = utils.lowpass(amp, fsampling, 3, lpcut) hpfiltered = utils.highpass(lpfiltered, fsampling, 3, hpcut) figt = plt.figure() plt.plot(a_t[(a_ant == 1)], a_E[(a_ant == 1)]) plt.plot(a_t[(a_ant == 1)], hpfiltered) #plt.plot(a_t[(a_ant==2)], a_E[(a_ant==2)]) #plt.plot(a_t[(a_ant==3)], a_E[(a_ant==3)]) #plt.plot(a_t[(a_ant==4)], a_E[(a_ant==4)]) #plt.semilogy(freq,np.abs(fft)) #plt.plot(freq,np.arctan(fft.imag/fft.real)) figspec = plt.figure() spec = np.absolute(np.fft.rfft(a_E[(a_ant == 1)])) specfiltered = np.absolute(np.fft.rfft(hpfiltered)) freq = np.fft.rfftfreq(len(a_t[(a_ant == 1)]), binning)
def lowpass(self, wf, fcut, order): filtamp = utils.lowpass(wf.amp,wf.sampling,order,fcut) newwf = waveform.Waveform(wf.time,filtamp,'an_filt') return newwf