public int[][] InverseDCT(int[][] matrix) { var sourceDouble = new double[size][]; for (var i = 0; i < size; i++) { sourceDouble[i] = new double[size]; for (var j = 0; j < size; j++) { sourceDouble[i][j] = matrix[i][j] * 1.0; } } var temp = Mt.MultiplyBy(sourceDouble, size); var temp2 = temp.MultiplyBy(M, size); var ans = new int[size][]; for (var i = 0; i < size; i++) { ans[i] = new int[size]; for (var j = 0; j < size; j++) { ans[i][j] = (int)temp2[i][j]; } } return(ans); }
public static Complex[] RealFastFourierTransform(double[] src, double amplitude = 1.0) { int n4 = 1 << (Mt.Log2Int(src.Length) - 2); int n = n4 * 4, n2 = n4 * 2, n3 = n4 * 3; int n2mask = n2 - 1; Complex[] Data = new Complex[n2 + 1]; for (int i = n2; --i >= 0;) { Data[i] = new Complex(src[i * 2], src[i * 2 + 1]); } Complex[] Dst = FastFourierTransform_(Data, true); TriangularTable Triangle = TriangularTable.Get(n); for (int i = n4; i >= 0; --i) { int j = n2 - i; Complex g1 = Dst[i]; Complex g2 = Complex.Conjugate(Dst[j & n2mask]); Complex h1 = (g1 + g2); Complex h2 = (g1 - g2) * Triangle.Complex(n3 - i); Data[i] = (h1 + h2); Data[j] = Complex.Conjugate(h1 - h2); } LetMul(Data, amplitude / 2); return(Data); }
public static double[] GetDataWindow(DataWindowType type, int size) { double[] Table = new double[size]; Table = new double[size]; double h = 2 * Math.PI / (size - 1); switch (type) { case DataWindowType.Box: for (int i = size; --i >= 0;) { Table[i] = 1; } break; case DataWindowType.Hanning: for (int i = size; --i >= 0;) { Table[i] = 0.50 - 0.50 * Math.Cos(h * i); } break; case DataWindowType.Hamming: for (int i = size; --i >= 0;) { Table[i] = 0.54 - 0.46 * Math.Cos(h * i); } break; case DataWindowType.Blackman: for (int i = size; --i >= 0;) { Table[i] = 0.42 - 0.50 * Math.Cos(h * i) + 0.08 * Math.Cos(2 * h * i); } break; case DataWindowType.Parzen: for (int i = size; --i >= 0;) { Table[i] = 1.0 - Math.Abs((i * 2 - (size - 1)) / (double)(size + 1)); } break; case DataWindowType.Welch: for (int i = size; --i >= 0;) { Table[i] = 1.0 - Mt.Sq((i * 2 - (size - 1)) / (double)(size + 1)); } break; } //double c = Math.Sqrt(n / Table.Sum(x => Sq(x))); //for (int i = n; --i >= 0; ) Table[i] *= c; return(Table); }
// Power Spectral Densityを求めたい。nの増加に伴いそれぞれの周波数カラムの幅(Δf)は狭くなるため、結果のData値は増加する // ΣResult != 単位時間辺りのpower // ∫Result df = 単位時間辺りのpower // y=a*sin(x) の結果は、a*a*n/2 振幅はa/2でパワーはa*a/4、one-sidedなので2倍してa*a/2、nは上記 // これは (1/n)*Σ(y*y) の結果と一致する // y=a の結果は a*a*n public static double[] PowerSpectrumFFT(double[] data, double amplitude) { Complex[] Freq = RealFastFourierTransform(data, Math.Sqrt(2 * amplitude / data.Length)); double[] Powr = new double[Freq.Length]; for (int i = Powr.Length; --i >= 0;) { Powr[i] = Mt.Sq(Freq[i].Real) + Mt.Sq(Freq[i].Imaginary); } Powr[0] /= 2; Powr[Powr.Length - 1] /= 2; return(Powr); }
public static Complex[] PowerPhaseSpectrumFFT(double[] data, double amplitude) { Complex[] Freq = RealFastFourierTransform(data, Math.Sqrt(2 * amplitude / data.Length)); Complex[] Powr = new Complex[Freq.Length]; for (int i = Powr.Length; --i >= 0;) { Powr[i] = new Complex(Mt.Sq(Freq[i].Real) + Mt.Sq(Freq[i].Imaginary), Freq[i].Phase); } var a = Powr[0]; Powr[0] = new Complex(a.Real / 2, a.Imaginary); var b = Powr[Powr.Length - 1]; Powr[Powr.Length - 1] = new Complex(b.Real / 2, b.Imaginary); return(Powr); }
private bool DeleteHorizontalLine(int chartId = 0, string name = "HLine") { Mt.ResetLastError(); if (Mt.ObjectDelete(chartId, name)) { return(true); } else { Console.WriteLine(Mt.GetLastError()); return(false); } }
private bool MoveHorizontalLine(int chartId = 0, string name = "HLine", double price = 0) { Mt.ResetLastError(); if (Mt.ObjectMove(chartId, name, 0, DateTime.Now, price)) { return(true); } else { Console.WriteLine(Mt.GetLastError()); return(false); } }
public static BigInteger GreatestCommonDivisor(BigInteger val1, BigInteger val2) { while (true) { if (val1 < val2) { Mt.Swap(ref val1, ref val2); } var z = BigInteger.Remainder(val1, val2); if (z == 0) { break; } val1 = z; } return(val2); }
public void Start() { var subscribeResult = Finex.SubscribeToTickerUpdates("tBTCUSD", data => { var mid = (data.Ask + data.Bid) / 2; if (Mt.ConnectionState != Mt5ConnectionState.Connected && Mt.ConnectionState != Mt5ConnectionState.Connecting) { Mt.BeginConnect(8228); } else if (Mt.ConnectionState == Mt5ConnectionState.Connected) { Console.WriteLine($"Move line to ${mid}"); MoveHorizontalLine(0, "HLine", (double)mid); } }); }
protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response) { EventHandlers.LogCommandUsed((CommandSender)sender, EventHandlers.FormatArguments(arguments, 0)); StringBuilder ListBuilder = new StringBuilder(); ListBuilder.Append("Here are the following enums you can use in commands:\n\nBreakType: "); foreach (BreakType Bt in Enum.GetValues(typeof(BreakType))) { ListBuilder.Append(Bt.ToString()); ListBuilder.Append(" "); } ListBuilder.AppendLine(); ListBuilder.Append("MoveType: "); foreach (MoveType Mt in Enum.GetValues(typeof(MoveType))) { ListBuilder.Append(Mt.ToString()); ListBuilder.Append(" "); } ListBuilder.AppendLine(); ListBuilder.Append("GrenadeType: "); foreach (GrenadeType Gt in Enum.GetValues(typeof(GrenadeType))) { ListBuilder.Append(Gt.ToString()); ListBuilder.Append(" "); } ListBuilder.AppendLine(); ListBuilder.Append("VectorAxis: "); foreach (VectorAxis Va in Enum.GetValues(typeof(VectorAxis))) { ListBuilder.Append(Va.ToString()); ListBuilder.Append(" "); } ListBuilder.AppendLine(); ListBuilder.Append("PositionModifier: "); foreach (PositionModifier Pm in Enum.GetValues(typeof(PositionModifier))) { ListBuilder.Append(Pm.ToString()); ListBuilder.Append(" "); } string message = ListBuilder.ToString(); ListBuilder.Clear(); response = message; return(true); }
//------------------------------------------------------------------------------------- #region Parts //------------------------------------------------------------- //0埋め private static double[] zeroInserting(double[] data) { int size = data.Length; int fixed_size = 1 << Mt.Log2Int(size) + 1; if (fixed_size > size) { double[] outdata = new double[fixed_size]; for (int i = 0; i < size; i++) { outdata[i] = data[i]; } return(outdata); } else { return(data); } }
private bool CreateHorizontalLine(int chartId = 0, string name = "HLine", int subWindow = 0, double price = 0, long color = 16777215, long style = 0, int width = 1, bool back = false, bool selection = true, bool hidden = false, long zOrder = 0) { if (Mt.ObjectCreate(chartId, name, ENUM_OBJECT.OBJ_HLINE, subWindow, DateTime.Now, price)) { Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_COLOR, color); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_STYLE, style); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_WIDTH, width); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_BACK, back ? 1 : 0); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_SELECTABLE, selection ? 1 : 0); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_SELECTED, selection ? 1 : 0); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_HIDDEN, hidden ? 1 : 0); Mt.ObjectSetInteger(chartId, name, ENUM_OBJECT_PROPERTY_INTEGER.OBJPROP_ZORDER, zOrder); return(true); } else { Console.WriteLine(Mt.GetLastError()); return(false); } }
static Complex[] FastFourierTransform_(Complex[] src, bool sw) { int l = Mt.Log2Int(src.Length); int n = 1 << l; Complex[] Data = new Complex[n]; for (int j = -(n >> 1), i = 0; i < n; i++) { int k = n; while ((k >>= 1) <= j) { j -= k; } j += k; Data[i] = src[j]; } int sign = sw ? -1 : 1; TriangularTable Triangle = TriangularTable.Get(n); for (int m = 0; m < l; m++) { int step = 1 << m; int rotw = sign * (1 << (l - 1 - m)); for (int k = 0; k < step; k++) { Complex u = Triangle.Complex(rotw * k); // (2 * Math.PI / n) * rotw * k for (int i = k; i < n; i += step * 2) { Complex t = Data[i + step] * u; Data[i + step] = Data[i] - t; Data[i] += t; } } } return(Data); }
//------------------------------------------------------------------------------------- //STFT(短時間フーリエ変換) public static Complex[,] STFT(double[] source_data, int window_size) { Complex[,] output; int source_length = source_data.Length; //入力データ長 int T_step; //時間ステップ数 int F_step; //周波数ステップ数 int fft_start_point = 0; //fftをするスタート点 double window_power = powerOfwindow(window_size); //窓関数のパワー WN T_step = (int)((source_length - window_size) / window_power) - 1; int n4 = 1 << (Mt.Log2Int(window_size) - 2); int n = n4 * 4, n2 = n4 * 2; F_step = n2 + 1; output = new Complex[F_step, T_step]; for (int t = 0; t < T_step; t++) { double[] data = new double[window_size]; fft_start_point = (int)window_power * t; for (int i = 0; i < window_size; i++) { data[i] = source_data[fft_start_point + i]; } data = windowing(data); Complex[] fft = Nm.RealFastFourierTransform(data); for (int f = 0; f < F_step; f++) { output[f, t] = fft[f]; } } return(output); }
public static double[] RealFastFourierTransform(Complex[] src, double amplitude = 1.0) { int n4 = 1 << (Mt.Log2Int(src.Length) - 1); int n = n4 * 4, n2 = n4 * 2, n3 = n4 * 3; int n2mask = n2 - 1; Complex[] Data = new Complex[n2]; TriangularTable Triangle = TriangularTable.Get(n); for (int i = n4; i >= 0; --i) { int j = n2 - i; Complex g1 = src[i]; Complex g2 = Complex.Conjugate(src[j]); Complex h1 = (g1 + g2); Complex h2 = (g1 - g2) * Triangle.Complex(n4 + i); Data[i] = (h1 + h2); Data[j & n2mask] = Complex.Conjugate(h1 - h2); } Data = FastFourierTransform_(Data, false); LetMul(Data, amplitude / n); double[] Dst = New.Array(n, i => (i & 1) == 0 ? Data[i / 2].Real : Data[i / 2].Imaginary); return(Dst); }