public void Test()
 {
     var filter = new ScalarKF(1, 0, 3, 0, 1);
     IList<StepOutput<float>> result =
         filter.Filter(new List<float>(new float[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
     Assert.That(result.Count > 0);
 }
        public void Test()
        {
            var filter = new ScalarKF(1, 0, 3, 0, 1);
            IList <StepOutput <float> > result =
                filter.Filter(new List <float>(new float[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));

            Assert.That(result.Count > 0);
        }
Example #3
0
        /// <summary>
        ///   According to
        ///   http://www.swarthmore.edu/NatSci/echeeve1/Ref/Kalman/Ex2ScalarKalman.html
        /// </summary>
        public void FirstOrderOutputTest()
        {
            try
            {
                if (Chart == null)
                {
                    return;
                }

                // Add test Lines to demonstrate the control
                Chart.Primitives.Clear();

                const float a = 0.85f, b = 0, h = 3, Q = 0.1f, R = 1;
                var         filter   = new ScalarKF(a, b, h, Q, R);
                float[]     inValues = SwordfishGraphHelper.CreateFloatArray(100, 1);
                IList <StepOutput <float> > outValues = filter.Filter(inValues);

                var originalZValues = new List <float>(outValues.Select(element => element.Z));
//            var smoothedZValues = new List<float>();
                int halfWindowLength = inValues.Length / 10;
                for (int i = halfWindowLength; i < originalZValues.Count - halfWindowLength; i++)
                {
                    float windowMean = 0;
                    for (int j = -halfWindowLength; j <= halfWindowLength; j++)
                    {
                        int windowIndex = i + j;
                        windowMean += originalZValues[windowIndex];
                    }

                    windowMean /= halfWindowLength * 2;
                    //                smoothedZValues.Add(windowMean);
                    originalZValues[i] = windowMean;
                }

//            AddLineXY("N-Window Smoothing", Colors.DarkGoldenrod, originalZValues);//smoothedZValues);
//            AddLineXY("Noise W", Colors.White, outValues.Select(element => element.W));
//            AddLineXY("Noise V", Colors.LightGray, outValues.Select(element => element.V));
//            AddLineXY("k", Colors.Cyan, outValues.Select(element => element.K));
                SwordfishGraphHelper.AddLineXY(Chart, "A Posteriori X", Colors.YellowGreen,
                                               outValues.Select(element => element.PostX));
                SwordfishGraphHelper.AddLineXY(Chart, "A Priori X", Colors.Blue,
                                               outValues.Select(element => element.PriX));
                SwordfishGraphHelper.AddLineXY(Chart, "X", Colors.Red, outValues.Select(element => element.X));

                Chart.Title      = "FirstOrderOutputTest()";
                Chart.XAxisLabel = "X Axis";
                Chart.YAxisLabel = "Y Axis";

                Chart.RedrawPlotLines();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        /// <summary>
        ///   According to
        ///   http://www.swarthmore.edu/NatSci/echeeve1/Ref/Kalman/Ex1ScalarKalman.html
        /// </summary>
        public void ConstantOutputTest()
        {
            try
            {
                if (Chart == null)
                    return;

                // Add test Lines to demonstrate the control
                Chart.Primitives.Clear();

                const float a = 1, b = 0, h = 3, Q = 0, R = 1;
                var filter = new ScalarKF(a, b, h, Q, R);
                float[] inValues = SwordfishGraphHelper.CreateFloatArray(100, 1);
                IList<StepOutput<float>> outValues = filter.Filter(inValues);

                var smoothedZValues = new List<float>(outValues.Select(element => element.Z));
                int halfWindowLength = inValues.Length/10;
                for (int i = halfWindowLength; i < smoothedZValues.Count - halfWindowLength; i++)
                {
                    float windowMean = 0;
                    for (int j = -halfWindowLength; j <= halfWindowLength; j++)
                    {
                        int windowIndex = i + j;
                        windowMean += smoothedZValues[windowIndex];
                    }

                    windowMean /= halfWindowLength*2;
                    smoothedZValues[i] = windowMean;
                }

                SwordfishGraphHelper.AddLineXY(Chart, "N-Window Smoothing", Colors.DarkGoldenrod, smoothedZValues);
                SwordfishGraphHelper.AddLineXY(Chart, "Noise V", Colors.LightGray,
                                               outValues.Select(element => element.V));
                SwordfishGraphHelper.AddLineXY(Chart, "k", Colors.Cyan, outValues.Select(element => element.K));
                SwordfishGraphHelper.AddLineXY(Chart, "A Posteriori X", Colors.YellowGreen,
                                               outValues.Select(element => element.PostX));
                SwordfishGraphHelper.AddLineXY(Chart, "A Priori X", Colors.Blue,
                                               outValues.Select(element => element.PriX));
                SwordfishGraphHelper.AddLineXY(Chart, "X", Colors.Red, outValues.Select(element => element.X));

                Chart.Title = "ConstantOutputTest()";
                Chart.XAxisLabel = "X Axis";
                Chart.YAxisLabel = "Y Axis";

                Chart.RedrawPlotLines();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }