Exemplo n.º 1
0
        public void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }
            _isInitialized = true;

            FftResult fftResult = _fftAnalyzer.Analyze(_batCall);

            SimpleIntBin[] simpleIntBins = new SimpleIntBin[fftResult.FftData.Length - 1];
            int            iPeak         = 0;

            for (int i = 1; i < fftResult.FftData.Length; i++)
            {
                //231kHz Sample Rate with 1024 Buffer -> 115.5 / 256 Bins => 0.451 kHz pro Bin
                simpleIntBins[i - 1] = new SimpleIntBin(fftResult.FftData[i], Math.Round(i * 0.451).ToString(CultureInfo.CurrentCulture), false);
                if ((iPeak < fftResult.Peaks.Length) && (fftResult.Peaks[iPeak] == i))
                {
                    simpleIntBins[i - 1].IsHighlighted = true;
                    iPeak++;
                }
            }

            Frequencies = new ObservableCollection <SimpleIntBin>(simpleIntBins);

            PlotModel  pm         = new PlotModel();
            LineSeries lineSeries = new LineSeries();

            pm.Series.Add(lineSeries);
            pm.Axes.Add(new LinearAxis {
                Maximum = 260, Minimum = 0, Position = AxisPosition.Left, Title = "Intensität"
            });
            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, Title = "Dauer [ms]"
            });

            LineAnnotation lineAnnotation = new LineAnnotation {
                Color = OxyColors.DarkRed, LineStyle = LineStyle.Dash, Type = LineAnnotationType.Horizontal, Y = BatCall.MaxPower, Text = $"Ø {BatCall.MaxPower}"
            };

            pm.Annotations.Add(lineAnnotation);

            if (_batCall.PowerData != null)
            {
                lineSeries.Points.AddRange(_batCall.PowerData.Select((b, i) => new DataPoint(i * 0.246, b)));
            }
            Power = pm.AddStyles();
        }
Exemplo n.º 2
0
        private PlotModel BuildSampleTimePlotModel()
        {
            PlotModel  pm         = new PlotModel();
            LineSeries lineSeries = new LineSeries();

            pm.Series.Add(lineSeries);

            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Title = "Dauer [ms]"
            });
            pm.Axes.Add(new DateTimeAxis {
                Position = AxisPosition.Bottom, Title = "Zeit"
            });

            lineSeries.Points.AddRange(ParentViewModel.BatInfos.Select((b, i) => new DataPoint(DateTimeAxis.ToDouble(b.Time), b.SampleDuration)));
            pm.PlotMargins = new OxyThickness(50, double.NaN, double.NaN, double.NaN);
            return(pm.AddStyles());
        }
Exemplo n.º 3
0
        private PlotModel BuildVoltagePlotModel()
        {
            PlotModel  pm         = new PlotModel();
            LineSeries lineSeries = new LineSeries();

            pm.Series.Add(lineSeries);

            pm.Axes.Add(new LinearAxis {
                Minimum = 0, Maximum = 5, Position = AxisPosition.Left, Title = "Spannung [V]"
            });
            pm.Axes.Add(new DateTimeAxis {
                Position = AxisPosition.Bottom, Title = "Zeit"
            });

            lineSeries.Points.AddRange(ParentViewModel.BatInfos.Select((b, i) => new DataPoint(DateTimeAxis.ToDouble(b.Time), b.BatteryVoltage / 1000.0)));

            pm.PlotMargins = new OxyThickness(50, double.NaN, double.NaN, double.NaN);
            return(pm.AddStyles());
        }
Exemplo n.º 4
0
        private void InitPlots(CallModel callModel)
        {
            BatCall call = callModel.Call;

            PlotModel  pmPower       = new PlotModel();
            LineSeries pwrLineSeries = new LineSeries();

            pwrLineSeries.LineJoin = LineJoin.Round;
            pmPower.Series.Add(pwrLineSeries);
            pmPower.Axes.Add(new LinearAxis {
                Maximum = 260, Minimum = 0, Position = AxisPosition.Left, Title = "Intensität"
            });
            pmPower.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, Title = "Dauer [ms]"
            });

            if (call.PowerData != null)
            {
                pwrLineSeries.Points.AddRange(call.PowerData.Select((b, i) => new DataPoint(i * 0.251, b)));
            }

            //if (call.OriginalCalls.Count > 1)
            //{
            //    int leftSum = call.OriginalCalls[0].PowerData.Length;
            //    for (int i = 0; i < call.OriginalCalls.Count-1; i++)
            //    {
            //        int width = (int)Math.Round((call.OriginalCalls[i + 1].StartTimeMs - call.OriginalCalls[i].EndTimeMs) / 0.251);
            //        double left = leftSum* 0.251;
            //        double right = left + (width* 0.251);
            //        RectangleAnnotation annotation = new RectangleAnnotation { Fill = OxyColors.LightGray, Layer = AnnotationLayer.BelowAxes, MinimumX = left, MaximumX = right, MinimumY = 0, MaximumY = 260 };
            //        //LineAnnotation lineAnnotation = new LineAnnotation { Color = OxyColors.Red, StrokeThickness = 2, LineStyle = LineStyle.Dash, Type = LineAnnotationType.Vertical, X = linePos };
            //        pmPower.Annotations.Add(annotation);
            //        leftSum = leftSum + width + call.OriginalCalls[i].PowerData.Length;
            //    }
            //}


            OnlineFilter filter = OnlineFilter.CreateBandstop(ImpulseResponse.Infinite, 20, 20, 150);

            LineSeries pwrLineSeriesAvg = new LineSeries();

            pwrLineSeriesAvg.LineJoin = LineJoin.Round;
            pwrLineSeriesAvg.Color    = OxyColors.Blue;
            pmPower.Series.Add(pwrLineSeriesAvg);

            //double[] input = call.PowerData.Select(d => (double)d).ToArray();
            //double[] data = filter.ProcessSamples(input);
            //pwrLineSeriesAvg.Points.AddRange(data.Select((d, i) => new DataPoint(i * 0.251, d)));

            int[] window  = new int[] { 2, 4, 8, 4, 2 };
            int   divisor = window.Sum();

            byte[] input = call.PowerData;
            for (int i = 0; i < input.Length; i++)
            {
                double sum = 0;
                for (int j = 0; j < 5; j++)
                {
                    int    x = i + (j - 2);
                    double q;
                    if (x < 0)
                    {
                        q = input[0];
                    }
                    else if (x >= input.Length)
                    {
                        q = input[input.Length - 1];
                    }
                    else
                    {
                        q = input[x];
                    }
                    sum += q * window[j];
                }
                pwrLineSeriesAvg.Points.Add(new DataPoint(i * 0.251, sum / divisor));
            }


            LineSeries pwrLineSeriesAvg2 = new LineSeries();

            pwrLineSeriesAvg2.LineJoin = LineJoin.Round;
            pwrLineSeriesAvg2.Color    = OxyColors.Crimson;
            pmPower.Series.Add(pwrLineSeriesAvg2);

            int avgCount = 7;

            int[] ringBuffer  = Enumerable.Repeat(-1, avgCount).ToArray();
            int   bufferIndex = 0;

            for (int i = 0; i < call.PowerData.Length; i++)
            {
                ringBuffer[bufferIndex++] = call.PowerData[i];
                if (bufferIndex >= ringBuffer.Length)
                {
                    bufferIndex = 0;
                }

                if (i > 4)
                {
                    int    c    = 0;
                    double mAvg = 0;
                    for (int j = 0; j < ringBuffer.Length; j++)
                    {
                        if (ringBuffer[j] >= 0)
                        {
                            c++;
                            mAvg += ringBuffer[j];
                        }
                    }
                    pwrLineSeriesAvg2.Points.Add(new DataPoint((i - 4) * 0.251, mAvg / c));
                }
            }


            LineAnnotation lineAnnotation = new LineAnnotation {
                Color = OxyColors.Red, StrokeThickness = 2, LineStyle = LineStyle.Dash, Type = LineAnnotationType.Horizontal, Y = call.AveragePower
            };

            pmPower.Annotations.Add(lineAnnotation);

            Power = pmPower.AddStyles();


            PlotModel    pmFreq     = new PlotModel();
            ColumnSeries freqSeries = new ColumnSeries();

            pmFreq.Series.Add(freqSeries);
            CategoryAxis item = new CategoryAxis();

            item.Position               = AxisPosition.Bottom;
            item.Title                  = "Frequenz [kHz]";
            item.GapWidth               = 0.1;
            item.IsTickCentered         = true;
            item.LabelFormatter         = i => LogAnalyzer.GetFrequencyFromFftBin((int)i).ToString(CultureInfo.CurrentCulture);
            item.MajorGridlineThickness = 0;
            pmFreq.Axes.Add(item);

            if (call.FftData != null)
            {
                freqSeries.Items.AddRange(call.FftData.Select((f, i) =>
                {
                    ColumnItem columnItem = new ColumnItem(f, i);
                    columnItem.Color      = i == call.MaxFrequencyBin ? OxyColors.Red : OxyColors.Green;
                    return(columnItem);
                }));
            }
            Frequency = pmFreq.AddStyles();
        }