Skip to content

Input length smaller than 16 #62

@arthurits

Description

@arthurits

It seems that this library currently doesn't support input signals whose length is smaller that 16 elements.
As far as I can see, this might be due to the use of ArrayPool here:

Complex[] temp = ArrayPool<Complex>.Shared.Rent(input.Length);

which allocates arrays of lengths: 16, 32, 64, 128, 256, 512, 1,024, 2,048, 4,096, 8,192, 16,384, 3,2768, 65,536, 131,072, 262,144, 524,288 and 1,048,576 elements.

Signal inputs for FFT are usually greater than 16 in length, but there might be still some use cases (ie: for testing or educational purposes) where smaller inputs are FFT-ed.

I believe this could be easily incorporated by adding the following line after the previous one:

Span<Complex> buffer = temp.AsSpan(0, input.Length);

Should the above suggestion be considered, it would also be necessary to modify the 16-element-length check here:

public static void FFTmagnitude(Span<double> destination, Span<double> input)
{
if (input.Length < 16)
throw new ArgumentException("This overload requires an input with at least 16 points");

Maybe something like this?

if (input.Length < 2)
    throw new ArgumentException("Input should have 2 points at least");

Would like to hearing your thoughts before attempting any PR, @swharden.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions