Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

plug_fourier.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006    
00007 #include "afni.h"
00008 
00009 #ifndef ALLOW_PLUGINS
00010 #  error "Plugins not properly set up -- see machdep.h"
00011 #endif
00012 
00013 /***********************************************************************
00014  ************************************************************************/
00015 
00016 char * Fourier_Main( PLUGIN_interface * ) ;
00017 
00018 static char helpstring[] =
00019    " Purpose: Do some common FFT manipulations of 3d+time data\n"
00020    " Inputs:\n"
00021    " Dataset = A 3d+time dataset in memory.\n"
00022    " Outputs:\n"
00023    " Prefix = Filename prefix to be usedfor the output dataset.\n"
00024    " Parameters:\n"
00025    " Preprocess: Data manipulations before/after filtering\n"
00026    "  Ignore: ignore the first n datapoints.  After filtering\n"
00027    "   these points are set to the value of the n+1th point\n"
00028    "   such that the timeseries is the same length\n"
00029    "  A linear trend is removed before any filtering is performed.\n"
00030    "   Setting retrend to 'Yes' restores this trend after filtering\n" 
00031    "   This is always yes for the 1D transform version\n"
00032    " Lowpass: Perform a low pass filtering of the data.\n"
00033    "  Fc is the frequency cutoff (in Hz).  Note that this is\n"
00034    "   typically a very small number.\n"
00035    " Highpass: Perform a high pass filtering of the data.\n"
00036    "  Fc is the frequency cutoff (in Hz).  Note that this is\n"
00037    "   typically a very small number.\n\n"
00038    " With appropriate combination of lowpass and highpass, a\n"
00039    "  bandpass (f_high < f_low) or notch (f_high > f_low)\n"
00040    "  filter can be made.\n"
00041 /*   " Autocorrelate: Perform an autocorrelation (DUH) of the time-\n"
00042    "  series.  Essentially the correlation between the data and\n"
00043    "  and all possible phase shifts of it.\n\n"
00044 */   " Note that if multiple operations are chosen, they are performed\n"
00045    "  in the order listed.\n\n"
00046    " IMPORTANT: This plugin also sets the parameters for the 1D \n"
00047    "  transform named Fourier.  Thus, it is not necessary to have\n"
00048    "  an input and output.\n\n"
00049    " BY- T. Ross and K. Heimerl 8/99\n"
00050 ;
00051 
00052 static float low_fc, high_fc;    /* Global variables so we can be a plugin or 1D transformation filter */
00053 static char *output_prefix;
00054 static int autocorr, retrend, ignore;
00055 static MCW_idcode *idc;
00056 
00057 
00058 /***********************************************************************
00059   include the filter driver and filter routines
00060  ************************************************************************/
00061 #define IN_FOURIER_PLUGIN
00062 #include "fourier_filter.c"
00063 
00064 /***********************************************************************
00065    1D transformation function
00066  ************************************************************************/
00067 
00068 void fourier_1D(int num, double to, double dt, float *vec) {
00069         filter(vec, low_fc, high_fc, num, (float)dt, ignore, TRUE, TRUE);
00070 }
00071 
00072 
00073 /***********************************************************************
00074    Set up the interface to the user
00075 ************************************************************************/
00076 
00077 
00078 DEFINE_PLUGIN_PROTOTYPE
00079 
00080 PLUGIN_interface * PLUGIN_init( int ncall )
00081 {
00082    PLUGIN_interface * plint ;
00083    static char *yn[2] = {"No", "Yes"};
00084 
00085    if( ncall > 0 ) return NULL ;  /* only one interface */
00086 
00087    /*-- set titles and call point --*/
00088 
00089    /* Initialize variables so we can be a 1D transformer*/
00090    low_fc=0; high_fc = 0; ignore=1; autocorr=FALSE; retrend=FALSE; output_prefix=NULL; idc=NULL;
00091    PLUTO_register_1D_function( "Fourier", fourier_1D );
00092 
00093 
00094    plint = PLUTO_new_interface( "Fourier Stuff" , "Filtering, autocorrelation and other stuff done with FFTs" , helpstring ,
00095                                  PLUGIN_CALL_VIA_MENU , Fourier_Main  ) ;
00096 
00097    PLUTO_add_hint( plint , "Filtering, autocorrelation and other stuff done with FFTs" ) ;
00098 
00099    PLUTO_set_sequence( plint , "z:Ross" ) ;
00100    /*-- first line of input: Dataset --*/
00101 
00102    PLUTO_add_option( plint , "Input" , "Input" , FALSE ) ;
00103    PLUTO_add_dataset(plint , "Dataset" ,
00104                                     ANAT_ALL_MASK , FUNC_ALL_MASK ,
00105                                     DIMEN_4D_MASK | BRICK_ALLREAL_MASK ) ;
00106 
00107    /*-- second line of input: Prefix for output dataset --*/
00108 
00109    PLUTO_add_option( plint , "Output" , "Output" , FALSE ) ;
00110    PLUTO_add_string( plint , "Prefix" , 0, NULL , 19 ) ;
00111 
00112    /*-- third line of input: Preprocessing --*/
00113 
00114    PLUTO_add_option( plint , "Preprocess" , "Preprocess" , TRUE ) ;
00115    PLUTO_add_number( plint , "Ignore" ,  0, 10,  0, 1 , FALSE) ;
00116    PLUTO_add_string( plint, "Re-trend", 2, yn, 0); 
00117 
00118    /*-- fourth line of input: Lowpass option --*/
00119 
00120    PLUTO_add_option( plint , "Lowpass" , "Lowpass" , FALSE ) ;
00121    PLUTO_add_number( plint , "Fc" ,  0, 5000,  3, 0 , TRUE) ;
00122 
00123    /*-- fifth line of input: Highass option --*/
00124 
00125    PLUTO_add_option( plint , "Highpass" , "Highpass" , FALSE ) ;
00126    PLUTO_add_number( plint , "Fc" ,  0, 5000,  3, 0 , TRUE) ;
00127 
00128    /*-- sixt line of input: Autocorrelation option --*/
00129 /*
00130    PLUTO_add_option( plint , "Autocorrelate" , "Autocorrelate" , FALSE ) ;
00131  */
00132    return plint ;
00133 }
00134 
00135 /***************************************************************************
00136   Main routine for this plugin (will be called from AFNI).
00137 ****************************************************************************/
00138 
00139 char * Fourier_Main( PLUGIN_interface * plint )
00140 {
00141    THD_3dim_dataset *input ;
00142    char *tag;
00143 
00144 
00145    /* New call, so reinitialize variables */
00146    low_fc=0; high_fc = 0; autocorr=FALSE; retrend=FALSE; output_prefix=NULL, idc=NULL;
00147 
00148    /*--------------------------------------------------------------------*/
00149    /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/
00150 
00151    if( plint == NULL )
00152       return "*************************\n"
00153              "Fourier_Main:  NULL input\n"
00154              "*************************"  ;
00155 
00156 
00157    tag = PLUTO_get_optiontag(plint) ;
00158    while( tag != NULL ){
00159 
00160         if (strcmp(tag, "Input") == 0 ) {
00161            idc  = PLUTO_get_idcode(plint) ;
00162            input = PLUTO_find_dset(idc) ;
00163            if( input == NULL )
00164               return "********************************\n"
00165                      "Fourier_Main:  bad input dataset\n"
00166                      "********************************"  ;
00167         }
00168 
00169         else if (strcmp(tag, "Preprocess") == 0) {
00170                 ignore = PLUTO_get_number(plint);
00171                 retrend = strcmp(PLUTO_get_string(plint), "No");
00172         }
00173 
00174       else if( strcmp(tag,"Output") == 0 ){
00175          output_prefix = PLUTO_get_string(plint) ;
00176          if( ! PLUTO_prefix_ok(output_prefix) )
00177             return "*************************\n"
00178                    "Fourier_Main:  bad prefix\n"
00179                    "*************************"  ;
00180       }
00181 
00182       else if( strcmp(tag,"Lowpass") == 0 ){
00183          low_fc = PLUTO_get_number(plint);
00184       }
00185 
00186       else if( strcmp(tag,"Highpass") == 0 ){
00187          high_fc = PLUTO_get_number(plint);
00188       }
00189  
00190       else if( strcmp(tag,"Autocorrelate") == 0 ){
00191          autocorr=TRUE;
00192       }
00193 
00194       tag = PLUTO_get_optiontag(plint) ;
00195    }
00196 
00197    /*------------------------------------------------------*/
00198    /*---------- At this point, the inputs are OK ----------*/
00199 
00200    if ((output_prefix == NULL) || (idc == NULL)) /* must be setting up for 1D transform */
00201       return NULL ;
00202    else 
00203       return Fourier_Filter_Driver(plint, input, low_fc, high_fc, ignore, autocorr, retrend, output_prefix);  
00204 }
 

Powered by Plone

This site conforms to the following standards: