# Smoothing Filter on Signal

With python scipy I am processing (in real time) chunks of 250,000 each a CW pulsed beep radio signal in python from a RTLSDR. The signal after some basic processing and decimation is 9995 samples long and looks like:

A "beep" or high state as shown in the image above happens about once every 1,000,000 signals, and I process in chunks of 250,000 (before decimation). A high state has a duration of 189 samples (decimated).

The aim of the project is to:

 (a) Calculate time between beeps (black arrow);
(b) Calculate beep length (red arrows)


I have tried a few techniques to smooth the signal in the picture (and improve SNR) but they are affecting the downstream calculations.

Moving Average Smoothing:

np.convolve(max_samples, [1]*189, 'valid')/189


Introduced artifacts on the padding edges, which caused downstream calculations particularly where a chunk edge slices the beginning of a rising edge because the "rising edge" largely disappears and is no longer detected.

Savitzky-Golay

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter

signal.savgol_filter(max_samples, 189, 50)


I could not get this filter to output any plot that made sense:

Is there a better way to deal with the smoothing issue, especially as it relates to where a chunk has sliced a beeps rising edge, and still accurately calculating a beeps length?

If the answer is in the Savitzky Golay filter - what are sensible values? When I tried values like:

I get stack error:

-> 630     raise ValueError(
631         "array must not contain infs or NaNs")
632 return a

• The error says you have nans or infs. Get rid of those (set them to the mean value for example).
– Jdip
Commented Apr 8 at 11:29
• Are the beeps consistent? I’m asking because in your example, there is a clear threshold over which the beep happens. For this particular example, you could set it at say $0.8$, and the crossings at that threshold define your beep in time…
– Jdip
Commented Apr 8 at 11:31
• Why don't you run this through a simple thresholder? Smoothing will always mess up the edges no matter how you do it. Commented Apr 8 at 14:50
• Thats a perfect signal - add noise, and the smoothing is useful in getting the signal out of the noise. (So no the beeps are not always that clear. Commented Apr 9 at 1:52
• @jdip I don't know how NaN or Inf get into the max_samples - there is valid numbers in the array. Commented Apr 9 at 2:11