Beispiel #1
0
def freqfilt_eeg(fn_in,fn_out,btype="lp",fl=None,fh=None,border=3,windowed=False):
    eeg = eegpy.open_eeg(fn_in)
    out = eegpy.F32(fn_out,"w+",shape=eeg.shape,cNames=eeg.channel_names,Fs=eeg.Fs)
    if btype == "lp":
        if not windowed:    
            out[:,:] = filtfilt_low(fl,eeg[:,:],Fs=eeg.Fs,border=border)
        else:
            for i in range(0,out.num_datapoints,100000):
                out[i:min(i+100000,out.num_datapoints),:] = filtfilt_low(fl,eeg[i:min(i+100000,out.num_datapoints),:],Fs=eeg.Fs,border=border)
    elif btype == "hp":
        #for i_c in range(eeg.num_channels):
        if not windowed:    
            out[:,:] = filtfilt_high(fh,eeg[:,:],Fs=eeg.Fs,border=border)
        else:
            for i in range(0,out.num_datapoints,100000):
                out[i:min(i+100000,out.num_datapoints),:] = filtfilt_high(fh,eeg[i:min(i+100000,out.num_datapoints),:],Fs=eeg.Fs,border=border)
    elif btype == "bp":
        if not windowed:    
            out[:,:] = filtfilt_band(fl,fh,eeg[:,:],Fs=eeg.Fs,border=border)
        else:
            for i in range(0,out.num_datapoints,100000):
                out[i:min(i+100000,out.num_datapoints),:] = filtfilt_band(fl,fh,eeg[i:min(i+100000,out.num_datapoints),:],Fs=eeg.Fs,border=border)
    elif btype == "bs":
        if not windowed:    
            out[:,:] = filtfilt_bandstop(fl,fh,eeg[:,:],Fs=eeg.Fs,border=border)
        else:
            for i in range(0,out.num_datapoints,100000):
                out[i:min(i+100000,out.num_datapoints),:] = filtfilt_bandstop(fl,fh,eeg[i:min(i+100000,out.num_datapoints),:],Fs=eeg.Fs,border=border)
Beispiel #2
0
 def calculate(self, cond_name=None):
     """After doing the setup, this method actually calculates the ERPs. 
     If no argument is supplied, then the data for all conditions are calculated."""
     if cond_name == None:
         cnames = self._times.keys()
     else:
         cnames = [cond_name]
     
     #self.check_for_artifacts()
     
     for c in cnames:
         logger.debug("Condition %s" % c)
         #assert self._datadict.has_key(c) and self._is_calculated.has_key(c), "Key in dictionary missing!"
         f = self.eeg
         #TODO: check timepoints
         ndp = f.numDatapoints
         tps_ok = True
         logger.debug("datapoints: %s, input: %s" % (ndp, str(f)))
         for t in self._times[c]:
             #if debug:
             #    print "t = ", t
             if t+self._start_end[0]<0 or t+self._start_end[1]>ndp:
                 tps_ok=False
                 break
         if tps_ok:
             #getData
             data = f.get_data_for_events(self._times[c],self._start_end)
             if self._lp_freq!=None:
                 data = filtfilt_low(self._lp_freq,data,Fs=f.Fs)
             #Baseline-Korrektur
             data -= self._get_baseline_data(data).mean(axis=0)
             #calculate average
             self._datadict[c] = data[:,:,~self._is_artifact[c]].mean(axis=2)
             #print "Shape datadict:", self._datadict[c].shape
             self._is_calculated[c] = True
         else:
             raise ValueError("Some problem with the timepoints occured." +
                              "Number of datapoints: %i, Max. timepoint: %i" %(ndp, max(self._times[c])))
Beispiel #3
0
 def final_lowpass(self, f=90):
     """Performs simple lowpass, removing sharp edges"""
     eeg = self.eeg
     eeg[:] = filtfilt_low(f,eeg[:],Fs=eeg.Fs)
Beispiel #4
0
 def final_lowpass(self, f=None):
     """Performs simple lowpass, removing sharp edges"""
     if f == None:
         f = self._f_flp
     eeg = self._data
     eeg[:] = filtfilt_low(f,eeg[:],Fs=self._Fs)