MATLAB: Convolution of two signal

convolution analytically or function code

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(,) ?

Best Answer

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
Related Question