private static bool SmoothDataButterworth( double[] smoothedYData, int dataCount, udtSICPeakFinderOptionsType peakFinderOptions, ref int peakWidthPointsMinimum, out string errorMessage) { var dataFilter = new DataFilter.DataFilter(); errorMessage = string.Empty; // Filter the data with a Butterworth filter (.UseButterworthSmooth takes precedence over .UseSavitzkyGolaySmooth) float butterWorthFrequency; if (peakFinderOptions.SelectedIonMonitoringDataIsPresent && peakFinderOptions.ButterworthSamplingFrequencyDoubledForSIMData) { butterWorthFrequency = peakFinderOptions.ButterworthSamplingFrequency * 2; } else { butterWorthFrequency = peakFinderOptions.ButterworthSamplingFrequency; } const int startIndex = 0; var endIndex = dataCount - 1; var success = dataFilter.ButterworthFilter(smoothedYData, startIndex, endIndex, butterWorthFrequency); if (!success) { Console.WriteLine("Error with the Butterworth filter" + errorMessage); return(false); } // Data was smoothed // Validate that peakWidthPointsMinimum is large enough if (butterWorthFrequency > 0) { var peakWidthPointsCompare = (int)Math.Round(1 / butterWorthFrequency, 0); if (peakWidthPointsMinimum < peakWidthPointsCompare) { peakWidthPointsMinimum = peakWidthPointsCompare; } } return(true); }
private bool SmoothDataSavitzkyGolay( double[] smoothedYData, int dataCount, udtSICPeakFinderOptionsType peakFinderOptions, int peakWidthPointsMinimum, out string errorMessage) { var dataFilter = new DataFilter.DataFilter(); // Filter the data with a Savitzky Golay filter var filterThirdWidth = (int)Math.Floor(peakWidthPointsMinimum / 3.0); if (filterThirdWidth > 3) { filterThirdWidth = 3; } // Make sure filterThirdWidth is Odd if (filterThirdWidth % 2 == 0) { filterThirdWidth -= 1; } const int startIndex = 0; var endIndex = dataCount - 1; // Note that the SavitzkyGolayFilter doesn't work right for PolynomialDegree values greater than 0 // Also note that a PolynomialDegree value of 0 results in the equivalent of a moving average filter var success = dataFilter.SavitzkyGolayFilter(smoothedYData, startIndex, endIndex, filterThirdWidth, filterThirdWidth, peakFinderOptions.SavitzkyGolayFilterOrder, out errorMessage, true); if (!success) { Console.WriteLine("Error with the Savitzky-Golay filter: " + errorMessage); return(false); } // Data was smoothed return(true); }