Beispiel #1
0
 public static void SimpleTimeCorrection(Dev dev, float common, float[] exps,
                                         out int common_i, out int[] exps_i)
 {
     double[] inpar = new double[exps.Length + 1];
     inpar[0] = common;
     for (int i = 0; i < exps.Length; i++)
     {
         inpar[i + 1] = exps[i];
     }
     int[] rez = mSimpleTimeCorrection(inpar, dev);
     common_i = rez[0];
     exps_i   = new int [exps.Length];
     for (int i = 0; i < exps.Length; i++)
     {
         exps_i[i] = rez[i + 1];
     }
 }
Beispiel #2
0
 //protected CONInterf Interf;
 public void Init(Dev dev)
 {
     D = dev;
     //Interf = interf;
     InitNullCalibrator();
 }
Beispiel #3
0
        /// <summary>
        /// This method converts from real time to supported time steps
        /// </summary>
        /// <param name="lTimes">real times</param>
        /// <returns></returns>
        private static int[] mSimpleTimeCorrection(double[] lTimes, Dev dev)
        {
            try
            {
                double step   = dev.Tick;// *0.000001;
                int    common = (int)(lTimes[0] / step);
                int[]  times  = new int[lTimes.Length - 1];
                for (int i = 0; i < times.Length; i++)
                {
                    times[i] = (int)(lTimes[i + 1] / step);
                }
                //int presp = (int)(lTimes[lTimes.Length - 1] / step);
                if (common <= 0)
                {
                    common = 1;
                }
                //if (presp < 0)
                //    presp = 0;
                for (int i = 0; i < times.Length; i++)
                {
                    if (times[i] <= 0)
                    {
                        times[i] = 1;
                    }
                    if (times[i] > common)
                    {
                        times[i] = common;
                    }
                }

                int    common_from = (int)(common * 0.7) - 2;
                int    common_to   = (int)(common * 1.3) + 2;
                int    best_common = common_from;
                double best_crit   = double.MaxValue;
                if (common_from < 1)
                {
                    common_from = 1;
                }
                int c;

                int prev_common = -1;
                for (c = common_from; c <= common_to; c++)
                {
                    double tmp_crit = 0;// Math.Abs(common - c) * 0.1 / (double)common;
                    for (int i = 0; i < times.Length; i++)
                    {
                        int n = mFindNearest(c, times[i]);
                        tmp_crit += Math.Pow((double)(Math.Abs(times[i] - n)) * 100 / times[i], 2);
                    }
                    if (tmp_crit < best_crit)
                    {
                        best_crit   = tmp_crit;
                        best_common = c;
                        prev_common = c;
                    }
                    else
                    {
                        if (tmp_crit == best_crit && Math.Abs(prev_common - common) > Math.Abs(prev_common - c))
                        {
                            best_crit   = tmp_crit;
                            best_common = c;
                            prev_common = c;
                        }
                    }
                }

                c = best_common;
                int[] ret = new int[times.Length + 1];
                ret[0] = best_common;
                for (int i = 0; i < times.Length; i++)
                {
                    int n = mFindNearest(best_common, times[i]);
                    ret[i + 1] = n;// times[i];
                }
                return(ret);
            }
            catch { }
            return(null);
        }