# Computing Discrete Convolution in terms of unit step function

Consider : $$x[n]:=\begin{cases} 1&\text{if 3\leq n\leq 8}\\ 0&\text{if otherwise} \end{cases} \quad\text{and}\quad h[n]:=\begin{cases} 1&\text{if 4\leq n \leq 15}\\ 0&\text{if otherwise} \end{cases}$$ I wish to compute the convolution $$\displaystyle y[n]=(x*h)[n]=\sum_{k=-\infty}^{\infty}x[k]h[n-k]$$. Because I dislike the method of graphing, I wanted to take another approach using unit step function : $$x[n]=u[n-3]-u[n-8] \quad \text{and} \quad h[n]=u[n-4]-u[n-15]$$ By using distributivity property of the discrete-time convolution, we get : \begin{align*} (x*h)[n]&=(u[n-3]-u[n-8])*(u[n-4]-u[n-15])\\ \\ &=\underbrace{u[n-3]*u[n-4]}_{(y_{1}[n])} -\underbrace{u[n-3]*u[n-15]}_{(y_{2}[n])}-\underbrace{u[n-8]*u[n-4]}_{(y_{3}[n])}+\underbrace{u[n-8]*u[n-15]}_{(y_{4}[n])} \end{align*} Therefore we have four convolutions for which we can see that :

$$y_{1}[n]$$ = $$\begin{cases}\displaystyle\sum_{3}^{n-4}1&\text{if 7\leq n \leq 11}\\0&\text{if otherwise}\end{cases}=\begin{cases}n-6&\text{if 7\leq n \leq 11}\\0&\text{if otherwise}\end{cases}$$

$$y_{2}[n] = \begin{cases}\displaystyle\sum_{3}^{n-15}1&\text{if 18\leq n \leq 33}\\0&\text{if otherwise}\end{cases}=\begin{cases}n-17&\text{if 18\leq n \leq 33}\\0&\text{if otherwise}\end{cases}$$

$$y_{3}[n] =\begin{cases}\displaystyle\sum_{8}^{n-4}1&\text{if 12\leq n \leq 16}\\0&\text{if otherwise}\end{cases}=\begin{cases}n-11&\text{if 12\leq n \leq 16}\\0&\text{if otherwise}\end{cases}$$

$$y_{4}[n]=\begin{cases}\displaystyle\sum_{8}^{n-15}1&\text{if 23\leq n \leq 38}\\0&\text{if otherwise}\end{cases}=\begin{cases}n-22&\text{if 23\leq n \leq 38}\\0&\text{if otherwise}\end{cases}$$

I must note that I am afraid I don't know if the upper bound in the sum of $$(1)$$, $$(2)$$, $$(3)$$, and $$(4)$$ are right or wrong. I think what's left to do is compute : $$y[n]=y_{1}[n]-y_{2}[n]-y_{3}[n]+y_{4}[n]$$ I hope someone can show me how from here we can prove that the answer is : $$y[n]=\begin{cases} n-6&\text{if 7\leq n\leq 11}\\ 6&\text{if 12\leq n\leq 18}\\ 24-n&\text{if 19\leq n \leq 23}\\ 0&\text{if otherwise} \end{cases}$$

As a first remark, I would really suggest to also familiarize yourself with the graphical way of convolving two functions or sequences. This will also make your calculations a lot easier because you get some intuition on the nature of the solution.

Second, your definitions of $$x[n]$$ and $$h[n]$$ in terms of the step sequence $$u[n]$$ are not correct. E.g., the given $$x[n]$$ equals $$1$$ for $$n=8$$, but $$u[n-3]-u[n-8]$$ is zero for $$n=8$$.

It is formally correct to represent the solution as the sum of four individual convolutions of shifted step sequences, so what you could do is derive a general solution of the individual convolutions of the form

$$u[n-n_0]\star u[n-n_1]=(n-N_0)u[n-N_1]\tag{1}$$

I leave it up to you to derive the correct values of $$N_0$$ and $$N_1$$ in terms of $$n_0$$ and $$n_1$$. Once you have obtained that result, you can just compute the solution to the original problem as the sum of four terms of the form $$(1)$$.

• I observe that $N_{0}=n_{0}+n_{1}-1$ and $N_{1}=n_{1}+k$ can $N_{1}$ be expressed in terms of $n_{0}$ and $n_{1}$? – deerclaysup Mar 12 at 12:10
• @deerclaysup: Your $N_0$ is correct. $N_1$ can indeed be expressed in terms of $n_0$ and $n_1$. Think about it graphically! – Matt L. Mar 12 at 12:43
• I observe that $N_{1}=n_{0}-n_{1}$ $:)$ – deerclaysup Mar 12 at 12:50
• @deerclaysup: Almost :) Again, please draw two shifted unit steps, flip on (as is done when convolving the two), and figure out the value of $n$ for which the two start overlapping (and hence the convolution sum gives a non-zero result). – Matt L. Mar 12 at 12:52
• @deerclaysup: Note that the expression for $N_1$ must be symmetric in $n_0$ and $n_1$, because it doesn't matter which of the two steps is shifted by $n_0$ and which by $n_1$. – Matt L. Mar 12 at 12:54

Your approach doesn't work: the convolution of two unit steps isn't a finite sum. You can express the rectangles as the difference of two unit steps, but you must keep the difference inside the convolution, so the infinite parts cancel.

If you want to do it analytically, you can simply stack up shifted unit step differences, i.e.

$$y[n] = \sum_ {k=3}^{8} u[n-k-4]-u[n-k-16]$$

For each sample you get 6 positives and six negative unit steps. For each time lag you can determine whether the unit step is 1 or 0 and then count the positive 1s and subtract the negative ones. Not pretty, but it will work.

A little more elegant would be to break this into two sums

$$y[n] = \sum_ {k=3}^{8} u[n-k-4]- \sum_ {k=3}^{8} u[n-k-16]$$

and figure out the upper and lower bound for each section.

• How you obtain the terms $u[n-k-4]$ and $u[n-k-16]$? – deerclaysup Mar 12 at 12:30
• I wouldn't choose that approach but it does work. The convolution of two shifted unit step sequences is just a linear function of $n$ for $n$ greater than some constant, which is determined by the shifts of the unit steps (Eq. $(1)$ in my answer). Of course, the individual unit steps must both be right-sided (or left-sided). – Matt L. Mar 12 at 12:47