Esempio n. 1
0
        public SingleVideoExportViewModel()
        {
            ObservableCollection <ISmoothingBase> smoothingFunctions = new ObservableCollection <ISmoothingBase>();

            smoothingFunctions.Add(ModelResolver.Resolve <IGaussianSmoothing>());
            smoothingFunctions.Add(ModelResolver.Resolve <IBoxCarSmoothing>());
            SmoothingFunctions        = smoothingFunctions;
            SelectedSmoothingFunction = SmoothingFunctions.First();
        }
Esempio n. 2
0
        private void CalculateData()
        {
            MinAngle     = Signal.Min();
            MaxAngle     = Signal.Max();
            MaxAmplitude = Math.Abs(MaxAngle - MinAngle);
            RMS          = SmoothingFunctions.GetRMS(Signal);

            if (ProtractionRetractionData == null)
            {
                return;
            }

            AverageAmplitude = ProtractionRetractionData.Where(x => x.Amplitude != 0).Average(protractionRetraction => protractionRetraction.Amplitude);

            double[] smoothedSignal  = SmoothingFunctions.BoxCarSmooth(Signal);
            int[][]  peaksandValleys = SmoothingFunctions.FindPeaksAndValleys(smoothedSignal);
            int[]    signalPeaks     = peaksandValleys[0];
            int[]    signalValleys   = peaksandValleys[1];

            SignalPeaks   = signalPeaks.Select(peak => SmoothingFunctions.FindClosestPeak(peak, Signal)).ToArray();
            SignalValleys = signalValleys.Select(valley => SmoothingFunctions.FindClosestValley(valley, Signal)).ToArray();
        }
Esempio n. 3
0
        private void CreateAngularVelocitySignal()
        {
            if (AngleSignal == null || AngleSignal.Length == 0)
            {
                return;
            }

            bool error = false;


            int[][] peaksAndValleys = SmoothingFunctions.FindPeaksAndValleys(AngleSignal);
            int[]   peaks           = peaksAndValleys[0];
            int[]   valleys         = peaksAndValleys[1];

            if (peaks.Length == 0 || valleys.Length == 0)
            {
                return;
            }

            int[] rawPeaks = new int[peaks.Length];
            for (int i = 0; i < peaks.Length; i++)
            {
                int closestPeak = SmoothingFunctions.FindClosestPeak(peaks[i], AngleSignal);

                if (rawPeaks.Contains(closestPeak))
                {
                    ErrorOccured("The signal is too noisy, accurate results can not be guaranteed");
                    error = true;
                }

                rawPeaks[i] = closestPeak;
            }

            int[] rawValleys = new int[valleys.Length];
            for (int i = 0; i < valleys.Length; i++)
            {
                int closestValley = SmoothingFunctions.FindClosestValley(valleys[i], AngleSignal);

                if (rawValleys.Contains(closestValley))
                {
                    ErrorOccured("The signal is too noisy, accurate results can not be guaranteed");
                    error = true;
                }

                rawValleys[i] = closestValley;
            }

            List <ProtractionRetractionBase> data = new List <ProtractionRetractionBase>();

            int  peakCounter   = 0;
            int  valleyCounter = 0;
            int  currentPeak   = rawPeaks[peakCounter];
            int  currentValley = rawValleys[valleyCounter];
            bool protract      = currentPeak > currentValley;
            Dictionary <int, ProtractionRetractionBase> protractionRetractionDictionary = new Dictionary <int, ProtractionRetractionBase>();

            while (true)
            {
                if (protract)
                {
                    double deltaTime = Math.Abs(currentPeak - currentValley) / FrameRate;
                    ProtractionRetractionBase protraction = new ProtractionData();
                    protraction.UpdateData(AngleSignal[currentValley], AngleSignal[currentPeak], deltaTime);
                    data.Add(protraction);

                    for (int i = currentValley; i < currentPeak; i++)
                    {
                        if (!protractionRetractionDictionary.ContainsKey(i))
                        {
                            protractionRetractionDictionary.Add(i, protraction);
                        }
                        else
                        {
                            ErrorOccured("The signal is too noisy, accurate results can not be guaranteed");
                            error = true;
                        }
                    }

                    valleyCounter++;

                    if (valleyCounter >= rawValleys.Length)
                    {
                        break;
                    }

                    currentValley = rawValleys[valleyCounter];

                    protract = false;
                }
                else
                {
                    double deltaTime = Math.Abs(currentPeak - currentValley) / FrameRate;
                    ProtractionRetractionBase retraction = new RetractionData();
                    retraction.UpdateData(AngleSignal[currentValley], AngleSignal[currentPeak], deltaTime);
                    data.Add(retraction);

                    for (int i = currentPeak; i < currentValley; i++)
                    {
                        if (!protractionRetractionDictionary.ContainsKey(i))
                        {
                            protractionRetractionDictionary.Add(i, retraction);
                        }
                        else
                        {
                            ErrorOccured("The signal is too noisy, accurate results can not be guaranteed");
                            error = true;
                        }
                    }

                    peakCounter++;

                    if (peakCounter >= rawPeaks.Length)
                    {
                        break;
                    }

                    currentPeak = rawPeaks[peakCounter];

                    protract = true;
                }
            }

            ProtractionRetractionData       = data;
            ProtractionRetractionDictionary = protractionRetractionDictionary;

            MeanProtractionVelocity = ProtractionRetractionData.Where(x => x is ProtractionData).Select(x => x.MeanAngularVelocity).Mean();
            MeanRetractionVelocity  = ProtractionRetractionData.Where(x => x is RetractionData).Select(x => x.MeanAngularVelocity).Mean();
            MeanAngularVelocity     = ProtractionRetractionData.Select(x => Math.Abs(x.MeanAngularVelocity)).Mean();

            double maxAngle = ProtractionRetractionData.Select(x => x.MaxAngle).Max();
            double minAngle = ProtractionRetractionData.Select(x => x.MinAngle).Min();

            MaxAmplitude = Math.Abs(maxAngle - minAngle);

            if (!error)
            {
                ModelObjectState = ModelObjectState.New;
            }
        }