Hi Experts.<br /><br />I am Physics student, and i wanna write referat about Fourier transformations, also about FFT 1D real case.<br />Hope this is best place for ask this, and here are best experts.<br /><br />I wanaa demonstrate how diverse window functions changes measured spectrum,<br />how much CPU ressources take diverse FFT algorithms ...<br /><br />Yet i understand [i hope so] how works windowing .<br /><br />Is somewhere available copy-paste self contained C example functions or makros for diverse FFT algorithms<br />FFT, QFT, Goertzel, radix-2, radix-4, split-radix, mixed-radix ... ?<br /><br />Which variables in FFT function must/should be defined as static, register ... for best performance ?<br />What typical comes in to FFT function ? Pointer to already windowed array of samples ?<br />What return FFT ?<br />What exact physical dimensions return FFT , if input function dimensions was - voltage depends from (time) U=U(t) ?<br />How from ...1024 or 2048 or 4096... FFT return values  i calculate power magnitudes for all bands, <br />and finally values for visual 10-20 hopping bars, like in Winamp , XMMS , QMMP ... ?<br /><br />If i exact know my FFT window size [for example 4096 samples] and window type , and it will be constant forever,<br />is it possible to calculate window(,sine,cosine,) and store all values in constant array,<br />so that in runtime it do not need be calculated , but i can just  take values form array ?<br /><br />I have google_d about FFT and have found such proggie [see below]<br />I have it little bit remixed , i generate pure sine frekwenz = 796.7285 HZ , <br />and in output file i got so what :<br /><br />[ 71] 764.4287 Hz: Re= 0.0000000011142182 Im= 0.0000002368905824 M= 0.0000002368932028<br />[ 72] 775.1953 Hz: Re= 0.0000000011147694 Im= 0.0000003578625618 M= 0.0000003578642981<br />[ 73] 785.9619 Hz: Re= 0.0000000011164234 Im= 0.0000007207092628 M= 0.0000007207101275<br />[ 74] 796.7285 Hz: Re=-0.0000022785007614 Im=-0.5000000048748561 M= 0.5000000048800476<br />[ 75] 807.4951 Hz: Re= 0.0000000011098065 Im=-0.0000007304711756 M= 0.0000007304720186<br />[ 76] 818.2617 Hz: Re= 0.0000000011114605 Im=-0.0000003676273975 M= 0.0000003676290776<br />[ 77] 829.0283 Hz: Re= 0.0000000011120118 Im=-0.0000002466579503 M= 0.0000002466604569<br />...<br />...<br />...<br />[4019] 43270.9717 Hz: Re= 0.0000000011120118 Im= 0.0000002466579503 M= 0.0000002466604569<br />[4020] 43281.7383 Hz: Re= 0.0000000011114605 Im= 0.0000003676273975 M= 0.0000003676290776<br />[4021] 43292.5049 Hz: Re= 0.0000000011098065 Im= 0.0000007304711756 M= 0.0000007304720186<br />[4022] 43303.2715 Hz: Re=-0.0000022785015510 Im= 0.5000000048748419 M= 0.5000000048800334<br />[4023] 43314.0381 Hz: Re= 0.0000000011164234 Im=-0.0000007207092628 M= 0.0000007207101275<br />[4024] 43324.8047 Hz: Re= 0.0000000011147694 Im=-0.0000003578625618 M= 0.0000003578642981<br />[4025] 43335.5713 Hz: Re= 0.0000000011142182 Im=-0.0000002368905824 M= 0.0000002368932028<br /><br />Where<br />43303.2715 + 796.7285 = 44100 or 44100 - 43303.2715 = 796.7285<br />Why Frequency 796.7285 is mirrored as Frequency 43303.2715 , and magnitude for both Frequencies is divided by 2 ????<br />Is here way direct calculate full magnitude and without Frequency mirroring , in band 0 Hz ... FSampl/2 ONLY ,<br />and not in full band - 0 Hz ... FSampl ??<br />In this case - how do i calculate corresponding frequency of each band that returns FFT, if sample frequency is 32K, 44K or 48K ?<br /> <br />Pleaz do not point me to FFTW[3] and such libs , i must self write/combine code .<br /> Except FFTW has best short self contained 1D functions for copy-paste :)<br /><br />Each pointer and example is welcomed.<br />Tnx in advance @ all.<br /><br /><br />Alfs Kurmis.<br /><br /><br /><br /><br />====<br /><br /><br /><br />#include <stdio.h><br />#include <stdlib.h><br />#include <string.h><br />#include <ctype.h><br />#include <math.h><br /><br />#define BUFFER 4096 //2048<br />//#define BUFFER 256<br /># define M_PI_LD        3.1415926535897932384626433832795029L  /* pi */<br />//void readwave(const char *filename, double *tr);<br />short FFT(short int dir, long m, double *x, double *y);<br /><br />double fstep;<br /><br />int main (int argc, char *argv [])<br />{<br />  int i;<br />  double f = 0.0;<br />  double amplitude = 0.;   double  samplerate = 44100., frekwenz=796.7285; double xarg=0. , argplus = 0. , pti ;<br />  double real[BUFFER], img[BUFFER];<br />//  ====  =====<br /><br />  argplus = ( frekwenz *2.0*M_PI )/samplerate;<br />  //printf("Reading %d bytes from %s.\r\n", BUFFER, argv[1]);<br />   for(i=0;i<BUFFER;i++)<br />    {  //  xarg=0.0;  argplus=0.2;   floarArg =0.0001;<br />       pti = sin ( xarg ) /* * 32767.0*/ ;<br />       /*if ( kante>0 ) { if( pti > 0.0 ){ pti = 23767.0; }else{pti = -23767.0;}  }  /**/<br />       xarg = xarg +argplus;//+floarArg;<br />         if ( xarg > (4.0*M_PI) ) xarg = xarg - (4.0*M_PI);<br />       real[i] = pti; <br />    }<br />  printf("F=  %7.2f Hz \n\n", (samplerate*argplus)/(2*M_PI) );<br /><br />  memset(img, 0, sizeof(img)); /* Fill all the imaginary parts with zeros */<br />   //fstep = (double) samplerate / (double) (BUFFER*2);<br />   fstep = (double) samplerate / (double) (BUFFER);<br />   printf("Frequency step : %10.6f\r\n", fstep);<br /><br />   FFT(1, /*11*/ 12, real, img); /* Fast Fourier Transform with 2^11 bins */<br />   // FFT(1,  7, real, img); /* Fast Fourier Transform with 2^11 bins */<br /><br />  /* Write fourier transformed data to stdio */<br />  i = 0;<br />  while(i < BUFFER) <br />  {<br />    amplitude = sqrt((real[i]*real[i]) + (img[i]*img[i]));<br />    //printf("(%4d) %.2f Hz: Re=%f Im=%f P=%f\r\n", i, f, real[i], img[i], amplitude);<br />    printf("[%4d] %8.4f Hz: Re=%22.16f  Im=%22.16f  M=%22.16f\n", i, f, real[i], img[i], amplitude);<br />    i++;<br />    f += fstep;<br />  }<br /><br />return 0 ;<br />} // main<br /><br /><br />/*<br />   This computes an in-place complex-to-complex FFT <br />   x and y are the real and imaginary arrays of 2^m points.<br />   dir =  1 gives forward transform<br />   dir = -1 gives reverse transform <br />*/<br />short FFT(short int dir, long m, double *x, double *y)<br />{<br />   long n,i,i1,j,k,i2,l,l1,l2;<br />   double c1,c2,tx,ty,t1,t2,u1,u2,z;<br /><br />   /* Calculate the number of points  N = M ^2 */<br />   n = 1;    for (i=0;i<m;i++)  n *= 2;<br />                  printf("FFT -->> (n) 2 ^ %ld =  %ld\n", m, n);<br />   /* Do the bit reversal */<br />   i2 = n >> 1;<br />   j = 0;<br />   for (i=0;i<n-1;i++) {<br />      if (i < j) {<br />         tx = x[i];         ty = y[i];<br />         x[i] = x[j];       y[i] = y[j];<br />         x[j] = tx;         y[j] = ty;<br />      }<br />      k = i2;<br />      while (k <= j) {<br />         j -= k;<br />         k >>= 1;<br />      }<br />      j += k;<br />   } // for (i=0;i<n-1;i++)<br /><br />   /* Compute the FFT */<br />   c1 = -1.0; <br />   c2 = 0.0;<br />   l2 = 1;<br />   for (l=0;l<m;l++) {<br />      l1 = l2;<br />      l2 <<= 1;<br />      u1 = 1.0; <br />      u2 = 0.0;<br />      for (j=0;j<l1;j++) {<br />         for (i=j;i<n;i+=l2) {<br />            i1 = i + l1;<br />            t1 = u1 * x[i1] - u2 * y[i1];  t2 = u1 * y[i1] + u2 * x[i1];<br />            x[i1] = x[i] - t1;             y[i1] = y[i] - t2;<br />            x[i] += t1;                    y[i] += t2;<br />         }<br />         z =  u1 * c1 - u2 * c2;<br />         u2 = u1 * c2 + u2 * c1;<br />         u1 = z;<br />      }<br />      c2 = sqrt((1.0 - c1) / 2.0);<br />      if (dir == 1) <br />         c2 = -c2;<br />      c1 = sqrt((1.0 + c1) / 2.0);<br />   }<br /><br />   /* Scaling for forward transform */<br />   if (dir == 1) {<br />      for (i=0;i<n;i++) {<br />         x[i] /= n;    y[i] /= n;<br />      }<br />   }<br />   <br />   return(1); //return(TRUE);<br />}<br /><br /><br /><br /><br /><br /><br /><br /><br /><div id="sig_upper"><br />  <br /> ----</div><br /> <div id="sig_lower"> </div>
<!--                                                                                                                                                                                                                                                                                                                      -->