- Why does the Savitzky–Golay filter preserve peaks better than a moving average?
- A moving average simply replaces each point with the mean of its neighbors, which flattens sharp features. The Savitzky–Golay filter fits a polynomial (e.g., a parabola) to the points in the window. Since many peaks are locally parabolic, this fit approximates the underlying signal's shape more accurately, thus maintaining the peak's height and width while still averaging out noise.
- What happens if I choose a polynomial order equal to or greater than the window size?
- The filter becomes ill-posed. A polynomial of order p requires at least p+1 points to be uniquely defined. If the window has fewer points than that, or if the order is too high, the least squares fit becomes unstable and can overfit the noise, defeating the purpose of smoothing. Typically, the order is much smaller than the window size.
- Is Savitzky–Golay smoothing only for cosine waves or evenly spaced data?
- No. While this simulator uses a cosine wave for clarity, the technique is general-purpose for smoothing any noisy dataset. A critical requirement, however, is that the data points must be uniformly spaced along the x-axis (e.g., constant time intervals). The convolution coefficients depend on this uniform spacing.
- How do I choose the right window size and polynomial order?
- It's a trade-off. A larger window smooths more noise but may oversmooth sharp features. A higher polynomial order can follow sharper curves but may follow noise if set too high. Start with a low order (2 or 3) and adjust the window size to be just wide enough to encompass the narrowest feature you wish to preserve. Trial and error on representative data is common.