-->a = [1 2 3] a = ! 1. 2. 3. ! -->b = [1 0 0 0 0 1 0 0 0] b = ! 1. 0. 0. 0. 0. 1. 0. 0. 0. ! -->c = convol(a,b) c = ! 1. 2. 3. 0. 0. 1. 2. 3. 0. 0. 0. !
We can see that `a' and `b' have different lengths and that `c' mixes the information contained in both signals. In this example each time that `b' takes value `1', `a' is introduced in the result.
Convolution can be used to modify a signal. Imagine that we have something similar to a calibration signal and we want to emphasize its changes
-->a = [ 0 0 0 1 1 1 1 0 0 0] a = ! 0. 0. 0. 1. 1. 1. 1. 0. 0. 0. ! -->b = [1 -1] b = ! 1. - 1. ! -->c = convol (a,b) c = ! 0. 0. 0. 1. 0. 0. 0. - 1. 0. 0. 0. !
In this example we have a squared wave 'a' similar to a calibration signal. 'b' has been designed to detect the positions where 'a' is not constant. We could see the process as if we had `filtered' the original signal with a `high pass' filter.
Depending on the values of 'b' we can produce very different effects in 'a'. In the previous example we eliminated slow changes but we can decrease fast changes too. In Clinical Neurophysiology, `smoothing' is frequently used to eliminate high frequency artifacts. Now, we are going to build a vector that `smoothes' signals. By using it, each point becomes the average of itself, its precedent value and its following one.
-->a = [ 0 0 0 1 1 1 1 0 0 0]; -->b = [ 1/3 , 1/3, 1/3]; -->c = convol(a,b); -->a' ans = ! 0. ! ! 0. ! ! 0. ! ! 1. ! ! 1. ! ! 1. ! ! 1. ! ! 0. ! ! 0. ! ! 0. ! -->c' ans = ! 0. ! ! 0. ! ! 0. ! ! 0.3333333 ! ! 0.6666667 ! ! 1. ! ! 1. ! ! 0.6666667 ! ! 0.3333333 ! ! 0. ! ! 0. ! ! 0. !
The apostrophe in the last two commands is only used to transpose 'a' and 'c' with the aim of presenting these vectors more clearly. In this example we have eliminated the abrupt changes that characterize the transition between `0' and `1' and between `1' and ' 0'. Saying it in another way, we have filtered the signal with a `low-pass filter'.
A graphical example similar to the previous one can be got with the following code
-->x = [0 0 0 1 1 1 1 1 1 0 0 0]; -->xsetech([0,0,1,1/3],[-1,-2,15,2]) -->plot2d(1:length(x), x, -3, "002"); -->xsetech([0,1/3,1,1/3],[-1,-2,15,2]) -->x1 = convol([1, -1], x); -->plot2d(1:length(x1), x1, -3, "002"); -->xsetech([0,2/3,1,1/3],[-1,-2,15,2]) -->x2 = convol ([1/3, 1/3, 1/3], x); -->plot2d(1:length(x2), x2, -3, "002");
The result is
![]() |
Notice that the first convolution acts like a high-pass filter while the second one acts like a low-pass filter.