/// <summary> /// Заполняет bmp изображением распределения данных сигнала. /// </summary> public static Bitmap FillBmpLogDistribution(float[] Data, int Width, int Height) { Bitmap bmp = new Bitmap(Width, Height); Pen pen = Pens.DarkGreen; Pen penLines = new Pen(Color.FromArgb(128, Color.Black)); Probability prob = new Probability(Data); float Begin = prob.Min - 5; float End = prob.Max + 5; float Length = End - Begin; float delta = Width / Length; float sigma = (float)Math.Sqrt(prob.D); float[] probData = new float[(int)Width]; float probDataMax = 0; for (int i = 0; i < Data.Length; i++) { int index = (int)((Data[i] - Begin) * delta); probData[index]++; if (probDataMax < probData[index]) probDataMax = probData[index]; } for (int i = 0; i < probData.Length; i++) { probData[i] = (float)Math.Log(probData[i] + 1); } probDataMax = (float)Math.Log(probDataMax + 1); float dx = (float)Width / Length; float dy = (float)Height / probDataMax; using (var g = Graphics.FromImage(bmp)) { for (int i = 0; i < probData.Length; i++) { float y2 = (Height - probData[i] * dy); g.DrawLine(pen, i, Height, i, y2); } float x2 = (prob.M - Begin); for (int i = 0; x2 > 0; i++) { float x = x2 * dx; g.DrawLine(penLines, x, 2, x, Height - 2); x2 -= sigma; } } return bmp; }
/// <summary> /// Calculate the minimum of input array using splines /// </summary> public static PointF Minimum(float[] Data, int Offset, int Length) { if(Offset < 0) Offset = 0; if (Data.Length < Offset + Length) Length = Data.Length - Offset; if (Length < 2) return new PointF(Offset, Data[Offset]); int Accuracy = 50; float[] pts = new float[Length]; Probability prob_pts = new Probability(Data, Offset, Length); for (int i = 0; i < Length; i++) pts[i] = Data[Offset + i] - prob_pts.M; float[] data = Spline(pts, 0, Length, Accuracy); float min = data[0]; float imin = 0; for (int i = 1; i < data.Length; i++) { if (min > data[i]) { min = data[i]; imin = i; } } min += prob_pts.M; return new PointF(Offset + imin / Accuracy, min); }
/// <summary> /// Заполняет bmp изображением распределения данных сигнала. /// </summary> public static Bitmap FillBmpDistribution(float[] Data) { int Width = 512; int Height = 256; Bitmap bmp = new Bitmap(Width, Height); Pen pen = Pens.Bisque; Probability prob = new Probability(Data); float Begin = prob.Min; float End = prob.Max; float Length = End - Begin; float delta = Width / Length; int[] probData = new int[Data.Length / 100]; int probDataMax = 0; for (int i = 0; i < Data.Length; i++) { int index = (int)((Data[i] - Begin) * delta); probData[index]++; if(probDataMax < probData[index]) probDataMax = probData[index]; } float dy = (float)Height / probDataMax; using (var g = Graphics.FromImage(bmp)) { for (int i = 0; i < probData.Length; i++) { float y2 = (Height - probData[i] * dy); g.DrawLine(pen, i, Height, i, y2); } } return bmp; }