diff --git a/src/AudioAnalysisTools/DSP/NoiseRemoval_Briggs.cs b/src/AudioAnalysisTools/DSP/NoiseRemoval_Briggs.cs index 3393f9670..89e300aca 100644 --- a/src/AudioAnalysisTools/DSP/NoiseRemoval_Briggs.cs +++ b/src/AudioAnalysisTools/DSP/NoiseRemoval_Briggs.cs @@ -199,14 +199,24 @@ public static double[] CalculateLocalVariance1(double[] data, int window) /// public static double[] CalculateLocalVariance2(double[,] matrix, int colId, int rowWindow) { + int rowCount = matrix.GetLength(0); + int colCount = matrix.GetLength(1); + + if (rowWindow < 3) + { + throw new Exception("Invalid value for length of rowWindow. Must be >= 3"); + } + + if (rowWindow > rowCount) + { + rowWindow = rowCount - 1; + } + // the column window must be an odd number. int colWindow = 5; int halfColWindow = colWindow / 2; int halfRowWindow = rowWindow / 2; - int rowCount = matrix.GetLength(0); - int colCount = matrix.GetLength(1); - double[] variances = new double[rowCount]; // set up the column Ids.