Beispiel #1
0
def singleChannelNoise(ds, timeStart=0.0, segmentLength=10.0, pad=0.5, reps=10, bandMin=5, bandMax=400, fnameRigFilter='', seed=0):
	'''Construct a single chanel band limited white noise stimulus. bandMin and bandMax specify the frequency of the band pass. segmentLength specifies the length of a noise segment in seconds. pad specifies an amount of silence surrounding the noise segment (pad occurs both before and after the noise). Reps specifies a number of times to repeat the pad,segment pair (thus, the total stimulus will be (segmentLength+2*pad)*reps seconds long). If specified, fnameRigFilter is a file name specifying a mat file containing a rig-specific velocity to voltage filter, which should be applied to the stimulus (after band passing). Seed, if specified and True (e.g. not 0), seeds the random number generator'''
	sl=int(round(segmentLength*ds.fs()))
	pad=int(round(pad*ds.fs()))
	l=reps*(sl+2*pad)
	xstart=int(round(timeStart*ds.fs()))
	sel = (None, [0], (xstart, xstart+l))
	if seed:
		random.seed(seed)
	dat=concatenate([zeros(pad), random.randn(sl), zeros(pad)])
	dat=bandpass(dat, bandMin, bandMax, ds.fs())
	fnameRigFilter=fnameRigFilter.strip()
	if fnameRigFilter:
		h=readmatfile(fnameRigFilter)
		h=h['h']
		ff=h['vel2volt0']
		opt=h['vel2volt_offsetpts_0'][0][0]
		hfs=h['sampfreq'][0][0]
		if hfs!=ds.fs():
			ff=array_resample(ff, hfs, ds.fs())
			opt=int(round(ds.fs()/hfs))
		dat=_cfilt(dat, ff, opt)
	dat=resize(dat, reps*dat.shape[0])
	sd=dat[pad:-pad].std()
	dat*=1.0/sd
	dat=reshape(dat, (-1, 1))	
	setSelection(ds, dat, sel)	
	fn='gwn%ito%iHz%ireps%isec_' % (bandMin, bandMax, reps, segmentLength)
	if fnameRigFilter:
		fn+="filtered"
	else:
		fn+="raw"
	ds.setAttrib('fname', fn)
Beispiel #2
0
def read(fname):
	return mf.readmatfile(fname)