在matlab中进行卷积的缩放因子以获得适当的区域

时间:2013-07-06 14:23:28

标签: matlab convolution

问题非常基本,我尝试重复结果,在matlab中使用conv函数继续卷积两个boxcar函数。因此http://en.wikipedia.org/wiki/Convolution它应该导致两个给定函数之间的区域重叠。应该缩放离散conv的结果以获得该区域的适当值。有些人建议使用采样频率进行缩放,但不能为该区域提供正确的结果。建议在Scale Factor in 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'})

Results produced by the code above

0 个答案:

没有答案