Note that there are some explanatory texts on larger screens.

plurals
  1. POScaling factor for convolution in matlab to get proper area
    primarykey
    data
    text
    <p>The question is pretty basic, I try to repeat results for continues convolution of two boxcar functions with <code>conv</code> function in matlab. Accordingly to <a href="http://en.wikipedia.org/wiki/Convolution" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Convolution</a> it should result in the area overlap between the two given function. The results of discrete <code>conv</code> 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 <code>sum(f)</code> in <a href="https://stackoverflow.com/questions/17412097/scale-factor-in-matlabs-conv">Scale Factor in Matlabs `conv()`</a> 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?</p> <pre><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'}) </code></pre> <p><img src="https://i.stack.imgur.com/pB2c8.png" alt="Results produced by the code above"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload