You are on page 1of 4

Convolution, continuous harmonic signals

Jan Cernock
y and Petr Motlcek, FIT VUT Brno

Convolution discrete time

Convolution is used when analyzing response of a system on arbitrary signals x[n], if we know its impulse response h[n]. The
output is then computed:
+
X
x[k]h[n k].
y[n] =
k=

Briefly: we define new auxiliary variable k, over which we will sum. The signal x[n] is redrawn as it is. The impulse
response h[n] is flipped in time, thus we get h[k]. To compute nth output sample, we need to create h[n k]. It can be done
in such a way that we shift zeroth time sample of sequence h[k] to the time n. Then, everything laying over is multiplied
and added we get y[n]. Then, we continue for next n. . .

Bounds of sum
must be found out, in order not to step out of time-spans of signals. Suppose, we have both x[n] and h[n] defined for time
n = [10, 10]. The definition of bounds is demonstrated on the following figure:
x[k]:
h[n-k]:

x[-10] ............ x[0] .... x[n] .... x[10]


h[10] ............ h[0] .............. h[-10]

Bounds for k, if we imagine a shifting of h[n k] over x[k], can be computed:


kod = max(10, n 10),
kdo = min(10, n + 10).
Try it out with two slips of paper! The sum then will be:
y[n] =

kdo
X

x[k]h[n k].

k=kod

When using Matlab, we should realize that Matlab counts all vectors from 1. Thus it cannot work with negative indexes,
such as in k or n. Therefore, it would be helpful to define an auxiliary variable gj0 (shortcut gde je 0 where is zero),
which will define an index of the real zero time. This variable will be added when indexing all vectors.

Exercise 1.
Compute a convolution of signal and impulse response from lecture (for time

2
for n = 1
3

1 for n = 0
2
x[n] =
h[n] =
1
for
n
=
1
1

0
elsewhere
0

n = [10, 10]):
for n = 0
for n = 1
for n = 2
elsewhere

Solution: first, time axis, auxiliary variable and signals need to be defined:

n = -10:10; gj0 = find(n==0);


h = zeros(size(n));
h(gj0) = 3; h(gj0+1) = 2; h(gj0+2) = 1;
stem (n,h);
x = zeros(size(n));
x(gj0-1) = 2; x(gj0) = -1; x(gj0+1) = 1;
stem (n,x);
The computation of convolution could be (the time counter is represented by variable ii, because in n the vector of time
samples is stored!):

y = zeros(size(n));
for ii = n
kod = max(-10,ii-10); kdo = min(10,ii+10);
acc = 0;
for k=kod:kdo
acc = acc + x(gj0+k) * h(gj0 + ii - k);
end
y(gj0+ii) = acc;
end
stem (n,y)
If someone familiar with Matlab programming sees this code, he will probably black out. In Matlab, we try to avoid using
cycles and replace it by operations with vectors, which are much faster.

Exercise 2.
Do optimization of computation of convolution in such a way that some auxiliary vectors will be selected xvyber a hvyber
and the multiplication and addition of their components will be performed by scalar multiplication. The inner cycle will
be discarded:
...
xvyber = x(gj0+kod:gj0+kdo);
hvyber = ... complete yourself ...
ii
[xvyber ; hvyber]
pause
y(gj0+ii) = xvyber * hvyber;
...
When filling selected parts of hvyber, we should realize that components from h are selected in descending order. The
indexing sequence will need -1 as the step. Commands
ii
[xvyber ; hvyber]
pause
will enable to take a look on selected part for given time. When pressing Enter, the computation will go on.

Exercise 3.
Perform convolution using Matlab function conv:
y = conv(x,h);
How many components does the output y contain ? Why ? Where is zeroth time ? Create time axis (e.g., nn) so that
command :
stem(nn,y)
will show the convolution correctly.

Exercise 4.
Verify by arbitrary method that the convolution is commutative, thus it doesnt matter which order of of x and h is chosen.

Convolution continuous time

As we already said in the first lab, we cannot generate in Matlab continuous time signals. Therefore, we will again overcome
this drawback by using very small time step among signal samples. The convolution integral:
Z +
x( )h(t )d.
y(t) =

will be approximated using function conv.

Exercise:
Compute convolution of signal x(t) and impulse response h(t) from the lecture. Both signals are defined for times t = [10, 10]:

0.5 for 0 t 2
1 for 0 t 2
1
for 4 t 6 .
h(t) =
x(t) =
0 elsewhere

0
elsewhere

Beginning of derivation: Lets start similarly as in the first exercise definition of signals:
step = 0.01; t = -10:step:10;
x = zeros(size(t));
x(find(t>=0 & t<=2)) = 1;
h = zeros(size(t));
h(find(t>=0 & t<=2)) = 0.5; h(find(t>=4 & t<=6)) = 1;
subplot (211); plot (t,x); subplot (212); plot (t,h);
Then, perform convolution:
y = conv(x,h);

When convolution will be shown using plot (y), we will find out that it is similar to the results obtained in the lecture.
However, there are inconsistencies in time and magnitudes. Try to solve these problems!
Hints:
If we want to define some sequence from a do b with N points in this interval, we can use linspace(a,b,N).
magnitudes we need to figure out that the integral has been replaced by sum. The sum doesnt know anything about
d . Whats d for us ?

Continuous harmonic signals

Now we will talk about harmonic signals and their decomposition on complex exponentials. Quick revision of fundamental
forms from lecture:
fundamental function:
cos(x) =
cosine with period T1 =

2
1 ,

ejx + ejx
2

but without beginning phase:


C1 cos(1 t) =

C1 j1 t C1 j1 t
e
+
e
.
2
2

arbitrary cosine function with beginning phase:


C1 j(1 t+1 ) C1 j(1 t+1 )
C1 j1 j1 t C1 j1 j1 t
+
e
= c1 ej1 t + c1 ej1 t ,
C1 cos(1 t + 1 ) =
e
+
e
=
e e
e
2
2
2
2
where coefficients c1 = C21 ej1 , c1 = C21 ej1 .

Exercise 1:
Create and show function cos(x) in interval x = [0, 4]. Generate functions e jx and ejx and show that their addition divided
by 2 is really cos(x).
Solution:
x = 0:0.01:4*pi;
plot (x, cos(x));
we check it using zoom (click on zoom, then select using mouse), that a period is really 2. . . and lets continue:
ejx= exp(j*x);
emjx= exp(-j*x);
subplot (311); plot3(x,real(ejx),imag(ejx));
xlabel(x); ylabel(Re); zlabel(Im); grid
subplot (312); plot3(x,real(emjx),imag(emjx));
xlabel(x); ylabel(Re); zlabel(Im); grid
vysl = (ejx + emjx) / 2;
subplot (313); plot(x,vysl);
It can be pretty good to turn our complex exponentials around (click on round arrow, then hold the picture and turn)
the way how plot3 shows them is not very presentable. When turning around, try to see only the projection into <-axisx
and then =-axisx. Do you see cosine and sine functions ?
3

Exercise 2:
Show function 5 cos(100t) for t = [0, 40 ms]. Show that we can obtain this function by composing two exponentials.

Exercise 3:
Show function 5 cos(100t 4 ) for t = [0, 40 ms]. Compute coefficients c1 a c1 and show them. Then show exponentials
multiplied by these two coefficients: c1 ej1 t and c1 ej1 t , take a look at them carefully, and show that their addition
represents the original cosine.
Tool: to show coefficients c1 and c1 we can try out e.g.,:
plot(real(c1), imag(c1),bo,real(cm1), imag(cm1),go); grid
The first will be shown as a blue dot (blue o), the second as a green dot (green o).

You might also like