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); }
public FunctionTableItem[] Transform(FunctionTableItem[] original) { FunctionTableItem[] res = DFTransform(original, -1); for(int i = 0 ; i < res.Length ; i++) { res[i].Arg = i; } return res; }
public FunctionTableItem[] Inverse(FunctionTableItem[] image) { FunctionTableItem[] res = DFTransform(image, 1); for(int i = 0 ; i < res.Length ; i++) { res[i].Arg = i; } return res; }
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; }
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); }
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; }
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; }
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; }
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); }
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; }
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; }