home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c129 / 1.ddi / FFTDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-13  |  1.8 KB  |  90 lines

  1. # include <math.h>
  2. # include "fft.h"
  3. # include <stdio.h>
  4. # include "miscio.h"
  5. # include <ctype.h>
  6.  
  7.  
  8. float fftr[512];
  9. float ffti[512];
  10. float ar[512];
  11. float bi[512];
  12. float xr[512];
  13. float yi[512];
  14.  
  15. int lower;
  16. int upper;
  17. int nd;
  18. int i;
  19. int j;
  20. int k;
  21. char c;
  22. void DisplayData(float dat1[],float dat2[], float dat3[],int numdat)
  23. {
  24.    int i;
  25.    int j;
  26.    int start;
  27.    int stop;
  28.    int increment;
  29.    char nextpage;
  30.    char cr;
  31.  
  32.    GotoXY(1,24);
  33.    printf(" (n)ext page      (b)ack page       (q)uit display");
  34.    start = 0;
  35.    stop = 19;
  36.    nextpage = 0;
  37.  
  38.    while ( nextpage != 'Q' ) {
  39.       for ( i = start; i <= stop; ++i ) {
  40.      GotoXY(1,3 + (i % 20));
  41.          ClrEol();
  42.          printf("%4d .      %10.3f    %10.3f       %10.3f",
  43.                    i, dat1[i], dat2[i], dat3[i]);
  44.  
  45.       }
  46.       GotoXY(1,23);
  47.       printf("prompt > ");
  48.       nextpage = getch();
  49.       printf(" %c",nextpage );
  50.       nextpage = toupper(nextpage);
  51.       if ( nextpage == 'N' ) {
  52.          increment = 20;
  53.       }
  54.       if ( nextpage == 'B' ) {
  55.          increment = -20;
  56.       }
  57.       start = start + increment;
  58.       if ( (start < 0) || (start > numdat - 19) ) {
  59.          start = 0;
  60.       }
  61.       stop = stop + increment;
  62.       if ( (stop < 19) || (stop > numdat) ) {
  63.          stop = 19;
  64.       }
  65.    }
  66. }
  67.  
  68.  
  69. void main()
  70. {
  71.    nd = 128;
  72.    for ( i = 0; i <= nd - 1; ++i ) {
  73.       xr[i] = cos(M_PI * i / 16.0) + cos(M_PI * i / 32.0);
  74.       yi[i] = 0;
  75.       ar[i] = xr[i];
  76.       bi[i] = yi[i];
  77.    }
  78.    FFTCalc(xr,yi,nd);
  79.    for ( i = 0; i <= nd-1; ++i ) {
  80.       fftr[i] = xr[i];
  81.       ffti[i] = yi[i];
  82.    }
  83.    FFTInvCalc(xr,yi,nd);
  84.    ClrScr();
  85.    GotoXY(1,1);
  86.    printf( "index          rawdata       fft data        inverse fft data");
  87.     DisplayData(ar,fftr,xr,nd);
  88.  
  89. }
  90.