1

这个问题非常基本,我尝试重复两个 boxcar 函数与convmatlab 中函数的连续卷积的结果。根据http://en.wikipedia.org/wiki/Convolution,它应该导致两个给定函数之间的区域重叠。离散的结果 conv应该被缩放以获得该区域的适当值。一些人建议使用采样频率进行缩放,但它没有给出该区域的正确结果。建议在 Matlabs `conv()`sum(f)的比例因子中使用,但它也不起作用。谁能解释应该使用什么比例因子?或者下面的代码可能有错误?

dx = 0.01
xmin = -0.7;
xmax =  0.7;
box = @(x) 0.5 * (sign(x - xmin) - sign(x - xmax));

x  = -2:dx:2;
f1 = box(x); 
f2 = box(x) * 1.5;
conv1 = conv(f1, f2, 'same');           % no scaling
conv2 = conv(f1, f2, 'same') * dx;      % scale with sampling frequency
conv3 = conv(f1 / sum(f1), f2, 'same'); % scale with sum of f1
conv4 = conv(f1, f2 / sum(f2), 'same'); % scale with sum of f2
conv5 = conv(f1 / sum(f1), f2 / sum(f1), 'same'); % scale with sum of f1 and f2
exact = ones(size(x)) * (xmax - xmin) * min(max(f1), max(f2));
plot(x, f1, 'c--o', x, f2, 'm--o' ...    % plot functions for reference 
     , x, conv2, 'r-'        ... 
     , x, conv3, 'g-'        ... 
     , x, conv4, 'b-'        ... 
     , x, conv5, 'y-'        ... 
     , x, exact, 'k:'         ...    % excat area
     );
legend({'f1' 'f2' 'dx scale' 'f1 scale' 'f2 scale' 'f1 and f2 scale' 'exact'})

上述代码产生的结果

4

0 回答 0