# In Matlab: how do I quickly create smoothing matrices?

Say I have 5 measurements of a signal as a column vector: x. I can smooth the signal by multiplying it with a smoothing matrix:

$\ \mathbf{xs=S*x}$

For instance I might use [1 2 1] as a smoothing kernel in which case I get:

S =
2     1     0     0     0
1     2     1     0     0
0     1     2     1     0
0     0     1     2     1
0     0     0     1     2


So far I have been using the function sparse() to build the matrix diagonal by diagonal, but this quickly becomes tedious.

How can I quickly create a mxm smoothing matrix from a 1xn convolution kernel in Matlab?

• Why don't you use filter instead? Something like filter([1 2 1],1,x) – Juancho Jul 5 '12 at 16:24
• Convolve seems a good candidate, too... – heltonbiker Jul 5 '12 at 18:24

kernel = [1 2 1];