Exemple #1
0
        //--------------------------------------------------------------------
        // constructor for blank Assay with specified cal - inits tables to size
        // indicated by cal

        public Assay(Calibration assayCal)
        {
            cal = (Calibration)assayCal.Clone();

            StepCount = (ushort)(Math.Abs(cal.FinalmVolts - cal.DepmVolts) / cal.StepSize + 1);

            ForwardTable    = new short[StepCount];
            ReverseTable    = new short[StepCount];
            DifferenceTable = new short[StepCount];
            CorrectedTable  = new short[StepCount];
            PotentialTable  = new short[StepCount];

            ResearchData = new rDataRec[StepCount];
        }
Exemple #2
0
        //--------------------------------------------------------------------

        public Assay ReCalcResults()
        {
            Calibration newCal = this.cal.Clone() as Calibration;

            // no need to recal LC3 results, since they were done on PC in first place
            if (Source == Analyzer.LeadCare3)
            {
                return((Assay)this.Clone());
            }

            // create new assay, set calibration,zero result
            Assay recalc = (Assay)this.Clone();

            recalc.cal      = newCal.Clone() as Calibration;
            recalc.Result   = 0;
            recalc.SWCValue = 0;

            // only recalc if we have raw data
            if (recalc.ForwardADC == null || recalc.ReverseADC == null || recalc.StepCount == 0)
            {
                return(recalc);
            }

            // intermediate data tables for filtering
            short[] avgForwardTable = new short[recalc.StepCount];
            short[] avgReverseTable = new short[recalc.StepCount];
            short[] rawDiffTable    = new short[recalc.StepCount];

            // first fill with raw ADC reads
            for (int step = 0; step < recalc.StepCount; step++)
            {
                if (Source == Analyzer.LeadCare3)
                {
                    avgForwardTable[step] = ConvertLc3AdcReading(ForwardADC[step]);
                    avgReverseTable[step] = ConvertLc3AdcReading(ReverseADC[step]);
                }
                else
                {
                    avgForwardTable[step] = ForwardADC[step];
                    avgReverseTable[step] = ReverseADC[step];
                }
            }

            TestAgainstCurrentLimit(recalc, avgForwardTable, avgReverseTable);

            // apply boxcar filter to averaged reads to get final forward & reverse tables
            Filter(recalc.ForwardTable, avgForwardTable, BoxcarFilter);
            Filter(recalc.ReverseTable, avgReverseTable, BoxcarFilter);

            // get difference table with ADC overflow flagging and then filter with FFT
            GetDifferenceCurve(recalc, rawDiffTable);
            Filter(recalc.DifferenceTable, rawDiffTable, FFTfilter);

            // fill raw corrected table and apply baseline correction
            for (int i = 0; i < recalc.StepCount; i++)
            {
                recalc.CorrectedTable[i] = recalc.DifferenceTable[i];
            }
            recalc.BCiterations = 0;
            for (int i = 0; i < 3; i++)
            {
                if (BaselineCorrection(recalc))
                {
                    ++recalc.BCiterations;
                }
            }

            // integrate to get square wave capacitance
            recalc.SWCValue = 0;
            for (int i = recalc.LowerMinimum; i <= recalc.UpperMinimum; i++)
            {
                if (recalc.CorrectedTable[i] > 0)
                {
                    recalc.SWCValue += (uint)recalc.CorrectedTable[i];
                }
            }

            // final correction and conversion
            TemperatureCorrection(recalc);
            TranslateBLL(recalc);
            if (recalc.Error == 0)
            {
                recalc.Result = recalc.BLLCorrected;
            }

            // debug test for calculation
            bool recalcOK = true;

            try {
                for (int step = 0; step < recalc.StepCount; step++)
                {
                    if (recalc.ForwardTable[step] != this.ForwardTable[step])
                    {
                        recalcOK = false;
                    }
                    if (recalc.ReverseTable[step] != this.ReverseTable[step])
                    {
                        recalcOK = false;
                    }
                    if (recalc.DifferenceTable[step] != this.DifferenceTable[step])
                    {
                        recalcOK = false;
                    }
                    if (recalc.CorrectedTable[step] != this.CorrectedTable[step])
                    {
                        recalcOK = false;
                    }
                }
                if (recalc.SWCValue != this.SWCValue)
                {
                    recalcOK = false;
                }
                if (recalc.TempCorrected != this.TempCorrected)
                {
                    recalcOK = false;
                }
                if (recalc.SWCscaled != this.SWCscaled)
                {
                    recalcOK = false;
                }
                if (recalc.BLLCorrected != this.BLLCorrected)
                {
                    recalcOK = false;
                }
            }
            catch (Exception) {
                recalcOK = false;
            }

            if (recalcOK)
            {
            }

            return(recalc);
        }