Re: fft in saol

From: John Lazzaro (lazzaro@CS.Berkeley.EDU)
Date: Sat Sep 16 2000 - 15:58:36 EDT


> The imaginairy component of the vector would be over 2?????
>
> What type of value is that?

Here's one possibility -- this very well may be wrong, but it
seems to make sense from the few quick experiments I did. To
get unity gain from an fft() ifft() combination of length N,
the total scaling that has to be done is 1/N. How you apportion
that scaling of 1/N between the fft and ifft will determine,
in part, the absolute value of the sqrt(re^2 + im^2) numbers
you are looking at.

The Structured Audio FDIS scales both the fft() summation and
the ifft() summation by 1/sqrt(N), so that if you do both back
to back you get:

(1/sqrt(N))*(1/sqrt(N)) = 1/N

However, this
also means if you take a look at the output of the fft(),
you're not getting the scaling you might expect (depending
on your expectation, of course :-).

If you plot out the numbers (1/sqrt(N))*sqrt(re^2 + im^2), the
absolute values look more reasonable -- I tried this for
a few different power-of-two N values, putting a 1000Hz
sinewave through an fft/ifft pair, and things look reasonable.

Here's a SAOL/SASL snippet:

SASL:

0.2 tone 0.6
0.9 end

SAOL:

global {
srate 44100;
krate 100;
outchannels 2;
}

instr tone ()
     
{
  table re(empty,512);
  table im(empty,512);
  table w(window,512,6);
  asig x,y,z,init;
  ivar a, shift, len;
  ksig newfft, i, j;

  shift = 512;
  len = 512;

  a = 2*sin(3.141597*1000/s_rate);

  if (!init)
    {
      init = 1;
      x = 0.5;
    }
  
  x = x - a*y;
  y = y + a*x;
  
  fft(y,re,im, len, shift, len, w);
  i = 498;
  while (i < 503)
    {
      printf("%f %f\n", i,
             (sqrt(tableread(re, i)*tableread(re, i) +
                  tableread(im, i)*tableread(im, i)))/sqrt(512));
        i = i + 1;
    }
  j = j + 1;
  printf("\n", j);
  if (j > 5)
    {
      turnoff;
    }
  z = ifft(re,im, len, shift, len, w);
  output(z, y);

}

This will print out the region around the peak, for 512 points
with a boxcar window, with the added 1/sqrt(N) in the print
statement.

                                                        --jl

-------------------------------------------------------------------------
John Lazzaro -- Research Specialist -- CS Division -- EECS -- UC Berkeley
lazzaro [at] cs [dot] berkeley [dot] edu www.cs.berkeley.edu/~lazzaro
-------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Mon Jan 28 2002 - 12:03:59 EST