Exemplo n.º 1
0
        public void SpanDftTheory(Complex[] signalExpected, Complex[] spectrumExpected)
        {
            int            windowSize = signalExpected.Length;
            IFftCalculator calculator = CreateCalculator(windowSize);

            Span <double> signalExpectedReal      = stackalloc double[windowSize];
            Span <double> signalExpectedImaginary = stackalloc double[windowSize];
            ComplexSpan   signalExpectedSpan      = new ComplexSpan(signalExpectedReal, signalExpectedImaginary);

            signalExpected.CopyTo(signalExpectedSpan);
            Span <double> spectrumExpectedReal      = stackalloc double[windowSize];
            Span <double> spectrumExpectedImaginary = stackalloc double[windowSize];
            ComplexSpan   spectrumExpectedSpan      = new ComplexSpan(spectrumExpectedReal, spectrumExpectedImaginary);

            spectrumExpected.CopyTo(spectrumExpectedSpan);

            Span <double> signalActualReal        = stackalloc double[windowSize];
            Span <double> signalActualImaginary   = stackalloc double[windowSize];
            ComplexSpan   signalActualSpan        = new ComplexSpan(signalActualReal, signalActualImaginary);
            Span <double> spectrumActualReal      = stackalloc double[windowSize];
            Span <double> spectrumActualImaginary = stackalloc double[windowSize];
            ComplexSpan   spectrumActualSpan      = new ComplexSpan(spectrumActualReal, spectrumActualImaginary);

            calculator.DFT(signalExpectedSpan, spectrumActualSpan);
            Assert.Equal(spectrumExpected, spectrumActualSpan.ToArray(), complexComparer);

            calculator.IDFT(spectrumActualSpan, signalActualSpan);
            Assert.Equal(signalExpected, signalActualSpan.ToArray(), complexComparer);
        }
Exemplo n.º 2
0
        public void ArrayDftTheory(Complex[] signalExpected, Complex[] spectrumExpected)
        {
            int            windowSize = signalExpected.Length;
            IFftCalculator calculator = CreateCalculator(windowSize);

            Complex[] spectrumActual = new Complex[windowSize];
            calculator.DFT(signalExpected, spectrumActual);
            Assert.Equal(spectrumExpected, spectrumActual, complexComparer);

            Complex[] signalActual = new Complex[windowSize];
            calculator.IDFT(spectrumActual, signalActual);
            Assert.Equal(signalExpected, signalActual, complexComparer);
        }