Scaling factor for convolution in matlab to get proper area

纵饮孤独 提交于 2019-12-24 14:05:49

问题


The question is pretty basic, I try to repeat results for continues convolution of two boxcar functions with conv function in matlab. Accordingly to http://en.wikipedia.org/wiki/Convolution it should result in the area overlap between the two given function. The results of discrete conv should be scaled to get a proper value for the area. Some suggest scaling with sampling frequency, but it does not give correct results for the area. It was suggested to use sum(f) in Scale Factor in Matlabs `conv()` but it does not work either. Can anybody explain what scaling factor should be used? Or maybe there is an error in the following code?

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'})

来源:https://stackoverflow.com/questions/17503835/scaling-factor-for-convolution-in-matlab-to-get-proper-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!