Ejemplo n.º 1
0
        private void MyRoutine2(double[] real1, FourierDirection dir)
        {
            int n   = real1.Length;
            var rnd = new System.Random();

            double[] real2 = new double[n];
            for (int i = 0; i < n; i++)
            {
                real2[i] = rnd.NextDouble() / n;
            }

            var fft = new Pfa235FFT(n);

            fft.RealFFT(real2, real1, dir);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a inplace fourier transformation. The original values are overwritten by the fourier transformed values.
        /// </summary>
        /// <param name="arr">The data to transform. On output, the fourier transformed data.</param>
        /// <param name="direction">Specify forward or reverse transformation here.</param>
        public void Transform(double[] arr, FourierDirection direction)
        {
            if (arr.Length != _numberOfData)
            {
                throw new ArgumentException(string.Format("Length of array arr ({0}) is different from the length specified at construction ({1})", arr.Length, _numberOfData), "arr");
            }

            switch (_method)
            {
            case Method.Trivial:
            {
                if (_numberOfData == 2)
                {
                    double a0 = arr[0], a1 = arr[1];
                    arr[0] = a0 + a1;
                    arr[1] = a0 - a1;
                }
            }
            break;

            case Method.Hartley:
            {
                FastHartleyTransform.RealFFT(arr, direction);
            }
            break;

            case Method.Pfa235:
            {
                NullifyTempArrN1();

                _pfa235.RealFFT(arr, _tempArr1N, direction);
            }
            break;

            case Method.Chirp:
            {
                if (direction == FourierDirection.Forward)
                {
                    NullifyTempArrN1();
                }
                else
                {
                    if (null == this._tempArr1N)
                    {
                        _tempArr1N = new double[_numberOfData];
                    }

                    _tempArr1N[0] = 0;
                    for (int k = 1; k <= _numberOfData / 2; k++)
                    {
                        double sumreal = arr[k];
                        double sumimag = arr[_numberOfData - k];

                        _tempArr1N[k] = sumimag;
                        _tempArr1N[_numberOfData - k] = -sumimag;
                        arr[_numberOfData - k]        = sumreal;
                    }
                }

                ChirpFFT.FFT(arr, _tempArr1N, direction, ref _fftTempStorage);

                if (direction == FourierDirection.Forward)
                {
                    for (int k = 0; k <= _numberOfData / 2; k++)
                    {
                        double sumreal = arr[k];
                        double sumimag = _tempArr1N[k];

                        if (k != 0 && (k + k) != _numberOfData)
                        {
                            arr[_numberOfData - k] = sumimag;
                        }
                        arr[k] = sumreal;
                    }
                }
            }
            break;
            }
        }