Convolution of two signal

29 visualizzazioni (ultimi 30 giorni)
Tayfun Çelebi
Tayfun Çelebi il 13 Apr 2019
Modificato: Paul il 24 Mar 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 Commenti
Walter Roberson
Walter Roberson il 13 Apr 2019
Modificato: Walter Roberson il 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 il 14 Apr 2019
thanks. I have the symbolic toolbox

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 23 Mar 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 il 24 Mar 2021
Modificato: Paul il 24 Mar 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by