示例#1
0
        /// <summary>
        /// Complex to complex transform.
        /// </summary>
        static void Example1(int length)
        {
            Console.Write("Test 1: complex transform ... ");

            // Size is 2 * n because we are dealing with complex numbers.
            int size = 2 * length;

            // Create two managed arrays, possibly misalinged.
            var data = Util.GenerateSignal(size);

            // Copy to native memory.
            var input  = new ComplexArray(data);
            var output = new ComplexArray(size);

            // Create a managed plan as well.
            var plan1 = Plan.Create1(length, input, output, Direction.Forward, Options.Estimate);

            plan1.Execute();

            var plan2 = Plan.Create1(length, output, input, Direction.Backward, Options.Estimate);

            plan2.Execute();

            Array.Clear(data, 0, data.Length);

            // Copy unmanaged output of back-tranform to managed array.
            input.CopyTo(data);

            // Check and see how we did.
            Util.CheckResults(length, length, data);
        }
示例#2
0
        public double[] Spectrum(double[] input, bool scale)
        {
            int length = input.Length;

            var zinput = Helper.ToComplex(input);

            using (var data1 = new ComplexArray(zinput))
                using (var data2 = new ComplexArray(length))
                    using (var plan1 = Plan.Create1(length, data1, data2, Direction.Forward, Options.Estimate))
                        using (var plan2 = Plan.Create1(length, data2, data1, Direction.Backward, Options.Estimate))
                        {
                            plan1.Execute();

                            var temp     = data2.ToArray();
                            var spectrum = Helper.ComputeSpectrum(temp);

                            plan2.Execute();

                            data1.CopyTo(input, true);

                            if (scale)
                            {
                                for (int i = 0; i < length; i++)
                                {
                                    input[i] /= length;
                                }
                            }

                            return(spectrum);
                        }
        }