示例#1
0
def getVarsDFT(x,t):
	"""Uses the discrete fast fouier transform to calculate
	the analytic signal (which is the hilbert transform 
	of the FS) this is diffrent as it uses the numpy solvers 
	to calculate the DFT, which is not robust and designed 
	for uniform sampling, and does not account for the dampening.
	Then the instantnious phase is calculated (and amp).
	The instantanious Freq is estimated by finite difference.
	x	1d np array of data
	t	1d np array of time corrisponding to x
		t will be used to sort 
		the x value, redundant data at a time point 
		will be combine via median.
	returns
	x	new x value (if redundent or unordered it will be diffrent)
	t	new corrisponding time
	th	instantanious phase
	dth	instantanious freq
	r	inst... amp...
	"""
	t,x = dataUtil.aveUnqTime(t,x,method='median')
	z = signal.hilbert(x)
	th = np.unwrap(np.arctan2(z.imag,z.real))
	r = np.abs(z)
	dth,t = dataUtil.FD(th,t)
	return(x,t,th,dth,r)
示例#2
0
def crossCorr(traj1,traj2,tstep=0,taumax=0):
	"""Performs corss correlation between two 
	dynamic trajectories with non uniform time spacing,
	and possibally diffrent time courses.
	will only use the overlaping time interval.
	will use a step size for tau equal to 
	the smallest step size in the data
	and will apply linear interpolation to 
	compute a uniform time course.
	A preprocessing step is used to 
	get a unique time seris for each 
	trajectory, meaidan value is used.
	"""
	# get unique time courses
	t1,x1_tmp = du.aveUnqTime(traj1[0],traj1[1],'median')
	t2,x2_tmp = du.aveUnqTime(traj2[0],traj2[1],'median')
	# find common range
	tmin = np.max(np.array([t1[0],t2[0]]))
	tmax = np.min(np.array([t1[-1],t2[-1]]))
	# we could use any step, but no reason to go lower
	# then smallest interval
	if tstep==0:
		tstep = np.min(np.array([np.min(t1[1:]-t1[:-1]),np.min(t2[1:]-t2[:-1])]))
	
	# the range to do linear interp
	t = np.arange(tmin,tmax,tstep)
	x1 = np.zeros(len(t))
	x2 = np.zeros(len(t))
	# do linear interp
	for i in range(len(t)):
		x1[i] = du.getOrInterp(t1,x1_tmp,t[i])
		x2[i] = du.getOrInterp(t2,x2_tmp,t[i])

	# calculate the number of tau steps if a max is specified
	if taumax>0:
		# how many steps to get to max?
		tausteps = int(taumax/tstep)+1

	else:
		tausteps = 0
	
	# now we have an evenly spaced time seris for two varriables
	# run the corss corelation
	cc,_ = crossCorrUniform(x1,x2,tstop=tausteps)
	tau = np.arange(float(len(cc)))
	tau = tau*tstep
	return(cc,tau)