# How do I find the convolution of the following signals? [closed] $$h(t)$$ is the inputted to convolve the $$x(t)$$

The signal written in unit step are:

$$x(t) = (5-t)u(t-3) - (5-t)u(t-5)$$

$$h(t) = 2u(t-1) - 2u(t-3)$$

So to convolve I first change the function to:

$$h(t-\tau) = 2u(t-\tau-1) - 2u(t-\tau-3)$$

The problem however is the signal I get after integrating the product of $$x(\tau)$$ and $$h(t-\tau)$$ doesn't even closely resemble the signal I get via $$conv$$ function on MATLAB.

I'm trying to do this through integration in the time domain.

If anyone can work it out and explain why, would help me understand this.

EDIT: $$y(t)$$ is the convoluted signal. The graph below shows one using the $$conv$$ function the other I manually calculated. yt2 = (t-4).*(14-t).*u4 - (t-4).*(14-t).*u6 + (t+4).*(15-t).*u6 - (t+4).*(15-t).*u7;

• What do you mean by "doesn't even closely resemble the signal"? Could you post a plot of the result so that we can see how far off it is? It might give a clue as to what the problem is Dec 7 '19 at 13:37
• I think I'm doing the convolution wrong on paper. I'll attach what I'm getting it's weird.
– xev
Dec 7 '19 at 14:19
• Try improve your intuition with that tool phiresky.github.io/convolution-demo Dec 7 '19 at 14:47
• Thanks that's a really nice tool. My objective from this thing I'm doing is to understand convolution myself so that i can manually achieve it. This will help for visualizing it live.
– xev
Dec 7 '19 at 17:11

Once you understand the intuition of convolution using the link in the comments, you can work on deriving the equations. These problems are a bit tedious at first and can cause confusion if you try to do too much at once. I'm uploading my hand written notes on how to break the problem down. The key is to think about what happens when there is no overlap, partial overlap when the box enters the triangle from the left, full overlap (occurs only when $$t=6$$), and partial overlap wen the box begins to exit the triangle. So now we can check our work using MATLAB! We just need to be careful and understand that conv computes the convolution sum, not integral, but we can still use it to approximate. Here is the code to check your work:

%% Do the problem in MATLAB first
% Original time axis for x(t) and h(t)
t = linspace(-10, 10, 1000);

% Make x(t)
x = zeros( size(t) );
x(  t <= 5 & t >= 3  ) = linspace( 2, 0, length( find( t <= 5 & t >= 3 ) ) );

% Plot the triangle
subplot(4, 1, 1)
plot(t, x)

% Make h(t)
h = zeros( size(t) );
h( t >= 1 & t <= 3 ) = 2;

% Plot the box
subplot(4, 1, 2)
plot(t, h)

% Calculate the convolution and new time axis
y = conv(x, h);
ty = linspace(-20, 20, length(x) + length(h) - 1 );
dy = ty(2) - ty(1);

% Need to multiply by dy to get the same result as doing the integral by hand
% MATLAB conv() does discrete time sum for the convolution but we can
% approximate the integral by multiplying by the time step dy
y = y .* dy;

% Plot the convolution result
subplot(4, 1, 3)
plot(ty, y)
ylim([0 5])

%% Verify using "by-hand" equations
% Make the plot using the derived equations
t = linspace(-10, 10, 100);
y = zeros( size(t) );

tt = t( 4 <= t & t <= 6 );
y( 4 <= t & t <= 6 ) = 10*(tt - 1) - (tt - 1).^2 - 21;

tt = t( 6 < t & t <= 8 );
y( 6 <= t & t <= 8 ) = (tt - 8).^2;

subplot(4, 1, 4)
plot(t, y)
xlim([-20 20])
ylim([0 5])
$$$$


Piecewise defined convolution integrals are a distinguishing part of practical engineering work. Those piecewise intervals indicate on-off switching of various devices such as relays, capacitors, heaters, motors, transistors, etc. And they make the integrals tedius to evaluate (assuming the antiderivate is already available) unlike the case where the limits were from zero to infinity for example.

Graphical evaluation (aka flip & drag) is a handy technique for easy visualisation of the valid limits for such integrals. Acquaintance with the flip & drag technique is a must for electrical engineers.

For this simple example however, I will show another means of evaluating the piecewise integral using a more direct approach, as if I were to evalaute any integral. This method benefits from an easy computer evaluation as the simplicty of the MATLAB code shows.

Given the signals $$x(t)$$ and $$h(t)$$, we want to evaluate the convolution integral :

$$y(t) = \int_{-\infty}^{\infty} h(t-\tau) x(\tau) d\tau \tag{1}$$

We know that the integrand must be non-zero (i.e, overlap) for the output to be evaluated. And for this reason we ask the question, for what range of $$\tau$$ will the integrand functions $$h(t-\tau$$ and $$x(\tau)$$ be nonzero ?

Given the piecewise definitions of $$x(t)$$ and $$h(t)$$ we can see that $$x(t) = \begin{cases} { 5-t ~~~,~~~ 3 < t < 5 \tag{2} \\ 0 ~~~~,~~~\text{otherwise} } \end{cases} \\$$

$$h(t) = \begin{cases} { 2 ~~~,~~~ 1 < t < 3 \tag{3}\\ 0 ~~~~,~~~\text{otherwise} } \end{cases}$$

So the range of $$\tau$$ for nonzero overlap of functions is found from the intersection of the following two sets :

$$\{ 1 < t -\tau < 3\} \cap \{ 3 < \tau < 5 \} \tag{4}$$

$$\{ t-3 < \tau

The intersection interval set can be summarized as : $$\max( t-3 ,3) < \tau < \min(t-1,5) \tag{6}$$

Hence the convolution integral becomes:

$$y(t) = \int_{\max( t-3 ,3)}^{\min(t-1,5)} 2 \cdot (5-\tau) d\tau \tag{7}$$

Now, evaluate this integral with limits, wit the constraint that it's valid (nonzero) for those values of $$t$$ whenever $$\max( t-3 ,3) < \min(t-1,5)$$. We see that :

\begin{align} y(t) &= \int_{M}^{m} 2 \cdot (5-\tau) d\tau \\ \\ &= 10\tau - \tau^2 |_M^m \\ \\ &= 10(m-M) + M^2-m^2 \\ \end{align}

where $$m = \min(t-1,5)$$ ad $$M = \max(t-3,3)$$.

This result may not be intuitive for the eye, but it will be quite easy to evaluate using MATLAB / OCTAVE as the following code demonstrates

t = linspace(0,10,1000);   % assume a time span for "t"
m = min(t-1,5);            % find min of (t-1 , 5) for each "t"
M = max(t-3,3);            % find max of (t-3 , 3) for each "t"
vind = M < m;              % find "valid" range of "t"

y = 10*(m-M) + M.^2 - m.^2;% EVALUATE the CONVOLUTION
y = y.*vind;               % force non-valid range to zero.

figure,plot(t,y);         % DISPLAY:
title('convolution of 2[u(t-1)-u(t-3)] and (5-t)[u(t-3)-u(t-5)]');
`

with the output : 