swharden/FftSharp

FFT.ForwardReal() should ensure the input length is a power of 2

swharden opened this issue · 1 comments

one overload does, the other does not

/// <summary>
/// Calculate FFT and return just the real component of the spectrum
/// </summary>
public static System.Numerics.Complex[] ForwardReal(System.Numerics.Complex[] samples)
{
if (!FftOperations.IsPowerOfTwo(samples.Length))
throw new ArgumentException($"{nameof(samples)} length must be a power of 2");
System.Numerics.Complex[] realBuffer = new System.Numerics.Complex[samples.Length / 2 + 1];
FftOperations.RFFT_WithoutChecks(realBuffer, samples);
return realBuffer;
}

/// <summary>
/// Calculate FFT and return just the real component of the spectrum
/// </summary>
public static System.Numerics.Complex[] ForwardReal(double[] samples)
{
System.Numerics.Complex[] buffer = samples.ToComplexArray();
Forward(buffer);
System.Numerics.Complex[] real = new System.Numerics.Complex[samples.Length / 2 + 1];
Array.Copy(buffer, 0, real, 0, real.Length);
return real;
}

Nevermind, ForwardReal() calls Forward() which does the check there