MATLAB: How to approximate a certain section of a vector to remove noise

approximationcomplexcurve fittinginterpolationnoiseSignal Processing Toolboxsmoothingvector

I have some plots of S-parameters from a network analyzer, and they have a large amount of noise around 2.4 GHz. I am relatively certain that this noise is due to the Wi-Fi signal in the lab where I am working, so I would like to remove this section of the vector entirely and replace it with an approximation of what the line should look like. These vectors are complex, which complicates the issue because if I use local linear approximation, the real and imaginary components turn out alright, but the magnitude still looks pretty bad. I've tried using some sort of interpolation function (like spline or pchip) but I can't seem to get it to do what I want, which is to entirely remove one section of the vector and replace it with values that fit with the curve before and after. I've attached a few plots to show the issue. The [Raw] plots are straight from the network analyzer, and the [Corrected] plots have simply been "fixed" with local linear approximation on both the real and imaginary components. Thanks!

Best Answer

I wouldn't use polyfit - I'd use a Savitzky-Golay filter. It's like polyfit, but does polyfit in a window of limited width as it slides along the entire signal. You can use function sgolayfilt() in the Signal Processing Toolbox. Since a sine wave or cosine wave is pretty well fit from a 4th or 5th order polynomial (as we know from the Taylor series representation of it), you could try 4 or 5 for the order of the Savitzky-Golay filter. Fitting a 5th order polynomial to a small sliding window will be better than fitting the entire signal with polyfit.