• API Main Page
  • Documentation
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

src/tools.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Matthias Ihrke   *
00003  *   mihrke@uni-goettingen.de   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "tools.h"
00022 #include "eeg.h"
00023 #include "mathadd.h"
00024 
00033 EEG* eeg_remove_baseline( EEG *eeg, double win_from, double win_to, bool alloc ){
00034 #ifdef FIXEEG
00035   int lim[2], c, i;
00036   double mean;
00037   EEG *eeg_out;
00038 
00039   if( !eeg->times ){
00040      errprintf("Need times-array, aborting...\n");
00041      return NULL;
00042   }
00043 
00044   if( alloc ){
00045      eeg_out = eeg_clone( eeg, EEG_CLONE_ALL );
00046   } else {
00047      eeg_out = eeg;
00048   }
00049 
00050   lim[0] = closest_index( eeg->times, eeg->n, win_from );
00051   lim[1] = closest_index( eeg->times, eeg->n, win_to );
00052   if( lim[1]<=lim[0] ){
00053      errprintf( "The specified limits are funny: %.2f-%.2f (results in %i-%i)\n", 
00054                     win_from, win_to, lim[0], lim[1] );
00055   }
00056   for( c=0; c<eeg->nbchan; c++ ){
00057      for( i=0; i<eeg->ntrials; i++ ){
00058         mean=dblp_mean( eeg->data[c][i]+lim[0], lim[1]-lim[0] );
00059         // printf(" mean=%f\n", mean);
00060         dblp_minus_scalar( eeg->data[c][i], eeg->n, mean );
00061      }
00062   }
00063 
00064   return eeg_out;
00065 #endif
00066 }

Generated on Fri Jun 25 2010 14:10:21 for libeegtools by  doxygen 1.7.0