Why is the convolution for the same signals different?
Mostrar comentarios más antiguos
Here is the code for convolution of two signals. I have two questions:
1) If I change the number of datapoints from n=1000 to n=100, the output is different. Why? How do I make sure that the given outout is the correct result?
2) Is it okay to label the x-axis of the last plot as "time" in this particular case?
n = 1000; % Whatever.
f = .10; % Whatever.
tau = 2; % Whatever.
t = linspace(0, 4*pi, n); % Time.
x = sin(2*pi*f*t);
h = exp(-t/tau);
y = conv(x, h, 'full');
% Plot u
subplot(3, 1, 1);
plot(t, x, 'b--', 'LineWidth', 3);
grid on;
set(gca,'xscale', 'linear', 'FontSize', 28)
set(gca,'yscale', 'linear', 'FontSize', 28)
set(gca,'XMinorTick', 'on')
set(gca,'YMinorTick', 'on')
xlim([0 12]);
xlabel('Time, $t$', 'interpreter', 'latex', 'FontSize', 40);
ylabel('$x\left(t\right)$', 'interpreter', 'latex', 'FontSize', 40);
title('Input, $x\left(t\right)=\sin\left(2\pi f t\right),\mbox{ }f=0.10$', 'interpreter', 'latex', 'FontSize', 44);
% Plot g
subplot(3, 1, 2);
plot(t, h, 'r-.', 'LineWidth', 3);
grid on;
set(gca,'xscale', 'linear', 'FontSize', 28)
set(gca,'yscale', 'linear', 'FontSize', 28)
set(gca,'XMinorTick', 'on')
set(gca,'YMinorTick', 'on')
xlim([0 12]);
xlabel('Time, $t$', 'interpreter', 'latex', 'FontSize', 40);
ylabel('$h\left(t\right)$', 'interpreter', 'latex', 'FontSize', 40);
title('Impulse response, $h\left(t\right)=e^{-t/\tau},\mbox{ }\tau=2$', 'interpreter', 'latex', 'FontSize', 44);
% Plot out
subplot(3, 1, 3);
plot(y, 'k-', 'LineWidth', 3);
grid on;
set(gca,'xscale', 'linear', 'FontSize', 28)
set(gca,'yscale', 'linear', 'FontSize', 28)
set(gca,'XMinorTick', 'on')
set(gca,'YMinorTick', 'on')
xlim([0 140]);
xlabel('Time, $t$', 'interpreter', 'latex', 'FontSize', 40);
ylabel('$y\left(t\right)$', 'interpreter', 'latex', 'FontSize', 40);
title('Output, $y\left(t\right)=x\left(t\right)*h\left(t\right)$', 'interpreter', 'latex', 'FontSize', 44);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
3 comentarios
Hi Vikash,
Two things to consider:
1) The code assumes that x(t) and h(t) are both 0 outside the interval 0 <= t <= 4*pi. If either x(t) or h(t) extend to infinite time, then conv can't be used, at least not to get the full solution (though in a practical sense there will be some time, tc, where for t > tc h(t) could probably be safely assumed to be zero).
2). If x(t) and h(t) are both 0 outside that interval, then the output conv needs to be multiplied by a dt so that result approximates the convolution integral, assuming the convolution integral is the goal.
3. If the convolution integral is the goal, consider the Symbolic Toolobox, if you have access to it, to get its closed form expression.
Vikash Pandey
el 3 de Ag. de 2023
Paul
el 3 de Ag. de 2023
Correct. In this problem, that scaling needs to be applied if you want the the output of conv, which is the convolution sum of discrete time samples, to be samples that approximate the convolution integral of the underlying continuous time signals. If either x(t) or h(t) had included a Dirac delta function, we'd have to do just bit more work to use conv to approximate the convolution integral.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

