예제 #1
0
 public FFTWTransform(int size)
 {
     Size          = size;
     _dataOut      = new double[Size / 2];
     DataInPtr     = FFTW.fftw_alloc_real(Size);
     DataOutPtr    = FFTW.fftw_alloc_complex(Size);
     Plan          = FFTW.fftw_plan_dft_r2c(1, ref size, DataInPtr, DataOutPtr, 0);
     _window       = Enumerable.Range(0, Size).Select(n => WindowFunction(n, Size)).ToArray();
     _windowFactor = 1 / Math.Pow(_window.Average(), 2);
 }
예제 #2
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // managed
                }

                // unamanaged
                FFTW.fftw_free(Plan);

                disposedValue = true;
            }
        }
예제 #3
0
        public double[] Transform()
        {
            FFTW.fftw_execute(Plan);

            unsafe {
                var pOut = (double *)DataOutPtr;
                for (var i = 0; i < _dataOut.Length; i++)
                {
                    var real = *(pOut + 0);
                    var imag = *(pOut + 1);

                    _dataOut[i] = Math.Sqrt(real * real + imag * imag);

                    pOut += 2;
                }
            }

            // https://www.wavemetrics.com/products/igorpro/dataanalysis/signalprocessing/powerspectra.htm
            Core.Multiply_IV64fS64f_IV64f(_dataOut, 0, 1 * _windowFactor / (double)Size, _dataOut.Length);

            return(_dataOut);
        }