def w_frequencies(state, spacing): """ This function calculates the FFT frequencies """ nX = state.shape[0] nY = state.shape[1] return sp.meshgrid(2.0 * sp.pi * pl.fftfreq(nX, spacing), 2.0 * sp.pi * pl.fftfreq(nY, spacing))
def PhaseSpectPlotter(self, f, f2, wg, Res, comp, reg, TIM, out_name = None, frmt='png'): Nx, Ny, Lx, Ly, N_nodes = self.OptsExtr() ndav, int_step, cc = self.more_opts_extr() actual_time = int(TIM)*int_step/ndav Fmin, Fmax, res, res_x, res_y, clrmap, freq_min, freq_max,freq2_min, freq2_max = Res # freq_min,freq_max = float(freq_min), float(freq_max) absc_min, absc_max, ord_min, ord_max, absc_name, ord_name = comp try: if len(res.split('x'))>1: resX = int(res.split('x')[0]) resY = int(res.split('x')[1]) else: resX = int(res) resY = resX except ValueError: self.stat_print("something's wrong with resolution") if absc_name == 'y' and absc_max==0. and absc_min==0.: L_absc = 0. R_absc=Ly elif absc_name == 'x' and absc_max==0. and absc_min==0.: L_absc = 0. R_absc=Lx else: R_absc=absc_max L_absc=absc_min if ord_name == 'y' and ord_max==0. and ord_min == 0.: L_ord = 0. R_ord=Ly elif ord_name == 'x' and ord_max==0. and ord_min == 0.: L_ord = 0. R_ord=Lx else: R_ord=ord_max L_ord=ord_min a,b,c = np.histogram2d(f2, f, bins= ( resY, resX ), range=[[L_ord, R_ord],[L_absc, R_absc]],normed=False, weights = resX*resY*wg) if Fmin == 0.: Fmin = None if Fmax == 0.: Fmax= None aa = abs(fft2(a))[:len(b)/2,:len(c)/2] freqX = fftfreq(len(c),c[1]-c[0])[:len(c)/2] freqY = fftfreq(len(b),b[1]-b[0])[:len(b)/2] self.fig.clear() sp = self.fig.add_subplot(111, title='time step = '+str(actual_time)+r'$ \tau_0$') pplt = sp.imshow(aa,vmin=Fmin,vmax=Fmax,extent=[freqX[0],freqX[-1],freqY[0],freqY[-1]], aspect = 'auto', interpolation=intrp,cmap = clrmap, origin='lower') sp.axis((freq_min,freq_max,freq2_min, freq2_max)) self.fig.colorbar(pplt) self.canvas.show()
def SpectPlotter(self,f,Res, reg, TIM = None, out_name = None , flag3D='2D',frmt='png'): Nx, Ny, Lx, Ly, N_nodes = self.OptsExtr() ndav, int_step, cc = self.more_opts_extr() actual_time = int(TIM)*int_step/ndav Nx1, Nx2, Ny1, Ny2, Fmin, Fmax, res, res_x, res_y, clrmap, freq_min, freq_max,freq2_min, freq2_max = Res res, res_x, res_y, Nx1, Nx2, Ny1, Ny2, freq_min,freq_max = int(res), int(res_x), int(res_y), float(Nx1),float(Nx2),float(Ny1),float(Ny2), float(freq_min), float(freq_max) Nx1=int(np.rint(Nx1*Nx/Lx));Nx2=int(np.rint(Nx2*Nx/Lx)) Ny1=int(np.rint(Ny1*Ny/Ly));Ny2=int(np.rint(Ny2*Ny/Ly)) dX=Lx/Nx dY=Ly/Ny if Fmin == 0.: Fmin = None if Fmax == 0.: Fmax= None if Nx2==0: Nx2 = Nx-1 if Ny2==0: Ny2 = Ny-1 dx, dy = self.StepDef(Res[:-4]) dx=int(np.ceil(dx/2.)) dy=int(np.ceil(dy/2.)) aa = abs(fft2(f[Ny1:Ny2,Nx1:Nx2]))[:(Ny2-Ny1)/2:dy,:(Nx2-Nx1)/2:dx] freqX = fftfreq(Nx2-Nx1, dX)[:(Nx2-Nx1)/2:dx] freqY = fftfreq(Ny2-Ny1, dY)[:(Ny2-Ny1)/2:dy] self.fig.clear() if flag3D == '3D': XX, YY = np.meshgrid(freqX, freqY) Xmin_ind = int(len(freqX)*freq_min/freqX[-1]) Xmax_ind = int(len(freqX)*freq_max/freqX[-1]) Ymin_ind = int(len(freqY)*freq_min/freqY[-1]) Ymax_ind = int(len(freqY)*freq_max/freqY[-1]) sp = Axes3D(self.fig, title='time step = '+str(actual_time)+r'$ \tau_0$') # sp.set_zlim3d(Fmin,Fmax) # sp.set_xlim3d(freq_min,freq_max) sp.set_ylim3d(freq_min,freq_max) sp.plot_surface(XX[Ymin_ind:Ymax_ind,Xmin_ind:Xmax_ind],YY[Ymin_ind:Ymax_ind,Xmin_ind:Xmax_ind],aa[Ymin_ind:Ymax_ind,Xmin_ind:Xmax_ind],cmap = clrmap, linewidth=0) if flag3D == '2D': sp = self.fig.add_subplot(111, title='time step = '+str(actual_time)+r'$ \tau_0$') pplt = sp.imshow(aa,vmin=Fmin,vmax=Fmax,extent=[freqX[0],freqX[-1],freqY[0],freqY[-1]], aspect = 'auto', interpolation=intrp,cmap = clrmap, origin='lower') sp.set_xlabel(r'$k_x/k_0$',fontsize=14) sp.set_ylabel(r'$k_y/k_0$',fontsize=14) sp.axis((freq_min,freq_max,freq2_min, freq2_max)) self.fig.colorbar(pplt) self.canvas.show() if reg == 'wrt': self.fig.savefig('./img/'+self.out_name_add+'_'+out_name+'_s_'+TIM+'.'+frmt) clf() return
def TemporalSpectPlot(self, d,wmin,wmax): self.fig.clear() sp = Axes3D(self.fig) ndav, int_step, cc = self.more_opts_extr() ll = len(d[0])-1 for i in ll-np.arange(ll): y=i*np.ones(len(d)/2) sp.plot(fftfreq(len(d), (d[1,0]-d[0,0])/(ndav/cc))[:len(d)/2], y ,abs(rfft(d[:,i]))[:-1]) sp.set_xlim3d(wmin,wmax) sp.set_xlabel(r'$\omega/\omega_0$',fontsize=14) sp.set_ylabel('node index',fontsize=14) sp.set_zlabel(r'$\langle E_z \rangle_\omega$',fontsize=14) self.canvas.show()
def __plot_frequency(audio, rate=rs.RATE): samples = audio.shape[0] data_fft = fft(audio) fft_abs = abs(data_fft) freq = pylab.fftfreq(samples, 1 / rate) plt.xlim([10, rate / 2]) plt.xscale('log') plt.grid(True) plt.xlabel('Frequency (Hz)') plt.plot(freq, fft_abs) plt.show()
def calcFourier(self, yout, tspan): ''' Calculate FFT and return magnitude spectrum and frequencies freqs === Python array aMags === numpy array rMags === numpy array ''' ActEC = yout[:, 3] RepEC = yout[:, 9] freqs = fftfreq(len(tspan), tspan[1] - tspan[0]) aMags = array(abs((fft(ActEC)))) rMags = array(abs((fft(RepEC)))) return freqs, aMags, rMags
def fitOscillations(self, harmonics=None): """""" t = self.variableArray dt = t[1] - t[0] data = self.orders[0] amp_guess = (data.max() - data.min()) / 2 weights = abs(py.fft(data))**2 index = weights.argmax() if harmonics is None else harmonics f_guess = py.fftfreq(t[-1] - t[0], dt)[index] offset_guess = data.mean() phi_guess = py.arccos(data[0] - offset_guess) guesses = [amp_guess, f_guess, phi_guess, offset_guess] self.guesses = guesses coeffs, matcov = curve_fit(self.func, t, data, self.guesses) self.coeffs = coeffs self.matcov = matcov
def fft_filter(time, signal, result, window_func=pl.hanning, \ samp_freq=8, freq_limit = (0.0033, 0.04)): """ Applies an Band Pass filter to signal in the frequency domain and returns filterd PSD. In: time : ndarray, relative R occurance times vector signal : ndarray, HRV vector result : dict, current fragment info (see process function) samp_freq : int, signal sample frequency freq_limit : tuple, (min, max) frequencies for band pass filter Out: freq_filt_log : ndarray, frequency in logarithm scale spec_filt_log : ndarray, PSD in logarithm scale """ window = window_func(len(signal)) # window signal_wed = signal * window n = len(signal)/2 spec = (pl.absolute(pl.rfft(signal_wed))[:-1]/(n))**2 # entering to frequency domain freq = pl.fftfreq(len(signal), 1.0/samp_freq)[:n] # get freqs axis values spec_filt = pl.zeros(spec.shape, dtype='float') freq_filt = pl.zeros(freq.shape, dtype='float') # same for filtered for i in range(n): # filter by frequency if pl.logical_and(freq_limit[0] <= abs(freq[i]), abs(freq[i]) <= freq_limit[1]): freq_filt[i] = freq[i] spec_filt[i] = spec[i] else: freq_filt[i] = 0 # fill invalid frequencies with 0 value spec_filt[i] = 0 spec_filt = pl.ma.masked_equal(spec_filt,0) # cutt off invalid values spec_filt = pl.ma.compressed(spec_filt) freq_filt = pl.ma.masked_equal(freq_filt,0) freq_filt = pl.ma.compressed(freq_filt) spec_filt_log = pl.log10(spec_filt) # for output freq_filt_log = pl.log10(freq_filt) return freq_filt_log, spec_filt_log
def freqz(sosmat, nsamples=44100, sample_rate=44100, plot=True): """Plots Frequency response of sosmat.""" from pylab import np, plt, fft, fftfreq x = np.zeros(nsamples) x[nsamples/2] = 0.999 y, states = sosfilter_double_c(x, sosmat) Y = fft(y) f = fftfreq(len(x), 1.0/sample_rate) if plot: plt.grid(True) plt.axis([0, sample_rate / 2, -100, 5]) L = 20*np.log10(np.abs(Y[:len(x)/2]) + 1e-17) plt.semilogx(f[:len(x)/2], L, lw=0.5) plt.hold(True) plt.title('freqz sos filter') plt.xlabel('Frequency / Hz') plt.ylabel('Damping /dB(FS)') plt.xlim((10, sample_rate/2)) plt.hold(False) return x, y, f, Y
def freqz(sosmat, nsamples=44100, sample_rate=44100, plot=True): """Plots Frequency response of sosmat.""" from pylab import np, plt, fft, fftfreq x = np.zeros(nsamples) x[int(nsamples/2)] = 0.999 y, states = sosfilter_double_c(x, sosmat) Y = fft(y) f = fftfreq(len(x), 1.0/sample_rate) if plot: plt.grid(True) plt.axis([0, sample_rate / 2, -100, 5]) L = 20*np.log10(np.abs(Y[:int(len(x)/2)]) + 1e-17) plt.semilogx(f[:int(len(x)/2)], L, lw=0.5) plt.hold(True) plt.title(u'freqz sos filter') plt.xlabel('Frequency / Hz') plt.ylabel(u'Damping /dB(FS)') plt.xlim((10, sample_rate/2)) plt.hold(False) return x, y, f, Y
def SpecEvolPlot(self, d,windwidth,step,wmin,wmax, rowind): dd=np.array([]) ndav, int_step, cc = self.more_opts_extr() Tim=np.arange(windwidth, len(d)-windwidth,step) for n in Tim: dd=np.append(dd, np.abs(rfft(d[n-windwidth:n+windwidth,rowind]))[:-1]) Freq=fftfreq(2*windwidth, (d[1,0]-d[0,0])/(ndav/cc))[:windwidth] if wmax!=0: nFrqMax= int(wmax/(Freq[1]-Freq[0])) else: nFrqMax=len (Freq) nFrqMin= int(wmin/(Freq[1]-Freq[0])) dd=dd.reshape(len(Tim),len(Freq))[:,nFrqMin:nFrqMax].transpose() self.fig.clear() sp = self.fig.add_subplot(111) pplt = sp.imshow(dd, origin='lower',aspect='auto',extent=[d[Tim[0],0]/(ndav/cc), d[Tim[-1],0]/(ndav/cc),Freq[nFrqMin],Freq[nFrqMax]]) sp.set_xlabel(r'$t/\tau_0$',fontsize=14) sp.set_ylabel(r'$\omega/\omega_0$',fontsize=14) self.fig.colorbar(pplt) self.canvas.show() return
def _calculatefdData(self,tdData): #no need to copy it before (access member variable is ugly but shorter) #calculate the fft of the X channel fd=py.fft(tdData.getEX()) #calculate absolute and phase values fdabs=abs(fd) fdph=abs(py.unwrap(py.angle(fd))) #calculate frequency axis dfreq=py.fftfreq(tdData.num_points,tdData.dt) #extrapolate phase to 0 and 0 frequency fdph=self.removePhaseOffset(dfreq,fdph) #set up the fdData array t=py.column_stack((dfreq,fd.real,fd.imag,fdabs,fdph)) #this is so not nice! self.fdData=t unc=self.calculateFDunc() t=self.getcroppedData(t,0,unc[-1,0]) #interpolate uncertainty intpunc=interp1d(unc[:,0],unc[:,1:],axis=0) unc=intpunc(t[:,0]) return py.column_stack((t,unc))
x_max = 10e-6 y_min = -10e-6 y_max = 10e-6 nx = 512 ny = 512 x = np.linspace(x_min, x_max, nx, endpoint=False) y = np.linspace(y_min, y_max, ny, endpoint=False) X, Y = np.meshgrid(x, y) dx = x[1] - x[0] dy = y[1] - y[0] # Fourier space: kx = 2 * pi * pl.fftfreq(len(x), d=dx) ky = 2 * pi * pl.fftfreq(len(y), d=dy) Kx, Ky = np.meshgrid(kx, ky) # Laplace operator in Fourier space: f_laplacian = -(Kx**2 + Ky**2) # The Harmonic trap at our gridpoints, (n_elements x N): V = 0.5 * m * omega**2 * (X**2 + Y**2) @inmain_decorator() def plot(i, t, psi): if SHOW_PLOT: rho_plot = np.abs(psi)**2 phase_plot = np.angle(psi)
#! /usr/bin/env python from pylab import figure, loadtxt, arange, ones, fftfreq, rfft from mpl_toolkits.mplot3d import Axes3D fig = figure() ax = Axes3D(fig) inp = raw_input("input xfel_xx number xx and node index:").split(' ') xx = inp[0] node = inp[1] d = loadtxt('../xfel_' + xx + '/etc/fld_00' + node + '_000') ll = len(d[0]) - 1 for i in ll - arange(ll): y = i * ones(len(d) / 2) ax.plot(fftfreq(len(d), 0.04)[:len(d) / 2], y, abs(rfft(d[:, i]))[:-1]) ax.set_xlim3d(0.9, 1.1) fig.show() fig.show() raw_input("Press Enter to continue...")
def SpectSpacePlotter(self,f,Res, reg, TIM = None, out_name = None, flag3D='2D', frmt='png'): Nx, Ny, Lx, Ly, N_nodes = self.OptsExtr() ndav, int_step, cc = self.more_opts_extr() actual_time = int(TIM)*int_step/ndav Nx1, Nx2, Ny1, Ny2, Fmin, Fmax, res, res_x, res_y, clrmap, freq_min, freq_max,freq2_min, freq2_max, ax = Res res, res_x, res_y, Nx1, Nx2, Ny1, Ny2,freq_max = int(res), int(res_x), int(res_y), float(Nx1),float(Nx2),float(Ny1),float(Ny2), float(freq_max) Nx1=int(np.rint(Nx1*Nx/Lx));Nx2=int(np.rint(Nx2*Nx/Lx)) Ny1=int(np.rint(Ny1*Ny/Ly));Ny2=int(np.rint(Ny2*Ny/Ly)) dX=Lx/Nx dY=Ly/Ny X=np.linspace(0,Lx,Nx) Y=np.linspace(0,Ly,Ny) dx, dy = self.StepDef(Res[:-5]) if Fmin == 0.: Fmin = None if Fmax == 0.: Fmax= None if Nx2==0: Nx2 = Nx-1 if Ny2==0: Ny2 = Ny-1 if ax=='x': Nn1=Nx Nn2=Ny Xx=X Yy=Y Ll=Ly ddx=int(np.ceil(dx/2.)) ddy=dy freq_min, freq_max = freq_min, freq_max elif ax=='y': f=f.transpose() Nn1=np.shape(f)[1] Nn2=Nx Xx=Y Yy=X Ll=Lx ddx=int(np.ceil(dy/2.)) ddy=dx freq_min, freq_max = freq2_min, freq2_max datFFT = np.zeros((Nn2, Nn1/2+1)) XFFT = abs(fftfreq( Nn1, Xx[1])[:Nn1/2+1]) for j in np.arange(Nn2): datFFT[j] = abs(rfft(f[j])) myextent=[XFFT[0],XFFT[-1],Yy[0],Yy[-1]] self.fig.clear() if flag3D == '3D': XX, YY = np.meshgrid(XFFT, Yy) sp = Axes3D(self.fig, title='time step = '+str(actual_time)+r'$ \tau_0$') sp.plot_surface(XX,YY,datFFT, cmap = clrmap, linewidth=0) sp.set_zlim3d(Fmin,Fmax) if flag3D == '2D': sp = self.fig.add_subplot(111, title='time step = '+str(actual_time)+r'$ \tau_0$') if ax=='x': sp.set_ylabel(r'$y/\lambda_0$',fontsize=14) sp.set_xlabel(r'$k_x/k_0$',fontsize=14) elif ax=='y': sp.set_ylabel(r'$x/\lambda_0$',fontsize=14) sp.set_xlabel(r'$k_y/k_0$', fontsize=14) pplt = sp.imshow(datFFT[::ddy,::ddx],extent=myextent, aspect = 'auto', interpolation=intrp,origin='lower',vmin=Fmin, vmax=Fmax, cmap = clrmap) sp.axis((freq_min,freq_max,0,Ll)) self.fig.colorbar(pplt) self.canvas.show() if reg == 'wrt': self.fig.savefig('./img/'+self.out_name_add+'_'+out_name+'_s'+ax+'_'+TIM+'.'+frmt) clf() return
def freqz(ofb, length_sec=6, ffilt=False, plot=True): """Computes the IR and FRF of a digital filter. Parameters ---------- ofb : FractionalOctaveFilterbank object length_sec : scalar Length of the impulse response test signal. ffilt : bool Backard forward filtering. Effectiv order is doubled then. plot : bool Create Plots or not. Returns ------- x : ndarray Impulse test signal. y : ndarray Impules responses signal of the filters. f : ndarray Frequency vector for the FRF. Y : Frequency response (FRF) of the summed filters. """ from pylab import np, plt, fft, fftfreq x = np.zeros(length_sec * ofb.sample_rate) x[int(length_sec * ofb.sample_rate / 2)] = 0.9999 if not ffilt: y, states = ofb.filter_mimo_c(x) y = y[:, :, 0] else: y, states = ofb.filter(x, ffilt=ffilt) s = np.zeros(len(x)) len_x_2 = int(len(x) / 2) for i in range(y.shape[1]): s += y[:, i] X = fft(y[:, i]) # sampled frequency response f = fftfreq(len(x), 1.0 / ofb.sample_rate) if plot: fig = plt.figure('freqz filter bank') plt.grid(True) plt.axis([0, ofb.sample_rate / 2, -100, 5]) L = 20 * np.log10(np.abs(X[:len_x_2]) + 1e-17) plt.semilogx(f[:len_x_2], L, lw=0.5) Y = fft(s) if plot: plt.title(u'freqz() Filter Bank') plt.xlabel('Frequency / Hz') plt.ylabel(u'Damping /dB(FS)') plt.xlim((10, ofb.sample_rate / 2)) plt.figure('sum') L = 20 * np.log10(np.abs(Y[:len_x_2]) + 1e-17) plt.semilogx(f[:len_x_2], L, lw=0.5) level_input = 10 * np.log10(np.sum(x**2)) level_output = 10 * np.log10(np.sum(s**2)) plt.axis([5, ofb.sample_rate / 1.8, -50, 5]) plt.grid(True) plt.title('Sum of filter bands') plt.xlabel('Frequency / Hz') plt.ylabel(u'Damping /dB(FS)') print('sum level', level_output, level_input) return x, y, f, Y
convolution = numpy.fft.ifft( pl.multiply(ftilda, gtilda) ) #Convolution using properties of fourier transforms and convolution return pl.divide(convolution, len(ftilda)) * T a = tophat(t, 3, 5) b = gaussian(t).tolist() c = split_gaussian(t) pl.figure("h(t)") pl.plot(t, a, label="h(t)") pl.plot(t, b, label="g(t)") #pl.figure("convolution") pl.plot(t, convolve(a, c), label="h(t)*g(t)") pl.legend() print(pl.trapz(convolve(a, c), t, dx=0.0001)) #finds area under convolution curve pl.figure() pl.plot(pl.fftfreq(N, d=dT), numpy.fft.fft(a), label=r"$\mathcal{F}(h(t))(\omega)$") pl.legend() pl.figure() pl.plot(pl.fftfreq(N, d=dT), numpy.fft.fft(b), label=r"$\mathcal{F}(g(t))(\omega)$") pl.legend()
def freqz(ofb, length_sec=6, ffilt=False, plot=True): """Computes the IR and FRF of a digital filter. Parameters ---------- ofb : FractionalOctaveFilterbank object length_sec : scalar Length of the impulse response test signal. ffilt : bool Backard forward filtering. Effectiv order is doubled then. plot : bool Create Plots or not. Returns ------- x : ndarray Impulse test signal. y : ndarray Impules responses signal of the filters. f : ndarray Frequency vector for the FRF. Y : Frequency response (FRF) of the summed filters. """ from pylab import np, plt, fft, fftfreq x = np.zeros(length_sec*ofb.sample_rate) x[length_sec*ofb.sample_rate/2] = 0.9999 if not ffilt: y, states = ofb.filter_mimo_c(x) y = y[:, :, 0] else: y, states = ofb.filter(x, ffilt=ffilt) s = np.zeros(len(x)) for i in range(y.shape[1]): s += y[:, i] X = fft(y[:, i]) # sampled frequency response f = fftfreq(len(x), 1.0/ofb.sample_rate) if plot: fig = plt.figure('freqz filter bank') plt.grid(True) plt.axis([0, ofb.sample_rate / 2, -100, 5]) L = 20*np.log10(np.abs(X[:len(x)/2]) + 1e-17) plt.semilogx(f[:len(x)/2], L, lw=0.5) plt.hold(True) Y = fft(s) if plot: plt.title('freqz() Filter Bank') plt.xlabel('Frequency / Hz') plt.ylabel('Damping /dB(FS)') plt.xlim((10, ofb.sample_rate/2)) plt.hold(False) plt.figure('sum') L = 20*np.log10(np.abs(Y[:len(x)/2]) + 1e-17) plt.semilogx(f[:len(x)/2], L, lw=0.5) level_input = 10*np.log10(np.sum(x**2)) level_output = 10*np.log10(np.sum(s**2)) plt.axis([5, ofb.sample_rate/1.8, -50, 5]) plt.grid(True) plt.title('Sum of filter bands') plt.xlabel('Frequency / Hz') plt.ylabel('Damping /dB(FS)') print('sum level', level_output, level_input) return x, y, f, Y
if not respaddr: raise RuntimeError except Exception,e: logging.error('Problems loading response file: %s => %s' % (filename, e)) for rec in tr.iter_record(): data = array( rec.trdata() ) logging.debug( 'Total samples: %s ' % len(data) ) npts = len(data) logging.debug('compute the one-dimensional discrete Fourier Transform') fft_values = fft(data)[0:int(npts/2)+1] # Return the Discrete Fourier Transform sample frequencies logging.debug('compute the Fourier Transform sample frequencies') freq = fftfreq(len(data), d=1.0/samprate)[range(0,npts/2+1)] # the last element is negative, because of the symmetry, but should # be positive fft_values[-1] *= -1 convolved = [] for f in freq: w = f * 2 * pi convolved.append( response._eval_response(respaddr, w ) ) data = irfft( convolved * fft_values ) logging.debug( 'Total samples: %s ' % len(data) ) rec.trputdata( data )
nsx_basic_header = nsx.read_basic_header(f_nsx) lfp1 = nsx.read_electrode(f = f_nsx, basic_header = nsx_basic_header, electrode = 14, tstart_ms = 5000, t_dur_ms = 1000) pylab.subplot(2,1,1) t = pylab.arange(lfp1.size)/2000. pylab.plot(t, lfp1) offset = 0 t_window_ms = 500 N_wave = t_window_ms * 2 mean_ft = pylab.zeros(N_wave, dtype='float') for n in range(100): lfp1 = nsx.read_electrode(f = f_nsx, basic_header = nsx_basic_header, electrode = 14, tstart_ms = t_window_ms*n + offset, t_dur_ms = t_window_ms) ft = pylab.absolute(pylab.fft(lfp1)) mean_ft += ft pylab.subplot(2,1,2) F = pylab.fftfreq(mean_ft.size, d = 1/2000.) pylab.semilogy(F, mean_ft/50.) pylab.xlabel('F (Hz)') pylab.ylabel('Signal')
#! /usr/bin/env python from pylab import figure, loadtxt, arange, ones,fftfreq, rfft from mpl_toolkits.mplot3d import Axes3D fig = figure() ax = Axes3D(fig) inp = raw_input("input xfel_xx number xx and node index:").split(' ') xx = inp[0] node=inp[1] d = loadtxt('../xfel_'+xx+'/etc/fld_00'+node+'_000') ll = len(d[0])-1 for i in ll-arange(ll): y=i*ones(len(d)/2) ax.plot(fftfreq(len(d), 0.04)[:len(d)/2], y ,abs(rfft(d[:,i]))[:-1]) ax.set_xlim3d(0.9,1.1) fig.show() fig.show() raw_input("Press Enter to continue...")
f_nsx = open(nev_dir + ns3_fname, 'rb') nsx_basic_header = nsx.read_basic_header(f_nsx) lfp1 = nsx.read_electrode(f=f_nsx, basic_header=nsx_basic_header, electrode=14, tstart_ms=5000, t_dur_ms=1000) pylab.subplot(2, 1, 1) t = pylab.arange(lfp1.size) / 2000. pylab.plot(t, lfp1) offset = 0 t_window_ms = 500 N_wave = t_window_ms * 2 mean_ft = pylab.zeros(N_wave, dtype='float') for n in range(100): lfp1 = nsx.read_electrode(f=f_nsx, basic_header=nsx_basic_header, electrode=14, tstart_ms=t_window_ms * n + offset, t_dur_ms=t_window_ms) ft = pylab.absolute(pylab.fft(lfp1)) mean_ft += ft pylab.subplot(2, 1, 2) F = pylab.fftfreq(mean_ft.size, d=1 / 2000.) pylab.semilogy(F, mean_ft / 50.) pylab.xlabel('F (Hz)') pylab.ylabel('Signal')