def ppc(session,area,unit,start,stop, window=100,FMAX=250,color='k',label=None,nTapers=None,lw=1.5,linestyle='-'): if not nTapers is None: warn('WARNING: no longer using multitaper, nTapers will be ignored! using Hann window') # depricating original code due to inconsistency with matlab PPC code ''' snippits = getSTLFP(session,area,unit,start,stop,window) M = shape(snippits)[0] fs = fft(snippits) raw = abs(sum(fs/abs(fs),0))**2 unbiased = (raw-M)/(M**2-M) freqs = fftfreq(window*2+1,1./FS) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],color=color,label=label) ylim(0,0.5) ylabel('PPC',labelpad=-10) xlim(0,FMAX) nicelimits() xticks(linspace(0,FMAX,11),['%d'%x for x in linspace(0,FMAX,11)]) xlabel('Frequency (Hz)') title('Pairwise phase consistency') simpleaxis(gca()) ''' channel = get_unit_channel(session,area,unit) ''' # formerly getting signals from each block. we need to pull the data # from the raw LFP though, so that we can grab some LFP outside the # blocks in order to analyze spikes close to the edge of block. We # need those spikes for statistical power signal = get_good_trial_lfp_data(session,area,channel) times = get_all_good_trial_spike_times(session,area,unit,(6,start,stop)) ''' signal = get_raw_lfp_session(session,area,channel) times = get_spikes_session_filtered_by_epoch(session,area,unit,(6,start,stop)) (freqs,unbiased,phases),snippits = pairwise_phase_consistancy(signal,times, window=window, Fs=1000, multitaper=False, biased=False, delta=100, taper=hann) # function does not return anything, # just plots (below) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],linestyle,color=color,label=label,lw=lw) #cl = ppc_chance_level(nSamples,10000,.999,nTapers) #plot(xlim(),[cl,cl],color=color,label=label+' 99.9% chance level') #print 'chance level is %s'%cl ylim(0,0.5) ylabel('PPC',labelpad=-10) xlim(0,FMAX) nicelimits() xticks(linspace(0,FMAX,6),['%d'%x for x in linspace(0,FMAX,11)]) xlabel('Frequency (Hz)') title('Pairwise phase consistency') simpleaxis(gca())
def compare_ppc_approaches(session,area,unit,start,stop,window=100,FMAX=250): ''' Try with compare_ppc_approaches('RUS120523','PMv',42,-1000,0,200) ''' channel = get_unit_channel(session,area,unit) signal = get_raw_lfp_session(session,area,channel) times = get_spikes_session_filtered_by_epoch(session,area,unit,(6,start,stop)) (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100, multitaper=False,biased=False,taper=hann) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Hann unbiased') (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100, multitaper=False,biased=True,taper=hann) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Hann biased') (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100, multitaper=True,biased=False,k=1) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Multitaper 1 taper unbiased') (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100,k=2, multitaper=True,biased=False) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Multitaper 2 taper unbiased') (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100,k=3, multitaper=True,biased=False) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Multitaper 3 taper unbiased') (freqs,unbiased),nSamples = pairwise_phase_consistancy(signal,times, window=window,Fs=1000,delta=100,k=4, multitaper=True,biased=False) use = (freqs>0.)&(freqs<=250.) plot(freqs[use],unbiased [use],label='Multitaper 4 taper unbiased') #cl = ppc_chance_level(nSamples,10000,.999,nTapers) #plot(xlim(),[cl,cl],color=color,label=label+' 99.9% chance level') #print 'chance level is %s'%cl ylim(0,0.5) ylabel('PPC',labelpad=-10) xlim(0,FMAX) nicelimits() xticks(linspace(0,FMAX,11),['%d'%x for x in linspace(0,FMAX,11)]) xlabel('Frequency (Hz)') title('Pairwise phase consistency') simpleaxis(gca())