Can anyone tell what kind of filter is this? I can see it's smoothing/averaging the input signal, but why specifically with [1,2,1] instead of something else? What is so special about this coef=[1,2,1]? Thanks

# Python code
length = 1000
signal = np.random.rand(length)
output = np.zeros(length-2)
coef= np.array([1,2,1])
for i in range(length - 2):
output[i] = np.sum(signal[i:i+3] * coef / 4)

• You could plot the frequency response and try to find out.
– Ben
Apr 17, 2018 at 21:52
• I'll propose the opposite: there's nothing "special" about this filter. You can't ask us "why it's being used" without telling us what for it's being used! Apr 18, 2018 at 6:39
• It's cheap to implement Apr 18, 2018 at 13:57
• I found this example from a tutorial, which the author use to smooth a noisy ECG signal. The moment I saw this example I was wondering why not using something else, such as a 5-point moving average with coef = [1,1,1,1,1]/5, ... etc Apr 21, 2018 at 0:39
• that having coefficients as integers and nothing else... Dec 4, 2018 at 23:44

$$x1[n] = ( x0[n] + x0[n-1] ) / 2$$

$$x2[n] = ( x1[n] + x1[n-1] ) / 2$$

$$x2[n] = ( ( x0[n] + x0[n-1] ) / 2 + ( x0[n-1] + x0[n-2] ) / 2 ) / 2$$

$$x2[n] = ( x0[n] + 2 x0[n-1] + x0[n-2] ) / 4$$

Where $x0$ is your source signal, $x1$ a simple average, and $x2$ the average of the average.

Now, change it to (1, -2, 1) and you get the discrete analog of the 2nd derivative.

Ced

• wow this is an incredible insight... but why would someone do 2-points averaging instead of with a longer samples... such as 5-points or 10-points...? Apr 21, 2018 at 0:50
• @ScoodoodC, I should have looked at your code a little closer. The minuses would have been plusses in my answer. If they were centered you could also say the result is the average of the sample with the average of its two neighbors. It is actually three point smoothing, which may be adequate. Longer intervals may be to "smeared", depends on the application. I have actually used [[1,2,1],[2,4,2],[1,2,1]] centered 2D smoothing on webcam images to improve the quality. Being Pascal triangle coefficients they are rough approximations of a Gaussian distribution. Apr 21, 2018 at 14:54

It is a symmetric odd-sized FIR smoothing kernel, belonging to the class of Pascal or binomial filters that somehow sample a Gaussian kernel. Plus, its coefficients are simple dyadic integers, that can be implemented as bit-shifts 1/4 1/2 1/4. The coefficients sum to one, hence it is unit gain at DC.

In simpler word: (one of) the simplest real smoother preserving symmetric feature location. It's efficiency is however limited

• I'd argue that's not even a nicely designed filter under the constraint of being that simple – a normalization could've made it unit-gain in passband, since this is all floating point math anyways. Apr 18, 2018 at 6:41
• Agreed, this filter is not deeigned. Except for the Gaussian likeness. Yet there is a normalization by 4 Apr 18, 2018 at 13:01
• Hi Laurent, do yo mind to further elaborate the significant of Gaussian kernel? Why not simply use 5-points moving average with coef = 1/5 1/5 1/5 1/5 1/5? Besides, what do you mean by "preserving symmetric feature location"? Apr 21, 2018 at 0:44