I have a time series signal I need to smoothen to get rid of some noise.
I decided to apply a moving average filter to this signal. I know the choice of the length of the MA is critical.
How should I choose the length?
I have a time series signal I need to smoothen to get rid of some noise.
I decided to apply a moving average filter to this signal. I know the choice of the length of the MA is critical.
How should I choose the length?
The magnitude frequency response $|Y(\omega)|$ of moving average of length $N$ can be approximated by:
$$|Y(\omega)| \approx |\hat Y(\omega)| = \left|\frac{2\sin(\frac{N\omega}{2})}{N\omega}\right|$$
Figure 1. Horizontal axis: $N\omega$, vertical axis: $|\hat Y(\omega)|$.
The frequency $\omega$ is in radians, meaning that $\omega=2\pi$ corresponds to the sampling frequency. You should choose $N$ such that the noise is attenuated as much as possible while keeping a flat enough frequency response over the signal's bandwidth so that the signal's waveform is not distorted too much. What is flat enough depends on what you are going to do with the signal. A good first bet is to have the -3 dB cutoff frequency at the upper bandlimit of your signal so that no frequency of the signal is attenuated by more than 3 dB. The -3 dB cutoff frequency $\omega_c$ of moving average can be approximated by:
$$\omega_c \approx \hat\omega_c = \frac{2.783}{N}$$
These approximations were derived here.