N step fft in D language

growler growlercab at gmail.com
Sun Sep 15 15:59:20 PDT 2013


On Sunday, 15 September 2013 at 20:58:54 UTC, Kadir Erdem Demir 
wrote:
> On Sunday, 15 September 2013 at 15:39:14 UTC, John Colvin wrote:
>> On Sunday, 15 September 2013 at 15:15:28 UTC, Kadir Erdem 
>> Demir wrote:
>>> I am using fft function from std.numeric
>>>
>>> Complex!double[] resultfft = fft(timeDomainAmplitudeVal);
>>>
>>> The parameter timeDomainAmplitudeVal is audio amplitude data. 
>>> Sample rate 44100 hz and there is 131072(2^16) samples
>>>
>>> I am seeing that resultfft has the same size as 
>>> timeDomainAmplitudeVal(131072) which does not fits my 
>>> project(also makes no sense).
>>
>> That's what the FFT does. See here: 
>> http://stackoverflow.com/questions/4364823/how-to-get-frequency-from-fft-result
>
> I believe I am well aware of the things which are explained in 
> the link. There is a sentence in link which says  : "The first 
> bin in the FFT is DC (0 Hz), the second bin is Fs / N, where Fs 
> is the sample rate and N is the size of the FFT."
>
> My question how can I determine the "N" which is the size of 
> FFT ?
> In fftw library one can define N like :
> fftw_create_plan(N, FFTW_FORWARD, FFTW_ESTIMATE);
> In D do we have a way to do that ?

Others are correct, the FFT result is always the same length as 
the input and the 'N' is the number of samples you have to 
transform. See this page:

http://www.fftw.org/fftw2_doc/fftw_2.html

and the example from it:

#include <fftw.h>
...
{
      fftw_complex in[N], out[N]; // <== N  = number of samples
      fftw_plan p;
      ...
      p = fftw_create_plan(N, FFTW_FORWARD, FFTW_ESTIMATE);
      ...
      fftw_one(p, in, out);
      ...
      fftw_destroy_plan(p);
}

As you're probably aware, the FFT result will be symmetrical 
around frequency N/2. However, the result array is not centred 
around "elelment"  N/2 but rather the symmetry is at each end, 
wrapping from N back to 0. Like this:

|        |
||      ||
|||....|||

You need to shift it to get it centred around N/2

     |
    |||
..|||||..

Cheers,
G.


More information about the Digitalmars-d-learn mailing list