Exemplo n.º 1
0
        public void testing_collection(System.Windows.Forms.TextBox textbox)
        {
            // Collection testing
            if (textbox != null)
            {
                textbox.Text += "Collection testing" + System.Environment.NewLine;
            }

            cc = new nkcore.Types.Collection(2);

            cc.set_VectorName(0, "test1");
            cc.set_VectorName(1, "test2");
            cc.set_VectorVisibility(1, false);

            cc.Add(0, 1); cc.Add(1, 11);
            cc.Add(0, 2); cc.Add(1, 22);
            cc.Add(0, 3); cc.Add(1, 33);
            cc.Add(0, 4); cc.Add(1, 44);

            cc.Load_TextFile("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);
            cc.Save_TextFile("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(002)_s_pr1__.txt", null);
            Console.WriteLine("Collection - done");
            if (textbox != null)
            {
                textbox.Text += "Collection - done" + System.Environment.NewLine;
            }
        }
Exemplo n.º 2
0
        public void testing_AllanVariance(System.Windows.Forms.TextBox textbox, ref bool isBreak)
        {
            // Regression testing
            if ( textbox != null ) textbox.Text += "Regression testing";
            nkcore.Types.Collection base_collection = new nkcore.Types.Collection("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);

            nkcore.Types.Collection dd = nkcore.Math.AllanVariance( base_collection, ref isBreak );
        }
Exemplo n.º 3
0
        public void testing_regression( System.Windows.Forms.TextBox textbox, Chart chart)
        {
            // Regression testing
            if ( textbox != null ) textbox.Text += "Regression testing";
            nkcore.Types.Collection base_collection = new nkcore.Types.Collection("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);

            //nkcore.Types.Collection base_collection = new nkcore.Types.Collection(2);
            //base_collection.Add(0,0);  base_collection.Add(1,0);
            //base_collection.Add(0,1);  base_collection.Add(1,0.5);
            //base_collection.Add(0,2);  base_collection.Add(1,1);

            nkcore.Types.Collection c1 = base_collection.get_SubCollection(new int[]{0});
            nkcore.Types.Collection c2 = base_collection.get_SubCollection(new int[]{1, 2, 3, 4});
            int []power_array = new int[]{0, 1, 2, 3, 4};

            double [][]res = nkcore.Math.Regression(c1, c2, power_array);
            for ( int i = 0 ; i < c2.VectorsCount; i++)
            {
                System.Console.WriteLine("  vector1  = ");
                if ( textbox != null ) textbox.Text += System.Environment.NewLine + "  vector" + i.ToString() + "  = ";

                for ( int k = 0; k < power_array.Length; k++ )
                {
                    System.Console.Write(res[i][k].ToString("f9") + "\t");
                    if ( textbox != null ) textbox.Text += res[i][k].ToString("f9") + "\t";
                }
            }

            System.Console.WriteLine("");
            if ( textbox != null ) textbox.Text += System.Environment.NewLine;
            if ( textbox != null ) textbox.Text += System.Environment.NewLine;

            List<double> correctionResult       = new List<double>();
            List<double> correctionResult_error = new List<double>();

            for ( int i = 0; i < c1[0].Count; i++)
            {
                double value = 0;
                for ( int k = 0;  k < c2.VectorsCount; k++)
                {
                    for ( int z = 0; z < power_array.Length; z++ )
                    {
                        value += res[k][z] * Math.Pow( c2[k][i] , power_array[z]);
                    }
                }

                correctionResult.Add(value);
                correctionResult_error.Add((c1[0][i] - value)/0.035*3600.0);
            }

            chart.Series[0].Points.DataBindY(c1[0]);
            chart.Series[1].Points.DataBindY(correctionResult);
            chart.Series[2].Points.DataBindY(correctionResult_error);
        }
Exemplo n.º 4
0
        public void testing_AllanVariance(System.Windows.Forms.TextBox textbox, ref bool isBreak)
        {
            // Regression testing
            if (textbox != null)
            {
                textbox.Text += "Regression testing";
            }
            nkcore.Types.Collection base_collection = new nkcore.Types.Collection("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);

            nkcore.Types.Collection dd = nkcore.Math.AllanVariance(base_collection, ref isBreak);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Низкочастотный фильтр
        /// </summary>
        /// <param name="t0">Время дискретизации</param>
        /// <param name="freq">Частота среза</param>
        /// <param name="hMax">Максимальная высока подъема</param>
        public filter_loPass(double t0, double freq, double hMax)
        {
            coefs = new Types.Collection(2);

            double Alfa = System.Math.Pow(System.Math.Tan(freq * t0 / 2.0 * 2.0 * System.Math.PI), 2.0);

            double A = System.Math.Sqrt(Alfa / (hMax * hMax - 0.5));
            double B = hMax * hMax * A * A;

            coefs.Add(0, B);
            coefs.Add(0, 2 * B);
            coefs.Add(0, B);

            coefs.Add(1, 1 + A + B);
            coefs.Add(1, -2 * (1 - B));
            coefs.Add(1, 1 - A + B);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Низкочастотный фильтр
        /// </summary>
        /// <param name="t0">Время дискретизации</param>
        /// <param name="freq">Частота среза</param>
        /// <param name="hMax">Максимальная высока подъема</param>
        public filter_loPass(double t0, double freq, double hMax)
        {
            coefs = new Types.Collection(2);

            double Alfa = System.Math.Pow(System.Math.Tan(freq* t0 / 2.0 * 2.0 * System.Math.PI), 2.0);

            double A = System.Math.Sqrt(Alfa / (hMax*hMax - 0.5));
            double B = hMax*hMax*A*A;

            coefs.Add(0, B  );
            coefs.Add(0, 2*B);
            coefs.Add(0, B  );

            coefs.Add(1, 1+A+B   );
            coefs.Add(1, -2*(1-B));
            coefs.Add(1, 1-A+B   );
        }
Exemplo n.º 7
0
        public void testing_collection(System.Windows.Forms.TextBox textbox)
        {
            // Collection testing
            if ( textbox != null ) textbox.Text += "Collection testing" + System.Environment.NewLine;

            cc = new nkcore.Types.Collection(2);

            cc.set_VectorName(0, "test1");
            cc.set_VectorName(1, "test2");
            cc.set_VectorVisibility(1, false);

            cc.Add(0, 1); cc.Add(1, 11);
            cc.Add(0, 2); cc.Add(1, 22);
            cc.Add(0, 3); cc.Add(1, 33);
            cc.Add(0, 4); cc.Add(1, 44);

            cc.Load_TextFile("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);
            cc.Save_TextFile("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(002)_s_pr1__.txt", null);
            Console.WriteLine("Collection - done");
            if ( textbox != null ) textbox.Text += "Collection - done" + System.Environment.NewLine;
        }
Exemplo n.º 8
0
        public static Types.Collection AllanVariance(nkcore.Types.Collection input, ref bool isBreak)
        {
            Types.Collection Result_Array = new Types.Collection();
            Types.Collection CurrData     = new Types.Collection();

            double invert_sqrt_2 = 1.0 / System.Math.Sqrt(2.0);

            int    input_ValsCount = input[0].Count;
            int    CountAlanPoint  = input[0].Count / 10;
            int    SumCounter;
            double CurrentSum;

            //if ( pb != NULL )
            //{
            //    pb->Position = 0;
            //    pb->Max =  CountAlanPoint;
            //}

            for (int i = 0; i < CountAlanPoint; i++)
            {
                CurrData.Clear();
                // ---------
                double OldSum = 0;
                for (int k = 0; k < input_ValsCount; k = k + (i + 1))
                {
                    SumCounter = 0;
                    CurrentSum = 0;
                    for (int z = k; z < k + (i + 1); z++)
                    {
                        if (z <= input_ValsCount - 1)
                        {
                            CurrentSum = CurrentSum + input[0][z];
                            SumCounter++;
                        }
                    }

                    CurrentSum = CurrentSum / (float)SumCounter;
                    // ---------- Разность соседних сумм -----
                    if (k > 0)
                    {
                        CurrData.Add(CurrentSum - OldSum);
                    }
                    // ----------
                    OldSum = CurrentSum;
                }

                double Mean = CurrData.Vectors[0].get_Mean();
                double SCO  = CurrData.Vectors[0].get_SCO(0, CurrData[0].Count, Mean) * invert_sqrt_2;

                Result_Array.Add(SCO);

                //if ( pb != NULL ) pb->Position = i;
                System.Windows.Forms.Application.DoEvents();


                if (isBreak == true)
                {
                    return(Result_Array);
                }
            }


            return(Result_Array);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Считает коэфициенты регрессии для "У" набором данных "Х"
        /// </summary>
        /// <param name="x">Набор данных Х</param>
        /// <param name="y">К чему стремимся</param>
        /// <param name="power">Степенной ряд, для которого делаем счет</param>
        /// <returns></returns>
        public static double [][] Regression(nkcore.Types.Collection y, nkcore.Types.Collection x, int[] powers)
        {
            if (x == null)
            {
                throw new Exception("(x) is null");
            }
            if (y == null)
            {
                throw new Exception("(y) is null");
            }
            if (powers == null)
            {
                throw new Exception("(powers) is null");
            }
            if (powers.Length >= y[0].Count)
            {
                throw new Exception("Length is small");
            }

            int ValuesCount  = y[0].Count;
            int xParamCount  = x.VectorsCount;
            int PolinomLevel = powers.Length;

            double [][] result = new double[xParamCount][];
            for (int i = 0; i < xParamCount; i++)
            {
                result[i] = new double[PolinomLevel];
            }

            nkcore.Types.Matrix XMat = new nkcore.Types.Matrix(ValuesCount, PolinomLevel * xParamCount);
            nkcore.Types.Matrix YMat = new nkcore.Types.Matrix(ValuesCount, 1);
            nkcore.Types.Matrix K    = new Types.Matrix();

            for (int i = 0; i < ValuesCount; i++)
            {
                YMat[i][0] = y[0][i];
            }

            for (int i = 0; i < ValuesCount; i++)
            {
                for (int z = 0; z < xParamCount; z++)
                {
                    for (int k = 0; k < PolinomLevel; k++)
                    {
                        XMat[i][k + z * (PolinomLevel)] = System.Math.Pow(x[z][i], powers[k]);
                    }
                }
            }


            K = (XMat.Transpose() * XMat).Inverse() * XMat.Transpose() * YMat;

            // ---------- K.Rows
            for (int i = 0; i < xParamCount; i++)
            {
                for (int k = 0; k < PolinomLevel; k++)
                {
                    result[i][k] = K[k + i * PolinomLevel][0];
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Расчет АЧХ/ФЧХ, по входному полиному (X/Y)
        /// </summary>
        /// <param name="begin_decad">Целое число - начальная декада</param>
        /// <param name="end_decad">Целое число - конечная декада</param>
        /// <param name="in_num_denum">Входной масив данных, вектор "0" - числитель полинома, вектор "1" - знаменатель полинома</param>
        /// <returns>Результат вычилений, вектор "0" - частота, вектор "1" - АЧХ, вектор "2" - ФЧХ</returns>
        public static nkcore.Types.Collection Frequency_responce(double begin_freq, double end_freq, double t0, nkcore.Types.Collection in_num_denum)
        {
            if (in_num_denum == null)
            {
                return(null);
            }

            nkcore.Types.Collection result = new Types.Collection(3);

            // preparing frequency list
            double b_decad = System.Math.Floor(System.Math.Log(begin_freq - 0.0001) / System.Math.Log(10));
            double e_decad = System.Math.Floor(System.Math.Log(end_freq + 0.0001) / System.Math.Log(10));

            int    count_decad             = Convert.ToInt32(e_decad - b_decad);
            int    screen_width            = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            double count_points_inOneDecad = screen_width / count_decad;

            // ------ Frequency List ------------
            for (int n = 0; n < count_decad; n++)
            {
                for (int k = 0; k < count_points_inOneDecad; k++)
                {
                    result.Add(0, System.Math.Pow(10, (k / count_points_inOneDecad) + n + b_decad));
                }
            }

            int vector_legth = result.Vectors[0].data.Count;
            int num_length   = in_num_denum.Vectors[0].data.Count;
            int denum_length = in_num_denum.Vectors[1].data.Count;

            for (int i = 0; i < vector_legth; i++)
            {
                double freq = result[0][i] + 1e-6;

                double Re1 = 0.0;
                double Im1 = 0.0;
                double Re2 = 0.0;
                double Im2 = 0.0;
                //double aOmega = 2 / T0 * Math::ArcTan2(T0 * aLambda, 2);
                double aOmega = freq;

                for (int k = 0; k < num_length; k++)
                {
                    double value = in_num_denum[0][k];
                    Re1 += value * System.Math.Cos(k * aOmega * t0 * 2 * System.Math.PI);
                    Im1 -= value * System.Math.Sin(k * aOmega * t0 * 2 * System.Math.PI);
                }

                for (int k = 0; k < denum_length; k++)
                {
                    double value = in_num_denum[1][k];
                    Re2 += value * System.Math.Cos(k * aOmega * t0 * 2 * System.Math.PI);
                    Im2 -= value * System.Math.Sin(k * aOmega * t0 * 2 * System.Math.PI);
                }

                double val1;
                double val2;
                try {
                    val1 = 20.0 * System.Math.Log10(System.Math.Sqrt(Re1 * Re1 + Im1 * Im1) / System.Math.Sqrt(Re2 * Re2 + Im2 * Im2));
                    val2 = System.Math.Atan2(Im1, Re1) - System.Math.Atan2(Im2, Re2);
                } catch {
                    val1 = 0.0;
                    val2 = 0.0;
                }

                result.Add(1, val1);
                result.Add(2, val2);
            }

            return(result);
        }
Exemplo n.º 11
0
        public void testing_regression(System.Windows.Forms.TextBox textbox, Chart chart)
        {
            // Regression testing
            if (textbox != null)
            {
                textbox.Text += "Regression testing";
            }
            nkcore.Types.Collection base_collection = new nkcore.Types.Collection("E:\\.PersonalProjects\\CSharp\\.Library\\.Data\\01-0078_(810).exp(001)_s_pr1.txt", null);

            //nkcore.Types.Collection base_collection = new nkcore.Types.Collection(2);
            //base_collection.Add(0,0);  base_collection.Add(1,0);
            //base_collection.Add(0,1);  base_collection.Add(1,0.5);
            //base_collection.Add(0,2);  base_collection.Add(1,1);

            nkcore.Types.Collection c1 = base_collection.get_SubCollection(new int[] { 0 });
            nkcore.Types.Collection c2 = base_collection.get_SubCollection(new int[] { 1, 2, 3, 4 });
            int [] power_array         = new int[] { 0, 1, 2, 3, 4 };

            double [][] res = nkcore.Math.Regression(c1, c2, power_array);
            for (int i = 0; i < c2.VectorsCount; i++)
            {
                System.Console.WriteLine("  vector1  = ");
                if (textbox != null)
                {
                    textbox.Text += System.Environment.NewLine + "  vector" + i.ToString() + "  = ";
                }

                for (int k = 0; k < power_array.Length; k++)
                {
                    System.Console.Write(res[i][k].ToString("f9") + "\t");
                    if (textbox != null)
                    {
                        textbox.Text += res[i][k].ToString("f9") + "\t";
                    }
                }
            }

            System.Console.WriteLine("");
            if (textbox != null)
            {
                textbox.Text += System.Environment.NewLine;
            }
            if (textbox != null)
            {
                textbox.Text += System.Environment.NewLine;
            }

            List <double> correctionResult       = new List <double>();
            List <double> correctionResult_error = new List <double>();

            for (int i = 0; i < c1[0].Count; i++)
            {
                double value = 0;
                for (int k = 0; k < c2.VectorsCount; k++)
                {
                    for (int z = 0; z < power_array.Length; z++)
                    {
                        value += res[k][z] * Math.Pow(c2[k][i], power_array[z]);
                    }
                }

                correctionResult.Add(value);
                correctionResult_error.Add((c1[0][i] - value) / 0.035 * 3600.0);
            }

            chart.Series[0].Points.DataBindY(c1[0]);
            chart.Series[1].Points.DataBindY(correctionResult);
            chart.Series[2].Points.DataBindY(correctionResult_error);
        }
Exemplo n.º 12
0
        public Form1()
        {
            InitializeComponent();


            int t1 = System.Environment.TickCount;

            this.StartPosition = FormStartPosition.CenterScreen;
            this.Text          = (System.Environment.TickCount - t1).ToString();

            chart1.ChartAreas.Clear();
            chart1.Series.Clear();

            chart1.ChartAreas.Add(new ChartArea("First"));
            chart1.ChartAreas.Add(new ChartArea("Second"));

            Series series1 = new Series();
            Series series2 = new Series();
            Series series3 = new Series();

            series1.Color     = Color.Blue;
            series1.ChartArea = "First";
            series1.ChartType = SeriesChartType.FastLine;

            series2.Color     = Color.Yellow;
            series2.ChartArea = "First";
            series2.ChartType = SeriesChartType.FastLine;

            series3.Color     = Color.Blue;
            series3.ChartArea = "Second";
            series3.ChartType = SeriesChartType.FastLine;

            chart1.Series.Add(series1);
            chart1.Series.Add(series2);
            chart1.Series.Add(series3);


            //////
            for (int i = 0; i < chart1.ChartAreas.Count; i++)
            {
                chart1.ChartAreas[i].Visible         = true;
                chart1.ChartAreas[i].BorderWidth     = 2;
                chart1.ChartAreas[i].BorderDashStyle = ChartDashStyle.Solid;

                //chart1.ChartAreas[i].AxisX.ArrowStyle        = AxisArrowStyle.Triangle;
                chart1.ChartAreas[i].AxisX.IsLogarithmic      = false;
                chart1.ChartAreas[i].AxisX.IsStartedFromZero  = false;
                chart1.ChartAreas[i].AxisX.LineColor          = Color.Red;
                chart1.ChartAreas[i].AxisX.LabelStyle.Enabled = false;

                //chart1.ChartAreas[i].AxisY.ArrowStyle        = AxisArrowStyle.Triangle;
                chart1.ChartAreas[i].AxisY.IsLogarithmic     = false;
                chart1.ChartAreas[i].AxisY.IsStartedFromZero = false;
                chart1.ChartAreas[i].AxisY.LineColor         = Color.Red;

                chart1.ChartAreas[i].AxisY.MajorGrid.Enabled   = false;
                chart1.ChartAreas[i].AxisX.MajorGrid.Enabled   = false;
                chart1.ChartAreas[i].AxisY.MajorGrid.LineWidth = 1;

                chart1.ChartAreas[i].AxisX.MinorGrid.Enabled       = true;
                chart1.ChartAreas[i].AxisX.MinorGrid.LineColor     = Color.Silver;
                chart1.ChartAreas[i].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dash;

                chart1.ChartAreas[i].AxisY.MinorGrid.Enabled       = true;
                chart1.ChartAreas[i].AxisY.MinorGrid.LineColor     = Color.Silver;
                chart1.ChartAreas[i].AxisY.MinorGrid.LineDashStyle = ChartDashStyle.Dash;

                //chart1.ChartAreas[i].Position.Width  = 80;
                //chart1.ChartAreas[i].Position.Height = 90;
                //chart1.ChartAreas[i].Position.X = 30;

                chart1.Dock   = DockStyle.Right;
                chart1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

                //chart1.Series[0].IsVisibleInLegend = false;
                chart1.Legends.Clear();
                chart1.Titles.Clear();
            }

            /////////////////////////
            //testing.testing_regression(textBox1, chart1);
            testing.testing_matix(textBox1);

            nkcore.Digital.filter_loPass lo = new nkcore.Digital.filter_loPass(0.001, 100, 1);
            nkcore.Types.Collection      c  = nkcore.Math.Frequency_responce(0.1, 1000, 0.001, lo.coefs);
            //testing.testing_collection(textBox1);
            /////////////////////////


            series1.Points.DataBindXY(c[0], c[1]);
            series3.Points.DataBindXY(c[0], c[2]);
            //series2.Points.DataBindY(testing.cc[0]);
        }