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  

fftcheck.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 "mrilib.h"
00008 
00009 int main( int argc , char * argv[] )
00010 {
00011    int N ;
00012    complex * cx , * cs ;
00013    int ii ;
00014    float f , sum , xx,yy ;
00015 
00016    if( argc < 3 ){ printf("Usage: fftcheck N nfreq | more\n"); exit(1); }
00017 
00018    N = strtod( argv[1] , NULL ) ;
00019 
00020    if( N > 0 && N != csfft_nextup(N) ){
00021       fprintf(stderr,"Can't do FFT of length %d\n",N) ; exit(1) ;
00022    } else if ( N < 0 ){
00023       N = -N ;
00024    }
00025 
00026    f = strtod( argv[2] , NULL ) / N ;
00027 
00028    cs = (complex *) malloc(sizeof(complex)*N) ;
00029    cx = (complex *) malloc(sizeof(complex)*N) ;
00030 
00031    for( ii=0 ; ii < N ; ii++ ){
00032       cx[ii].r = cos(2*PI*f*ii) ; cx[ii].i = sin(2*PI*f*ii) ;
00033       cs[ii] = cx[ii] ;
00034    }
00035 
00036    csfft_scale_inverse(1) ;
00037 
00038    csfft_cox( -1 , N , cx ) ;
00039 
00040    for( ii=0 ; ii < N ; ii++ )
00041       printf("%2d: %12.5g %12.5g\n" , ii , cx[ii].r , cx[ii].i ) ;
00042 
00043    csfft_cox( 1 , N , cx ) ;
00044    sum = 0.0 ;
00045    for( ii=0 ; ii < N ; ii++ ){
00046       xx = cx[ii].r - cs[ii].r ;
00047       yy = cx[ii].i - cs[ii].i ; sum += xx*xx + yy*yy ;
00048    }
00049    sum = sqrt( sum/N ) ;
00050    printf("RMS error = %g\n",sum) ;
00051    exit(0) ;
00052 }
 

Powered by Plone

This site conforms to the following standards: