Exemple #1
0
 /// <summary>
 /// The inverse of a FFT (Fast Fourier Transform).
 /// </summary>
 /// <param name="complex">An array of complex data (real amplitude and imaginary phase).
 /// For each complex pair the index is the real part and the value is the imaginary part.</param>
 /// <returns>An array of inverse FFT values or "FAILED".</returns>
 public static Primitive FFTInverse(Primitive complex)
 {
     try
     {
         Type PrimitiveType = typeof(Primitive);
         Dictionary <Primitive, Primitive> dataMap;
         dataMap = (Dictionary <Primitive, Primitive>)PrimitiveType.GetField("_arrayMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.Instance).GetValue(complex);
         int       length      = dataMap.Count;
         Complex[] complexData = new Complex[length];
         int       i           = 0;
         foreach (KeyValuePair <Primitive, Primitive> kvp in dataMap)
         {
             string[] values    = ((string)kvp.Value).Split(new char[] { '=', ';' });
             double   real      = double.Parse(values[0]);
             double   imaginary = double.Parse(values[1]);
             complexData[i++] = new Complex(real, imaginary);
         }
         Fourier.BluesteinInverse(complexData, FourierOptions.Default);
         string result = "";
         for (i = 0; i < length; i++)
         {
             result += (i + 1).ToString() + "=" + complexData[i].Real.ToString(CultureInfo.InvariantCulture) + ";";
         }
         return(Utilities.CreateArrayMap(result));
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
         return("FAILED");
     }
 }
        public void FourierBluesteinIsReversible(FourierOptions options)
        {
            var samples = Generate.RandomComplex(0x7FFF, GetUniform(1));
            var work    = new Complex[samples.Length];

            samples.CopyTo(work, 0);

            Fourier.BluesteinForward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            Fourier.BluesteinInverse(work, options);
            AssertHelpers.AlmostEqual(samples, work, 10);
        }
Exemple #3
0
        public void Backward(Complex32[] spectrum, FourierTransformScaling scaling)
        {
            switch (scaling)
            {
            case FourierTransformScaling.SymmetricScaling:
                Fourier.BluesteinInverse(spectrum, FourierOptions.Default);
                break;

            case FourierTransformScaling.BackwardScaling:
                Fourier.BluesteinInverse(spectrum, FourierOptions.AsymmetricScaling);
                break;

            default:
                Fourier.BluesteinInverse(spectrum, FourierOptions.NoScaling);
                break;
            }
        }
        public void BackwardInplace(Complex[] complex, FourierTransformScaling scaling)
        {
            switch (scaling)
            {
            case FourierTransformScaling.SymmetricScaling:
                Fourier.BluesteinInverse(complex, FourierOptions.Default);
                break;

            case FourierTransformScaling.BackwardScaling:
                Fourier.BluesteinInverse(complex, FourierOptions.AsymmetricScaling);
                break;

            default:
                Fourier.BluesteinInverse(complex, FourierOptions.NoScaling);
                break;
            }
        }
Exemple #5
0
        public void Forward(Complex[] samples, FourierTransformScaling scaling)
        {
            switch (scaling)
            {
            case FourierTransformScaling.SymmetricScaling:
                Fourier.BluesteinForward(samples, FourierOptions.Default);
                break;

            case FourierTransformScaling.ForwardScaling:
                // Only backward scaling can be expressed with options, hence the double-inverse
                Fourier.BluesteinInverse(samples, FourierOptions.AsymmetricScaling | FourierOptions.InverseExponent);
                break;

            default:
                Fourier.BluesteinForward(samples, FourierOptions.NoScaling);
                break;
            }
        }