N step fft in D language
stdin at kraybit.com
Tue Sep 17 04:39:16 PDT 2013
On Sunday, 15 September 2013 at 20:58:54 UTC, Kadir Erdem Demir
> 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:
> 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 ?
Haven't tried this, but looking at the docs it looks like you
auto mySample = getSampleData();
auto fftData0 = fft(mySample[0..512]);
auto fftData1 = fft(mySample[512..1024]);
This would give you the frequency correlation data for two
"windows" in time, and by reading that stackoverflow I assume for
256 frequencies each.
Docs also says there's a class you can reuse if you know the max
size, which should be faster.
auto ffter = new Fft(512);
auto fftData = ffter.fft(chunk);
The FFT size, "N", is the same as the number of samples you
provide it. So the more data you provide, the finer correlation
detail you get. I think it makes sense?
Hmm, what it seems you have done is pass the entire sample
though, which gives you an FFT of size 131072. So you get
phenomenally good detail in frequency correlation, but just one
huge time window—the entire sample! I think what you're simply
looking for is chopping it up into smaller pieces and run fft on
each—that's at least what most audio tools do I believe.
More information about the Digitalmars-d-learn