Sunteți pe pagina 1din 2

Discrete time convolution in Matlab

Using Matlab to compute convolution


Convolution is defined as:
+∞
X
y[n] = x[n] ∗ h[n] = x[i] · h[n − i]
i=−∞

If the signal x[n] has non zero taps only in the region [n1, n2] convolution can be rewritten as:

n2
X
y[n] = x[i] · h[n − i]
i=n1

This happens because all other terms of the sum are zero.
We can also do a change of variable and rewrite the sum as:

X1 +1
n2 −n
y[n] = x[i + n1 − 1] · h[n − (i + n1 − 1)]
i=1

Now observe that x ′[i] = x[i + n1 − 1] is a shifted version of x[n] with the first non zero tap at
i = 1.
X1 +1
n2 −n
y[n] = x ′[i] · h[(n − n1 + 1) − i]
i=1

We can do now yet another manipulation and obtain:

X1 +1
n2 −n
y[n − n1] = x ′[i] · h[n + 1 − i]
i=1

Assume now that the signal h[m] is non zero in the interval [m1, m2]. At any given n the pre-
vious multiplication will use taps from [n + 1 − n2 + n1 − 1, n + 1 − 1] = [n − (n2 − n1), n]. There-
fore for any n < m1 and n − (n2 − n1) > m2 the signal y[n + n1] is equal to 0.
We can further modify the formula using h ′[k] = h[k + m1 − 1], a shifted version of h[k] that has
its first non zero tap at k = 1.

X1 +1
n2 −n
y[n − n1] = x ′[i] · h ′[n + 1 − i − m1 + 1]
i=1

We can further rewrite the expression as:

X1 +1
n2 −n
y ′[n] = y[n − n1 − m1 + 1] = x ′[i] · h ′[n + 1 − i]
i=1

Since h ′[n] is non zero only in the [1, m2 − m1 + 1] we see that only for values of n > 1 it can be
non zero. This implies that y[n] has its first non zero tap at n1 + m1.

1
The last summation is exactely what matlab computes (you can see this in the documentation).
Therefore y ′[n] = conv(x ′[n], h ′[n]) and we can obtain y[n] by shifting conv(x ′[n], h ′[n]) by n1 +
m1 + 1 to the left. The matlab output contains the non zero taps of y ′[n], wich we computed
start at 1, so the first entry of the vector returned by matlab is corresponds to y[m1 + n1].

Computing convolution of signal with infinite support


Clearly if both signals we are convolving have infinite support we cannot compute y[n] with
Matlab. If only one of them has infinite support we can compute part of the convolution by
taking a window of the signal. The values of the convolution for all taps for which the finite sup-
port signal “fits” in the window of the other signal will correct.
Now we will compute for which values exactely the convolution is correct. Assume we have a
signal x[n] which support is contained in [n1, n2] and we take a window hw[n] of the infinite sup-
port signal h[n] in the interval [w1, w2], where:

h[n] ∀n ∈ [w1, w2]
hw[n] =
0 otherwise

We know that the convolution can be rewritten as:


n2
X
x[n] ∗ h[n] = x[i] · h[n − i]
i=n1

So as long as n − i ∈ [w1, w2] using h[n] or hw[n] doesn’t matter. In other words to compute the
tap of the convolution at time n we use taps from n − n2 to n − n1 of h[n]. So if n − n2 > w1 and
n − n1 6 w2, i.e. n ∈ [w1 + n2, w2 + n1], we have that hw[n] ∗ x[n] = h[n] ∗ x[n].
If the infinite support signal is non zero only for taps n > m1 then if we take a window of the
signal such that w1 6 m1 all values of the convolution computed for n 6 w2 + n1 are correct. This
because as long as n 6 w2 + n1 the summation takes taps of hw[n] wich are equal to h[n].

S-ar putea să vă placă și