# Convolution of two uniform probability densities (two square waves)

Assuming $$X$$ and $$Y$$ are i.i.d. random variables let $$Z = X + Y$$

$$f_X(x) = f_Y(y) = \begin{cases} 1/2 & -1 \le x \le 1 \\ 0 & \text{else} \end{cases}$$

Find the density $$f_z$$ of $$Z$$.

I am attempting to do this using the convolution of $$f_X(x) * f_Y(y)$$.

$$f_X(x) * f_Y(y) = \int_{-\infty}^{\infty} f_X(x)f_Y(z-x) dx \\ = \int_{0}^{2} \frac{1}{2}(z - \frac{1}{2}) dx \\ = \frac{1}{2} \left[ zx - \frac{1}{2}x \right]_{0}^2 \\ = \frac{2z - 1}{2}$$

I understand the intuitive approach to this problem. i.e. the signals & systems geometric approach. And (I think) I also understand what the integral in the definition of convolution is actually doing. That being said I know the answer should be a piecewise function separated at intervals $$[-2,0]$$ and $$[0,2]$$. And I know my answer cannot be correct as it has a positive slope for the interval $$[0,2]$$ which should most certainly have negative slope.

Does anyone know what I am doing wrong here? Additionally, does anyone have any tips for understanding how to change the limits of integration other than imagining the graphical convolution?

It is not correct to replace $$f_y(z-x)$$ with $$z - \frac12$$.
There are only two possible values for $$f_y(z-x)$$: it can be either $$\frac12$$ or $$0$$. What you need to do is to determine which values of $$x$$ make $$f_y(z-x) = \frac12$$ and which values of $$x$$ make $$f_y(z-x) = 0$$. Then split the integral into integrals over disjoint intervals so that you are integrating with $$\frac12$$ in place of $$f_y(z-x)$$ over the interval where $$f_y(z-x) = \frac12$$, and integrating with $$0$$ in place of $$f_y(z-x)$$ over the interval where $$f_y(z-x) = 0$$.
We have to take into account the indicators: on has $$f_X(x)=f_X(x)=2^{-1}\mathbf{1}_{[-1,1]}(x)$$ hence we actually have $$f_Z(z)=\int_{-\infty}^\infty 2^{-1}\mathbf{1}_{-1\leqslant x\leqslant 1}2^{-1}2^{-1}\mathbf{1}_{-1\leqslant z-x\leqslant 1}dx.$$ The product of indicators can be written as $$\mathbf{1}_{.\max\{z-1,-1\}\leqslant x\leqslant \min\{1,z+1\}}$$. For some values of $$z$$, this indicator is $$0$$.