Why does tridiagonal matrix reduce noise?

296 Views Asked by At

Let

$$B = \begin{pmatrix} 1/3 & 1/3 & 0 & 0 & 0 & \dots & 0 & 0 \\ 1/3 & 1/3 & 1/3 & 0 & 0 & \dots & 0 & 0 \\ 0 & 1/3 & 1/3 & 1/3 & 0 & \dots & 0 & 0 \\ 0 & 0 & 1/3 & 1/3 & 1/3 & \dots & & . \\ 0 & 0 & 0 & 1/3 & 1/3 & \dots & & . \\ \vdots & \vdots & \vdots & \vdots & \vdots & \dots & 0 & . \\ \vdots & \vdots & \vdots & \vdots & \vdots & \dots & 0 & 1/3 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1/3 & 1/3 \\ \end{pmatrix}$$

Let $f(x)$ be a function. I see that if I add random noise to f(x), $g(x)=f(x) + noise$. Then $Bg(x)$ is closer to $f(x)$ than $g(x)$.

Why is that? Can someone explain how this works?

I've tried to make a small example on Wolfram Alpha, but it doesn't really help.

1

There are 1 best solutions below

0
On BEST ANSWER

Note that this matrix is averaging each element with its adjacent values so $Bg(x)$ is a smoothed version of $g(x)$. For $n(x)$ denoting the noise signal

$$ Bg(x)=Bf(x) + Bn(x) \simeq f(x)+0 $$

assuming your noise is zero mean and the original signal $f(x)$ is smooth enough (so $Bf(x)\simeq f(x)$, we get approximately the same signal after smoothing it).

If you want a simple example in Python:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,10)
f = x/10
n = np.random.randn(len(x))
g = f + n

def plot(size): 
    plt.title(f'Averaging over {size} samples') 
    plt.plot(x, g, label='g(x)') 
    B = np.zeros((len(x), len(x))) 
    for i in range(len(x)): 
          B[i, max(0, int(i - (size - 1) / 2)):min(len(x) - 1, i + int((size - 1) / 2))] = 1 / size 
    plt.plot(x, B @ g, label='Bg(x)') 
    plt.plot(x, f, label='f(x)') 
    plt.legend() 
    plt.show()

plot(3)
plot(10)

enter image description here enter image description here