Esempio n. 1
0
        public FunctionTableItem[] DFTransform(FunctionTableItem[] original, int direction)
        {
            FunctionTableItem[] image = new FunctionTableItem[original.Length];
            Complex             tmp;
            Complex             power;

            for (int i = 0; i < original.Length; i++)
            {
                image[i] = new FunctionTableItem();
            }
            ActionCount = 0;

            for (int n = 0; n < original.Length; n++)
            {
                tmp = new Complex(0, 0);

                for (int k = 0; k < original.Length; k++)
                {
                    ActionCount++;
                    power = direction * 2 * Complex.ImaginaryOne * Math.PI * n * k / original.Length;
                    tmp  += original[k].Value * Complex.Exp(power);
                }
                image[n].Value = tmp / Math.Sqrt((double)original.Length);
            }
            return(image);
        }
Esempio n. 2
0
 public FunctionTableItem[] Transform(FunctionTableItem[] original)
 {
     FunctionTableItem[] res = DFTransform(original, -1);
     for(int i = 0 ; i < res.Length ; i++)
     {
         res[i].Arg = i;
     }
     return res;
 }
Esempio n. 3
0
        public FunctionTableItem[] Inverse(FunctionTableItem[] image)
        {
            FunctionTableItem[] res = DFTransform(image, 1);

            for(int i = 0 ; i < res.Length ; i++)
            {
                res[i].Arg = i;
            }

            return res;
        }
Esempio n. 4
0
        public int Butterfly(FunctionTableItem a, FunctionTableItem b, int n, int m, int direction)
        {
            Complex W = Complex.Exp(direction * Complex.ImaginaryOne * 2 * Math.PI * m / n);
            Complex tempa = a.Value + b.Value;
            Complex tempb = (a.Value - b.Value) * W;

            a.Value = tempa;
            b.Value = tempb;

            this.ActionCount++;

            return 0;
        }
Esempio n. 5
0
        public int Butterfly(FunctionTableItem a, FunctionTableItem b, int n, int m, int direction)
        {
            Complex W     = Complex.Exp(direction * Complex.ImaginaryOne * 2 * Math.PI * m / n);
            Complex tempa = a.Value + b.Value;
            Complex tempb = (a.Value - b.Value) * W;


            a.Value = tempa;
            b.Value = tempb;

            this.ActionCount++;

            return(0);
        }
Esempio n. 6
0
        public FunctionTableItem[] Transform(FunctionTableItem[] original)
        {
            FunctionTableItem[] image;

            image = FTTransform(original, -1);

            image = Swap(image);

            for (int i = 0; i < image.Length; i++)
            {
                image[i].Value /= Math.Sqrt((double) image.Length);
                image[i].Arg = i;
            }

            return image;
        }
Esempio n. 7
0
        public FunctionTableItem[] Inverse(FunctionTableItem[] image)
        {
            FunctionTableItem[] original;

            original = FTTransform(image, 1);

            original = Swap(original);

            for (int i = 0; i < original.Length; i++)
            {
                original[i].Value /= Math.Sqrt((double) original.Length);
                original[i].Arg = i;
            }

            return original;
        }
Esempio n. 8
0
        public FunctionTableItem[] FTTransform(FunctionTableItem[] original, int direction)
        {
            int dist;
            if (original.Length > 1)
            {
                dist = original.Length / 2;

                for (int i = 0; i < dist; i++)
                {
                    Butterfly(original[i], original[i + dist], original.Length, i, direction);
                }
                FTTransform(original.Take(dist).ToArray(), direction).CopyTo(original, 0);
                FTTransform(original.Skip(dist).ToArray(), direction).CopyTo(original, dist);
                /*for(int i = 0 ; i < dist ; i++)
                {
                    original[2*i] = fe[i];
                    original[2*i + 1] = fo[i];
                }*/
            }

            return original;
        }
Esempio n. 9
0
        private FunctionTableItem[] Swap(FunctionTableItem[] toSwap)
        {
            FunctionTableItem[] swapped = new FunctionTableItem[toSwap.Length];
            FunctionTableItem   tmp;

            int[] map;

            map = GetBinaryInvertedList(toSwap.Length);

            for (int i = 0; i < toSwap.Length / 2; i++)
            {
                tmp            = toSwap[i];
                toSwap[i]      = toSwap[map[i]];
                toSwap[map[i]] = tmp;
                toSwap[i].Arg  = i;
            }

            for (int i = 0; i < toSwap.Length; i++)
            {
                toSwap[i].Arg = i;
            }
            return(toSwap);
        }
Esempio n. 10
0
        public FunctionTableItem[] DFTransform(FunctionTableItem[] original, int direction)
        {
            FunctionTableItem[] image = new FunctionTableItem[original.Length];
            Complex tmp;
            Complex power;

            for (int i = 0; i < original.Length; i++ )
                image[i] = new FunctionTableItem();
            ActionCount = 0;

            for (int n = 0; n < original.Length; n++)
            {
                tmp = new Complex(0,0);

                for (int k = 0; k < original.Length; k++)
                {
                    ActionCount++;
                    power = direction * 2 * Complex.ImaginaryOne * Math.PI * n * k / original.Length;
                    tmp += original[k].Value*Complex.Exp(power);
                }
                image[n].Value = tmp / Math.Sqrt((double)original.Length);
            }
            return image;
        }
Esempio n. 11
0
        private FunctionTableItem[] Swap(FunctionTableItem[] toSwap)
        {
            FunctionTableItem[] swapped = new FunctionTableItem[toSwap.Length];
            FunctionTableItem tmp;
            int[] map;

            map = GetBinaryInvertedList(toSwap.Length);

            for(int i = 0 ; i < toSwap.Length/2 ; i++)
            {
                tmp = toSwap[i];
                toSwap[i] = toSwap[map[i]];
                toSwap[map[i]] = tmp;
                toSwap[i].Arg = i;
            }

            for (int i = 0; i < toSwap.Length; i++)
                toSwap[i].Arg = i;
            return toSwap;
        }