Sunday, April 7, 2024

Padding issue with smoothing filter

Hi Guys,

I am doing beep detection on a signal. The signal has a beep every few seconds, and I am processing the signal in chunks.

To better detect beeps in noisy signals I have this smoothing function:

    samples = signal.convolve(samples, [1]*189, 'same')/189

I think this is a moving average filter, and since I am outputting 'same' (I dont want the chunk size to change) I get these artifacts on the edges of my chunks:


So how can I fix this?


Another might be to pad with the previous samples, something like this:

>>> previous = np.random.sample(size=(200,))
>>> samples = np.random.sample(size=(200,))
>>> kernel = np.ones(189)/189.
>>> np.convolve(samples, kernel, mode='valid').shape
(12,)
>>> np.convolve(np.concatenate((previous[-188:], samples)), kernel, mode='valid').shape
(200,)
Are there any other ways around this issue?

IIRC I need to keep the output the same size else it screws up my calculations.

Thanks

AL


 

No comments:

Post a Comment