public static void Filter(int windowSize) { List <ushort> window; int halfWindow = windowSize / 2; int lowerBorder = windowSize; int upperBorder = OriginalValues.Count - windowSize; int position = 0; FilteredValues.Clear(); for (int x = 0; x < OriginalValues.Count; x++) { if (x < lowerBorder) { position = halfWindow; } else if (x > upperBorder) { position = upperBorder - halfWindow; } else { position = x - halfWindow; } window = OriginalValues.GetRange(position, windowSize); window.Sort(); FilteredValues.Add(window[halfWindow]); } }