Beispiel #1
0
        public static List <EventPsc> Psc(double[] sweepY, double sampleRate, DetectionSettingsPsc settings)
        {
            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();

            // prepare useful units
            double pointsPerMsec          = (double)sampleRate / 1000;
            int    windowSizePoints       = (int)(settings.windowSizeMs * pointsPerMsec);
            int    windowStepPoints       = (int)(settings.windowStepMs * pointsPerMsec);
            int    baselineBackUpPoints   = (int)(settings.baselineBackUp * pointsPerMsec);
            int    baselineDurationPoints = (int)(settings.baselineDuration * pointsPerMsec);

            var events = new List <EventPsc>();
            int sweepI = baselineBackUpPoints + baselineDurationPoints;

            while (sweepI < sweepY.Length - windowSizePoints)
            {
                // abort if this window doesn't contain extrema greater than the threshold
                var windowExtrema = new arrayExtrema(sweepY, sweepI, sweepI + windowSizePoints);
                if (windowExtrema.range < settings.threshold)
                {
                    sweepI += windowStepPoints;
                    continue;
                }

                // record the peak peak
                var thisEvent = new EventPsc();
                if (settings.upward)
                {
                    thisEvent.peakI = windowExtrema.maxI;
                }
                else
                {
                    thisEvent.peakI = windowExtrema.minI;
                }

                // calculate baseline
                thisEvent.baselineEndI   = sweepI - baselineBackUpPoints;
                thisEvent.baselineStartI = thisEvent.baselineEndI - baselineDurationPoints;
                double baselineSum = 0;
                for (int i = thisEvent.baselineStartI; i < thisEvent.baselineEndI; i++)
                {
                    baselineSum += sweepY[i];
                }
                thisEvent.baselineLevel = baselineSum / baselineDurationPoints;

                // if we made it this far, the event is valid
                events.Add(thisEvent);
                sweepI += windowStepPoints;
            }

            double elapsedMsec = stopwatch.ElapsedTicks * 1000.0 / System.Diagnostics.Stopwatch.Frequency;

            System.Console.WriteLine(string.Format("Event detection finished in {0:0.000} ms", elapsedMsec));

            return(events);
        }
        public DetectionSettingsPsc GetSettings()
        {
            var settings = new DetectionSettingsPsc
            {
                threshold        = (double)nudThreshold.Value,
                timeToPeak       = (double)nudTimeToPeak.Value,
                baselineBackUp   = (double)nudBaselineBackUp.Value,
                baselineDuration = (double)nudBaselineDuration.Value,
                decayFraction    = (double)nudDecayFraction.Value,
                area             = (double)nudArea.Value,
                upward           = (cbDirection.Text == "up")
            };

            return(settings);
        }