Documente Academic
Documente Profesional
Documente Cultură
f g (t ) f g t d (1.1)
In Matlab in order to implement the convolution first we must define the two signals as
functions. Let us consider the following signals:
2, for t (0,3)
f (t ) (1.2)
0, otherwise
3, for t (0,5)
g (t ) (1.3)
0, otherwise
thr = 0.00001;
for i=1:length(t)
if (t(i) - thr > 0)&&(t(i) + thr < 5)
y(i) = 3;
end
end
Next we will represent the two functions according to 6,10 , so that we display the
whole function:
step =0.1;
tau=-6:step:10;
figure(1);
subplot(2,1,1);
plot(tau,f(tau));
% With axis(xmin, xmax, ymin, ymax) we establish the limits for
% displaying the graphs so that we see the whole signal
axis([min(tau), max(tau), -1, 4]);
xlabel('Time \tau [s]'), ylabel('Amplitude'), title('f(\tau)');
% We use the “grid” command to display a grid on the graph so that we visualize
the graphs easier
grid;
subplot(2,1,2);
plot(tau,g(tau));
axis([min(tau), max(tau), -1, 4]);
xlabel('Time \tau [s]'), ylabel('Amplitude'), title('g(\tau)');
grid;
Next we will determine the convolution by computing the integral (1.1) for every t tmin , tmax
. The values of tmin and t max should be chosen so that we include all the values of the convolution.
We know from the seminar that for the signals considered in the example above the convolution will
have the support 0,8 , therefore we will choose tmin 1 , tmax 9 and determine the convolution:
tmin = -1;
tmax = 9;
t = tmin:step:tmax;
for index_t=1:length(t)
% We display on the first plot the 3 signals f(tau), g(t-tau) and
% f(tau)*g(t-tau)
figure(2);
subplot(211);
plot(tau,f(tau),'b');
xlabel('Time \tau [s]');
ylabel('Amplitude');
title('Signals f(\tau), g(t-\tau) and their product');
hold on
plot(tau,g(t(index_t)-tau),'r');
prod = f(tau).*g(t(index_t)-tau);
stem(tau, prod,'g');
hold off
% We use axis in order to specify the limits of the figure
axis([min(tau),max(tau),-1,7]);
% With legend() we ca display the name of each graph
legend('f(\tau)', 'g(t-\tau)', 'f(\tau)*g(t-\tau)');
grid;
The graphs will display an animation with the calculus of the convolution of the two signals. A
frame from this animation is presented in the following figure:
Note: at the beginning of the script we should use the following commands in order to erase
the variables from previous runs of the script:
close all;
clear;
clc;
f ˆ g (t ) f g t d (1.4)
Since the two operations are very similar we can modify the previous program to display the
correlation of signals f ( ) and g ( ) as follows:
tmin = -4;
tmax = 6;
t = tmin:step:tmax;
for index_t=1:length(t)
% We display on the first subplot the 3 signals f(tau), g(t-tau) and
% f(tau)*g(t-tau)
figure(2);
subplot(211);
plot(tau,f(tau),'b');
xlabel('Time \tau [s]');
ylabel('Amplitude');
title('Signals f(\tau), g(\tau+t) and their product');
hold on
plot(tau,g(tau + t(index_t)),'r');
prod = f(tau).*g(tau + t(index_t));
stem(tau, prod,'g');
hold off
% We use axis in order to specify the limits of the figure
axis([min(tau),max(tau),-1,7]);
% With legend() we ca display the name of each graph
legend('f(\tau)', 'g(\tau+t)', 'f(\tau)g(\tau+t)');
grid;
3. Homework
Given two non periodic signals:
t 5, t 3,8
g (t ) (1.6)
0, otherwise
using Matlab, compute the following operations and display the corresponding results:
a) f ˆ g (t ) d) f g (t ) g) f ˆ g (t )
b) g ˆ f (t )
e) f g (t ) h) f3 ˆ g (t )
c) f g (t ) f) f g3 (t )
i) f g 5 (t )