2

Actually, I think that I get the discrete Fourier transform some basics. And now I have some problems with the fast Fourier transform algorithm.

I don't want to share all the functions so as not to complicate the problem. But if you don't understand some parts I can edit the question.

Slow Fourier transform:

void slowft (float *x, COMPLEX *y, int n)
{
    COMPLEX tmp, z1, z2, z3, z4;
    int m, k;

/* Constant factor -2 pi */
    cmplx (0.0, (float)(atan (1.0)/n * -8.0), &tmp);
    
    printf (" constant factor -2 pi %f ", (float)(atan (1.0)/n * -8.0));
    for (m = 0; m<=n; m++)
    {
      
      cmplx (x[0], 0.0, &(y[m]));
      for (k=1; k<=n-1; k++)
      {
/* Exp (tmp*k*m) */
        cmplx ((float)k, 0.0, &z2);
        cmult (tmp, z2, &z3);
        cmplx ((float)m, 0.0, &z2);
        cmult (z2, z3, &z4);
        cexp (z4, &z2);
/* *x[k] */
        cmplx (x[k], 0.0, &z3);
        cmult (z2, z3, &z4);
/* + y[m] */
        csum (y[m], z4, &z2);
        y[m].real = z2.real; y[m].imag = z2.imag;
      }
    }
}

to make clear: cmplx is creating a complete number, cmult is complex multiplication and cexp is taking exponent. that's all.

And some optimizations:

void newslowft (double *x, COMPLEX *y, int n)
{
    COMPLEX tmp, z1, z2, z3, z4, *pre;
    long  m, k, i, p;

    pre = (COMPLEX *)malloc(sizeof(struct cpx)*1024);

/* Constant factor -2 pi */
    cmplx (0.0, atan (1.0)/n * -8.0, &z1);  
    cexp (z1, &tmp);

/* Pre-compute most of the exponential */
    cmplx (1.0, 0.0, &z1);          /* Z1 = 1.0; */
    //n=1024
    for (i=0; i<n; i++)
    {
      cmplx (z1.real, z1.imag, &(pre[i]));
      cmult (z1, tmp, &z3);
      cmplx (z3.real, z3.imag, &z1);
    }

/* Double loop to compute all Y entries */
    for (m = 0; m<n; m++)
    {
      cmplx (x[0], 0.0, &(y[m]));
      for (k=1; k<=n-1; k++)
      {
/* Exp (tmp*k*m) */
        p = (k*m % n);

/* *x[k] */
        cmplx (x[k], 0.0, &z3);
        cmult (z3, pre[p], &z4);
/* + y[m] */
        csum (y[m], z4, &z2);
        y[m].real = z2.real; 
        y[m].imag = z2.imag;
      }
    }
}

The problem: The first step of the optimization:

"precalculating some exponential inside the loop".

So this is actually what I ask. How does this algorithm calculate the all exponential? I think we are calculating the following exponentials: e^0 e^1 e^2.... e^1023 So where are the other exponentials?

I mean, in the first algorithm, inside the for loops we are using m (m=0; m<=1024; m ) and k(k=0; k<1023-1; k ) but, where is the e^1000*900?

As far as I understand, the second algorithm takes the mode according to n. I think this is the key point right? But I didn't get how to work?

Thanks in advance masters.

badcode
  • 581
  • 1
  • 9
  • 28
  • 1
    Is this C or C++? Please edit the tag if necessary – Quimby Aug 23 '21 at 18:46
  • 1
    @Quimby sorry, edited. – badcode Aug 23 '21 at 18:55
  • 3
    The Fast Fourier Transform does not need all the coefficients that a slow DFT uses because the needed products arising from compounding various operations. The FFT performs several passes where it multiplies elements by various coefficients in one pass (and also combines them with other elements in certain patterns) and then multiplies by different coefficients (and combines with different elements) in another pass, and the combinations work out to produce the required products. I do not advise trying to understand the FFT by reading code; tutorial text showing the math is a better approach. – Eric Postpischil Aug 23 '21 at 19:02

0 Answers0