Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

DFT functions in AForge.Math.FourierTransform and Accord.Math.Transforms #257

Closed
conaonda opened this issue Jun 28, 2016 · 3 comments
Closed

Comments

@conaonda
Copy link

conaonda commented Jun 28, 2016

for simple complex array [ 3+1i 9+14i 11+7i 40+31i]..

Accord.Math.Transforms.FourierTransform2.DFT(Forward) changes the array to
[ 63+53i -25+25i -35-37i 9-37i ]

AForge.Math.FourierTransform.DFT(Forward) changes the array to
[ 0.75+0.25i 2.25+3.5i 2.75+1.75i 10+7.75i ]

In Matlab answers same value with Accord.Math.Transforms.FourierTransform2.DFT.

Their function bodies(Accord and AForge) are almost same but direction is reversed.

And backward return operation of AForge may be incorrect.

In Accord..

        for (int i = 0; i < c.Length; i++)
        {
            ...
            c[i] = new Complex(sumRe, sumIm);
        }

        if (direction == FourierTransform.Direction.Backward)
        {
            for (int i = 0; i < c.Length; i++)
                data[i] = c[i] / n;
        }
        else
        {
            ...
        }

but AForge..

        for (int i = 0; i < dst.Length; i++)
        {
            for (int j = 0; j < data.Length; j++)
            {
                ...
                dst[i] += new Complex(re, im);
            }
        }

        // copy elements
        if (direction == Direction.Forward) //<< reversed direction
        {
            // devide also for forward transform
            for (int i = 0; i < data.Length; i++)
                data[i] /= n; //<< not using "dst" array
        }
        else
        {
            ...
        }

I think it needs to be validate.

(why same functions are exist?)

@DiegoCatalano
Copy link
Contributor

Hello @conaonda,

The new version of dft/fft (Accord.NET) was coded for the compatibility with the Matlab. The old version (AForge.NET) exists only for the compatibility with the rest of the AForge.NET. I recommend to use the version of the Accord.NET because the fft can handle with size different of the power of 2.

There is differents scales for the directions. The matlab uses Asymmetric scale.

@cesarsouza
Copy link
Member

Exactly, thanks @DiegoCatalano for the explanation! I will keep this issue open until I mark the AForge.NET implementation as obsolete and add more information about it in the documentation.

@cesarsouza cesarsouza reopened this Jul 3, 2016
cesarsouza added a commit that referenced this issue Sep 29, 2017
Updates:
- GH-257: DFT functions in AForge.Math.FourierTransform and Accord.Math.Transforms
- GH-500: Add an Example for FourierTransform2.FFT Method (Complex[], FourierTransform.Direction) doc-request
- GH-560: Add an Example for FourierTransform2.FFT Method (Double[], Double[], FourierTransform.Direction) doc-request
- GH-665: Add an Example for FourierTransform.FFT Method doc-request
@cesarsouza
Copy link
Member

cesarsouza commented Oct 22, 2017

The documentation for Accord.Math.FourierTransform has been updated. It now contains a pointer to FourierTransform2 explaining the limitations of the FourierTransform class and that FourierTransform2 should be preferred when trying to achieve compatibility with Octave and MATLAB implementations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants