Beispiel #1
0
        static void ExampleUsePlanDirectly2d()
        {
            Console.Clear();
            // Use the same arrays for as many transformations as you like.
            // If you can use the same arrays for your transformations, this is faster than calling DFT.FFT / DFT.IFFT
            using (var input = new AlignedArrayDouble(16, 64, 16))
                using (var output = new AlignedArrayDouble(16, input.GetSize()))
                {
                    for (int row = 0; row < input.GetLength(0); row++)
                    {
                        for (int col = 0; col < input.GetLength(1); col++)
                        {
                            input[row, col] = 10;// (double)row * col / input.Length;
                        }
                    }

                    //using (var timeDomain = new FftwArrayDouble(256))
                    //using (var frequencyDomain = new FftwArrayDouble(timeDomain.GetSize()))
                    using (var fft = FftwPlanR2R.Create(input, output, DftDirection.Forwards))
                        using (var ifft = FftwPlanR2R.Create(output, input, DftDirection.Backwards))
                        {
                            // Set the input after the plan was created as the input may be overwritten
                            // during planning
                            for (int row = 0; row < input.GetLength(0); row++)
                            {
                                for (int col = 0; col < input.GetLength(1); col++)
                                {
                                    input[row, col] = col + row;// (double)row * col / input.Length;
                                }
                            }

                            // timeDomain -> frequencyDomain
                            fft.Execute();

                            //for (int i = 0; i < frequencyDomain.Length; i++)
                            //    Console.WriteLine(frequencyDomain[i]);

                            //for (int i = frequencyDomain.Length / 2; i < frequencyDomain.Length; i++)
                            //    frequencyDomain[i] = 0;
                            // frequencyDomain -> timeDomain
                            ifft.Execute();

                            for (int row = 0; row < input.GetLength(0); row++)
                            {
                                for (int col = 0; col < input.GetLength(1); col++)
                                {
                                    Console.Write((input[row, col] / (4 * input.Length)).ToString("F1").PadLeft(8));// (output[row, col] / input[row, col] / input.Length).ToString("F2").PadLeft(6));
                                }
                                //Console.Write(output[row, col].ToString("F2").PadLeft(10));
                                Console.WriteLine();
                            }
                            //for (int i = 0; i < frequencyDomain.Length; i++)
                            //    Console.WriteLine(timeDomain[i]);

                            Console.ReadKey();

                            // Do as many forwards and backwards transformations here as you like
                        }
                }
        }
Beispiel #2
0
        static void ExampleUsePlanDirectly1()
        {
            // Use the same arrays for as many transformations as you like.
            // If you can use the same arrays for your transformations, this is faster than calling DFT.FFT / DFT.IFFT
            using (var timeDomain = new FftwArrayDouble(256))
                using (var frequencyDomain = new FftwArrayDouble(timeDomain.GetSize()))
                    using (var fft = FftwPlanR2R.Create(timeDomain, frequencyDomain, DftDirection.Forwards))
                        using (var ifft = FftwPlanR2R.Create(frequencyDomain, timeDomain, DftDirection.Backwards))
                        {
                            // Set the input after the plan was created as the input may be overwritten
                            // during planning
                            for (int i = 0; i < timeDomain.Length; i++)
                            {
                                timeDomain[i] = i % 16;
                            }

                            // timeDomain -> frequencyDomain
                            fft.Execute();

                            for (int i = 0; i < frequencyDomain.Length; i++)
                            {
                                Console.WriteLine(frequencyDomain[i]);
                            }

                            //for (int i = frequencyDomain.Length / 2; i < frequencyDomain.Length; i++)
                            //    frequencyDomain[i] = 0;
                            Console.ReadKey();
                            Console.Clear();
                            // frequencyDomain -> timeDomain
                            ifft.Execute();

                            for (int i = 0; i < frequencyDomain.Length; i++)
                            {
                                Console.WriteLine(timeDomain[i]);
                            }

                            Console.ReadKey();

                            // Do as many forwards and backwards transformations here as you like
                        }
        }