www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - fft and isPowerOf2?

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

this applications throws an error in std.numeric (Line 2826).
=> assert(isPowerOf2(range.length));

-----------
module std.numeric

void fftImplPureReal(Ret, R)(R range, Ret buf) const
     in
     {
         assert(range.length >= 4);
         assert(isPowerOf2(range.length));
     }
-----------

The application is rewritten from python (numpy).
How can I workaround this issue? Isn't it possible to give an 
arbitrary length
of data to fft like in numpy?

import std.numeric;
import std.datetime.stopwatch;
import std.stdio: writeln;
import std.random;
import std.array : array;
import std.range : generate, takeExactly;

void fourierTest(int samplingRate)
{
     auto sw = StopWatch(AutoStart.yes);

     foreach(n; 0..60 * 24)
     {
         sw.stop();
         double[] x = generate!(() => 
uniform01).takeExactly(samplingRate * 60).array;
         sw.start();

         writeln(x);
         auto y = fft(x);
     }

     sw.stop();
     writeln("microseconds: ", sw.peek.total!"usecs");
}

void main()
{
     fourierTest(50);
}

Kind regards
André
May 17 2018
parent reply kdevel <kdevel vogtner.de> writes:
On Thursday, 17 May 2018 at 12:34:25 UTC, Andre Pany wrote:
 this applications throws an error in std.numeric (Line 2826).
 => assert(isPowerOf2(range.length));
 Isn't it possible to give an arbitrary length
 of data to fft like in numpy?
There is a mathematical background which is well explained here: https://math.stackexchange.com/questions/77118/non-power-of-2-ffts#77152
May 17 2018
parent Andre Pany <andre s-e-a-p.de> writes:
On Thursday, 17 May 2018 at 13:36:39 UTC, kdevel wrote:
 On Thursday, 17 May 2018 at 12:34:25 UTC, Andre Pany wrote:
 this applications throws an error in std.numeric (Line 2826).
 => assert(isPowerOf2(range.length));
 Isn't it possible to give an arbitrary length
 of data to fft like in numpy?
There is a mathematical background which is well explained here: https://math.stackexchange.com/questions/77118/non-power-of-2-ffts#77152
Thanks a lot for the details link. Kind regards André
May 17 2018