Convolution of two signal

31 Ansichten (letzte 30 Tage)
Tayfun Çelebi
Tayfun Çelebi am 13 Apr. 2019
Bearbeitet: Paul am 24 Mär. 2021
How can I write the convolution code of the function below?
u(t)=sin(2*pi*f*t)
g(t)=exp(-t/tau)
Analytically or with con(,) ?
  2 Kommentare
Walter Roberson
Walter Roberson am 13 Apr. 2019
Bearbeitet: Walter Roberson am 13 Apr. 2019
If you have the symbolic toolbox then it might be easiest to use the laplace transform:
laplace(u convolved with g) = laplace(u) times laplace(g)
and take the inverse laplace of both sides...
Tayfun Çelebi
Tayfun Çelebi am 14 Apr. 2019
thanks. I have the symbolic toolbox

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Apr. 2019
Try this:
numPoints = 1000; % Whatever.
f = .10; % Whatever.
tau = 2; % Whatever.
t = linspace(0, 4*pi); % Whatever.
u = sin(2*pi*f*t);
g = exp(-t/tau);
out = conv(u, g, 'full');
% Plot u
subplot(3, 1, 1);
plot(t, u, 'b-', 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', 12);
ylabel('u', 'FontSize', 12);
% Plot g
subplot(3, 1, 2);
plot(t, g, 'b-', 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', 12);
ylabel('g', 'FontSize', 12);
% Plot out
subplot(3, 1, 3);
% plot(t, out, 'b-', 'LineWidth', 2); % Would need to compute the new t if you want this.
plot(out, 'b-', 'LineWidth', 2); % Just plot vs. index.
grid on;
xlabel('t', 'FontSize', 12);
ylabel('out', 'FontSize', 12);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
0001 Screenshot.png
  15 Kommentare
Image Analyst
Image Analyst am 23 Mär. 2021
If you use 'same', the t axis will be the same. If you use 'full', the t axis will be bigger on both ends by half a window width. You can calculate what that time would be. If you use 'valid', it will of course be less, coming in by half a window width on either end.
The amplitude is what it is and it is correct. If you want to scale it, you're free to do so. If you make the sum of the kernel window, g, elements 1, then the mean of the output signal will be the same as the mean of the input signal.
Paul
Paul am 24 Mär. 2021
Bearbeitet: Paul am 24 Mär. 2021
The following code shows how to compute the result three different ways, assuming that both functions to be convolved are zero for t < 0 (as suggested in the original question):
syms t f tau s w
syms u(t,f) g(t,tau) yconvint(t,f,tau)
u(t,f) = sin(2*sym(pi)*f*t)*heaviside(t);
g(t,tau) = exp(-t/tau)*heaviside(t);
% time domain convolution integral
yconvint(t,f,tau) = int(g(w,tau)*u(t-w,f),w,0,t);
yconvint(t,f,tau) = simplify(rewrite(yconvint(t,f,tau),'sincos'));
% inverse Laplace
ylaplace(t,f,tau) = ilaplace(laplace(u(t,f))*laplace(g(t,tau)));
% discretized convolution
% assume values for f and tau
fval = 1; tauval = 0.5;
% time vector
dt = 0.02;
tvec = 0:.02:10;
ufunc = matlabFunction(u(t,f),'Vars',[t f]);
gfunc = matlabFunction(g(t,tau),'Vars',[t tau]);
yconvdis = conv(ufunc(tvec,fval),gfunc(tvec,tauval));
plot(tvec,double(yconvint(tvec,fval,tauval)),tvec,double(ylaplace(tvec,fval,tauval)),'o',tvec,yconvdis(1:numel(tvec))*dt,'x'),grid
The discretized convolution needs to be scaled by dt to match the true, continuous convolution.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by