Skip to content

One extra array element from Magnitude and Power methods? #68

@MV10

Description

@MV10

I am passing 2048 PCM samples to either FFT.Magnitude or FFT.Power, and I'm getting back 1025 elements instead of 1024.

This isn't a big deal since, of course, most of the "far end" (for music) is zero or near-zero, but I wasn't expecting that. Is this known/expected for some reason? Or am I doing something wrong? Nothing fancy in the code, reading 16-bit short samples via OpenAL:

private void FrequencyProcessing()
{
    // FFT buffer is 2048, "slide" two passes of PCM 1024 data through it.
    // Copy the second half of the FFT buffer "back" to the first half:
    Array.Copy(BufferFFT, BufferLength, BufferFFT, 0, BufferLength);
    // Next, copy new PCM data to the second half of the FFT buffer:
    Array.Copy(BufferPCM, 0, BufferFFT, BufferLength, BufferLength);

    var window = new Hanning();
    double[] windowed = window.Apply(BufferFFT);
    double[] zeroPadded = Pad.ZeroPad(windowed);
    System.Numerics.Complex[] spectrum = FFT.Forward(zeroPadded);

    // this returns 1025 elements?
    BufferFreq = FFT.Magnitude(spectrum);
}

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