home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 March / macformat-035.iso / Shareware City / Developers / FFTs for RISC 1.0 / rfftTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-19  |  2.1 KB  |  91 lines  |  [TEXT/CWIE]

  1. /*  A program to test and time real input fast fourier transform routine    */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <timer.h>
  7. #include "fftsbig.h"
  8.  
  9. #define    NUMROWS 1        /* process Matrix of NUMROWS different ffts of length N    */
  10. #define N 2048            /* size of FFT, must be a power of 2 */
  11. #define NTIMES 20        /* number of timings, invalid if too big (if a[0][0] = 0 | nan)*/
  12.  
  13. void main(){
  14. float        *Utbl;
  15. float        (*a)[N];
  16. UnsignedWide         TheTime1;
  17. UnsignedWide         TheTime2;
  18. double        TheTime;
  19. long         i, il;
  20. long         TheErr;
  21. long        M;
  22.  
  23. Utbl = (float *) malloc((N/4+1)*sizeof(float));
  24. if (Utbl==0)
  25.     TheErr = 2;
  26. else
  27. TheErr = rFFTInit(&M, N, Utbl);
  28.  
  29. if(!TheErr){
  30.     a = (float (*)[N]) malloc(NUMROWS*N*sizeof(float));
  31.     if (a == 0) TheErr = 2;
  32. }
  33.  
  34. if(!TheErr){
  35.  
  36.             /*  set up a simple test case */
  37.     for (il=0; il<NUMROWS; il++){
  38.         for (i=0; i<N; i+=2){
  39.             a[il][i] = sqrt(il+i+.77777);    
  40.             a[il][i+1] = (il+i+.22222)*(il+i+.22222) / N - N/2;    
  41.         }
  42.         a[il][0] = N+3;
  43.         a[il][2] = 1-N;
  44.     }
  45.  
  46.     Microseconds(&TheTime1);
  47.     for (i=0;i<NTIMES;i++){        /* do many times for timing */
  48.         rffts((float *)a, M, NUMROWS, Utbl);
  49.     }
  50.     Microseconds(&TheTime2);
  51.  
  52.     TheTime = (double)(TheTime2.hi - TheTime1.hi) * 65536.0 * 65536.0;
  53.     TheTime = (TheTime + (double)(TheTime2.lo - TheTime1.lo))/1000.0;
  54.     printf("Time rfft = %12f   ms.    a[0][0]= %6e\n", TheTime/NTIMES/NUMROWS, a[0][0]);
  55.  
  56.     printf("\n");
  57.  
  58.             /*  set up a simple test case */
  59.     for (il=0; il<NUMROWS; il++){
  60.         for (i=0; i<N; i+=2){
  61.             a[il][i] = sqrt(il+i+.77777);    
  62.             a[il][i+1] = (il+i+.22222)*(il+i+.22222) / N - N/2;    
  63.         }
  64.         a[il][0] = N+3;
  65.         a[il][2] = 1-N;
  66.     }
  67.  
  68.     rffts((float *)a, M, NUMROWS, Utbl);
  69.  
  70.     if (N*NUMROWS <= 256){
  71.          for (il=0; il<NUMROWS; il++){
  72.             printf("atrans = [ \n");
  73.             for (i=0; i<N; i+=2)
  74.                 printf(" %+20.15e + j * ( %+20.15e ) \n", a[il][i], a[il][i+1]);
  75.             printf("]; \n");    
  76.             }
  77.         }
  78.     else {  /* abbreviate big output */
  79.         printf("the last 20 values of the first transform are: \n");
  80.         for (i=N-40; i<N; i+=2)
  81.             printf(" %+20.15e + j * ( %+20.15e ) \n", a[0][i], a[0][i+1]);
  82.     }
  83.     free (a);
  84.     free (Utbl);
  85. }
  86. else
  87. if(TheErr==2)    printf(" out of memory ");
  88. else    printf(" error ");
  89. return;
  90. }
  91.