# Calculating the convolution of a piecewise function

Let

$$f(x) = \begin{cases} \frac{1}{2}, & \text{if \rvert x\lvert \le 1 } \\ 0, & \text{otherwise} \end{cases}$$

I want to calculate the convolution of $f$ with itself.

I am given the following formula:

$$f*g=\int_{-\infty}^{+\infty} f(y)g(x-y) dy$$

so, $\space f*f=\int_{-\infty}^{+\infty} f(y)f(x-y) dy$. How do I evaluate this integral?

While doing some research online I found that one can calculate the convolution by using the fourier-transform. $$\mathcal F(f(x)f(x))=\frac{1}{\sqrt{2 \pi}} \hat{f}(k) *\hat{f}(k)$$

The problem with using this method is that I don't know how to multiply a piecewise function with itself. Would it just be:

$$f(x) = \begin{cases} \color{red}{\frac{1}{4}}, & \text{if \rvert x\lvert \le 1 } \\ 0, & \text{otherwise} \end{cases}$$

or am I doing something wrong here?

Use the original definition: $$\space f*f=\int_{-\infty}^{+\infty} f(y)f(x-y) dy$$ When $|y|>-1$, $f(y)=0$, otherwise it is $\frac{1}{2}$. So the integral is reduced to $$\frac{1}{2}\int_{-1}^{1} f(x-y) dy$$

Now substitute $t=x-y$,

$$\frac{1}{2}\int_{x-1}^{x+1} f(t) dt$$

It is easy to see when $x\leq -2$ or $x\geq 2$, $f(t)$ is entirely $0$, so this function is equal to $0$ in those intervals. Between $-2$ and $2$, $f(t)$ is $\frac{1}{2}$ in the green region:

In this picture, the upper boundary of the green region is $y=x+1$, the lower boundary is $x-1$. The height of the green region is the distance we want. So you can see that the integral is equal to $$(x+1)-(-1)=x+2, \quad\quad -2\leq x\leq 0\\ 1-(x-1)=2-x, \quad\quad 0\leq x\leq 2$$

And this is the required function after multiplying by $\frac{1}{4}$.

• EDIT: I misread what you wrote. Sorry! Thank you very much for your answer and for the graphic. It really helps to look at this visually. – bluemoon Jan 7 '16 at 21:52
• @bluemoon: I forgot the $\frac{1}{4}$ though. Just added. – KittyL Jan 7 '16 at 22:20

We can use the unit step function $u(x)$ defined as

$$u(x)=\begin{cases} 1&,x>0\\\\ 0&,x<0 \end{cases}$$

to write $f(x)$ as $f(x)=\frac12 (u(x+1)-u(x-1))$.

Then, the convolution $(f*f)$ is given by

\begin{align} (f*f)(x)&=\int_{-\infty}^\infty f(y)\,f(x-y)\,dy\\\\ &=\frac14\int_{-\infty}^\infty (u(y+1)-u(y-1))(u(x-y+1)-u(x-y-1))\,dy\\\\ &=\frac14 \int_{-1}^{1}(u(x-y+1)-u(x-y-1))\,dy\\\\ &=\frac14\left(\int_{-1}^{x+1} 1\,dy\right)(u(x+2)-u(x))+\frac12u(x)\\\\ &-\frac14\left(\int_{-1}^{x-1} 1\,dy\right)(u(x)-u(x-2))-\frac12u(x-2)\\\\ &=\frac14(x+2)(u(x+2)-u(x))+\frac12 u(x)\\\\ &-\frac14(x)(u(x)-u(x-2))-\frac12u(x-2)\\\\ &=\frac14(x+2)(u(x+2)-u(x))+\frac14(2-x)(u(x)-u(x-2))\\\\ \end{align}

Therefore, the convolution $f*f$ is

$$(f*f)(x)= \begin{cases} x+2&,-2\le x\le 0\\\\ 2-x&,0\le x\le 2\\\\ 0&,\text{elsewhere} \end{cases}$$