public void TestCutPSDbyFreq(bool LS, double freqMin, double freqMax, double expValue00, double expValue10, double expValue0e, double expValue1e, double expValue0m, double expValue1m)
        {
            InspectionAnalysisResults re = null;
            var freq = signals.First().TimeStampNumber;

            if (LS)
            {
                var data2 = new List <List <double> >();
                foreach (var item in data)
                {
                    data2.Add(item.Select(x => Math.Abs(x)).ToList());
                }
                re = Functions.CutPSDbyFreq(LS, freqMin, freqMax, data2, freq);
            }
            else
            {
                re = Functions.CutPSDbyFreq(LS, freqMin, freqMax, data, freq);
            }

            var slength = re.Y[0].Count;

            NUnit.Framework.Assert.AreEqual(re.X.Count, 259);
            NUnit.Framework.Assert.AreEqual(re.Y.Count, 2);
            NUnit.Framework.Assert.AreEqual(slength, 259);
            NUnit.Framework.Assert.AreEqual(re.Y[0][0], expValue00);
            NUnit.Framework.Assert.AreEqual(re.Y[1][0], expValue10);
            NUnit.Framework.Assert.AreEqual(re.Y[0][slength - 1], expValue0e);
            NUnit.Framework.Assert.AreEqual(re.Y[1][slength - 1], expValue1e);
            NUnit.Framework.Assert.AreEqual(re.Y[0][slength / 2], expValue0m);
            NUnit.Framework.Assert.AreEqual(re.Y[1][slength / 2], expValue1m);
            NUnit.Framework.Assert.AreEqual(re.X[0], 0.0001003125);
            NUnit.Framework.Assert.AreEqual(re.X[slength - 1], 0.00019984953703703704);
            NUnit.Framework.Assert.AreEqual(re.X[slength / 2], 0.00015008101851851852);
        }
Exemple #2
0
        public static InspectionAnalysisResults CutPSDbyFreq(bool LS, double freqMin, double freqMax, List <List <double> > dataInFreqDomain, List <double> freqAll)
        {
            var re       = new InspectionAnalysisResults();
            var keepFreq = new List <double>();
            var keepPxx  = new List <List <double> >();

            for (int i = 0; i < dataInFreqDomain.Count; i++)
            {
                keepPxx.Add(new List <double>());
            }
            for (int i = 0; i < freqAll.Count; i++)
            {
                var freq = freqAll[i];
                if (freq >= freqMin && freq <= freqMax)
                {
                    keepFreq.Add(freq);
                    for (int ii = 0; ii < dataInFreqDomain.Count; ii++)
                    {
                        if (LS)
                        {
                            keepPxx[ii].Add(10 * Math.Log10(dataInFreqDomain[ii][i]));
                        }
                        else
                        {
                            keepPxx[ii].Add(dataInFreqDomain[ii][i]);
                        }
                    }
                }
            }

            re.Y = keepPxx;
            re.X = keepFreq;
            return(re);
        }
        private void _spectralInspection(object obj)
        {
            var    plot       = obj as SignalPlotPanel;
            double startPoint = 0;
            double endPoint   = 0;
            int    startIndex = 0;
            int    endIndex   = 0;

            foreach (var ax in plot.SignalViewPlotModel.Axes)
            {
                if (ax.IsHorizontal())
                {
                    startPoint = ax.ActualMinimum;
                    endPoint   = ax.ActualMaximum;
                    //start = DateTime.FromOADate(ax.ActualMinimum).ToString("MM/dd/yyyy HH:mm:ss.fff");
                    //end = DateTime.FromOADate(ax.ActualMaximum).ToString("MM/dd/yyyy HH:mm:ss.fff");
                    break;
                }
            }
            var timeStamp = plot.Signals[0].TimeStampNumber;

            startIndex = timeStamp.FindLastIndex(a => a <= startPoint);
            endIndex   = timeStamp.FindIndex(a => a >= endPoint);
            if (startIndex == -1)
            {
                startIndex = 0;
            }
            if (endIndex == -1)
            {
                endIndex = timeStamp.Count - 1;
            }
            List <List <double> > allData = plot.Signals.Select(a => a.Data.GetRange(startIndex, endIndex - startIndex + 1).ToList()).ToList();

            double[] t = timeStamp.GetRange(startIndex, endIndex - startIndex + 1).ToArray();
            InspectionAnalysisResults result = null;

            if (plot.Signals.Count > 0)
            {
                InspectionAnalysisParams.Fs = plot.Signals[0].SamplingRate;
                try
                {
                    result             = Functions.InspectionSpectral(allData, InspectionAnalysisParams.Model);
                    result.Signalnames = plot.Signals.Select(x => x.SignalName).ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            SelectedSignalPlotPanel.AddATab = true;
            if (result != null)
            {
                //plot it!
                _plotInspectionAnalysisResult(result);
            }
        }
Exemple #4
0
        public static InspectionAnalysisResults InspectionSpectral(List <List <double> > data, InspectionAnalysisParameters parameters)
        {
            var fs         = parameters.Fs;
            int N          = (int)Math.Round(parameters.AnalysisLength * fs);
            var Nw         = Math.Round(parameters.WindowLength * fs);
            var Nover      = Math.Round(parameters.WindowOverlap * fs);
            var LS         = parameters.LogScale;
            var windowtype = parameters.WindowType;

            var freqMin = 0d;
            var freqMax = 0d;

            if (parameters.FreqMin != null)
            {
                freqMin = (double)parameters.FreqMin;
            }
            if (parameters.FreqMax != null)
            {
                freqMax = (double)parameters.FreqMax;
            }
            var Nzp = 0;

            if (parameters.ZeroPadding != null)
            {
                Nzp = (int)parameters.ZeroPadding;
            }

            List <List <double> > dataInFreqDomain;
            List <double>         freqAll;

            ComputePSD(data, fs, N, Nw, Nover, Nzp, windowtype, out dataInFreqDomain, out freqAll);

            InspectionAnalysisResults re = CutPSDbyFreq(LS, freqMin, freqMax, dataInFreqDomain, freqAll);

            re.Xlabel = "F (Hz)";
            if (LS)
            {
                re.Ylabel = "PSD (dB)";
            }
            else
            {
                re.Ylabel = "PSD";
            }
            //need to do some argument validation
            //such as the window size need to be smaller than the actual signal length
            //overlap size need to be smaller than window size

            return(re);
        }
        private void _plotInspectionAnalysisResult(InspectionAnalysisResults result)
        {
            var AsignalPlot = new ViewResolvingPlotModel()
            {
                PlotAreaBackground = OxyColors.WhiteSmoke
            };
            //var legends = new ObservableCollection<Legend>();
            LinearAxis xAxis = new LinearAxis()
            {
                Position           = AxisPosition.Bottom,
                Title              = result.Xlabel,
                MajorGridlineStyle = LineStyle.Dot,
                MinorGridlineStyle = LineStyle.Dot,
                MajorGridlineColor = OxyColor.FromRgb(44, 44, 44),
                TicklineColor      = OxyColor.FromRgb(82, 82, 82),
                IsZoomEnabled      = true,
                IsPanEnabled       = true,
            };

            //timeXAxis.AxisChanged += TimeXAxis_AxisChanged;
            AsignalPlot.Axes.Add(xAxis);
            LinearAxis yAxis = new LinearAxis()
            {
                Position = AxisPosition.Left,
                Title    = result.Ylabel,
                //Unit = SelectedSignalToBeViewed.Unit,
                MajorGridlineStyle = LineStyle.Dot,
                MinorGridlineStyle = LineStyle.Dot,
                MajorGridlineColor = OxyColor.FromRgb(44, 44, 44),
                TicklineColor      = OxyColor.FromRgb(82, 82, 82),
                IsZoomEnabled      = true,
                IsPanEnabled       = true
            };

            AsignalPlot.Axes.Add(yAxis);
            for (int index = 0; index < result.Y.Count; index++)
            {
                var newSeries = new LineSeries()
                {
                    LineStyle = LineStyle.Solid, StrokeThickness = 2
                };
                for (int i = 0; i < result.Y[index].Count; i++)
                {
                    newSeries.Points.Add(new DataPoint(result.X[i], result.Y[index][i]));
                }
                newSeries.Title = result.Signalnames[index];
                foreach (var item in SelectedSignalPlotPanel.Legends)
                {
                    if (newSeries.Title == item.Name)
                    {
                        newSeries.Color = item.Color;
                    }
                }
                AsignalPlot.Series.Add(newSeries);
            }
            AsignalPlot.LegendPlacement    = LegendPlacement.Outside;
            AsignalPlot.LegendPosition     = LegendPosition.RightMiddle;
            AsignalPlot.LegendPadding      = 0.0;
            AsignalPlot.LegendSymbolMargin = 0.0;
            AsignalPlot.LegendMargin       = 0;
            AsignalPlot.IsLegendVisible    = false;
            SelectedSignalPlotPanel.SpectralInspectionPlotModel = AsignalPlot;
        }