为什么matlab得到的卷积与理论上得到的不同?
指数函数与正弦函数卷积的理论结果如下所示。
当我直接使用 matlab 绘制函数时,我得到了这个,
然而 Matlab conv 命令产生了这个,
这两个图看起来很相似,但它们并不相同,请参见比例尺。matlab 良率是理论结果的十倍。为什么?
matlab 代码在这里。
clc;
clear all;
close all;
t = 0:0.1:50;
x1 = exp(-t);
x2 = sin(t);
x = conv(x1,x2);
x_theory = 0.5.*(exp(-t) + sin(t) - cos(t));
figure(1)
subplot(313), plot(t, x(1:length(t))); subplot(311), plot(t, x1(1:length(t))); subplot(312), plot(t, x2(1:length(t)))
figure(2)
subplot(313), plot(t, x_theory); subplot(311), plot(t, x1(1:length(t))); subplot(312), plot(t, x2(1:length(t)))
回答
conv做离散时间卷积,它不做数学积分函数。从数字上讲,这基本上意味着将两个信号的结果相乘和相加多次,每个点一次,其中一个信号有一个小的偏移。
如果您考虑这一点,您就会意识到信号的采样会产生影响。即,如果每 0.1 个值或 0.001 个值有一个点,则乘以的点数不同,因此结果的值不同(不是形状)。
因此,每次进行数值卷积时,总是需要乘以采样率,以“规范化”操作。
只需更改您的代码即可
sampling_rate= 0.1;
t = 0:sampling_rate:50;
x = conv(x1,x2)*sampling_rate;
- @Vikash change the sample rate. Try 0.5. Now try 0.01. A numerical solution will always just be an approximations to the analytical one. This is true for all numerical approximations, not just convolution. (luckily this is why mathematicians still have a job :D)
- @Vikash the right sampling rate is "0", i.e. infinite sampling points. Obviously this is impossible. Anything larger will always have some error. This is why analytical solution for problems are generally desired.
- @Vikash: Your sine function can be properly sampled with only just over two samples per period. But the exponential function cannot be sampled, you always make an error. Fourier analysis shows you how much of the power of the signal gets lost to aliasing. This allows you to pick a sampling rate where the loss of power is acceptable in your application.