title: Rescaling convolution in Matlab
body: <p>I'm trying to numerically calculate multiple convolutions in Matlab and rescaling the result. Because I'm doing discrete convolutions using Matlab's <code>conv</code>, I need to divide the convolution by the number of timesteps taken, <code>N</code>:</p>
  
  <pre><code>N = 1e3;
  % N = 1e5;
  t = linspace(-10,10,N);
  
  x = t.*exp(-t.^2);
  y = exp(-4*t.^2).*cos(t);
  z = (t-2)./((t-2).^2+3^2);
  w = exp(-3*t.^2).*exp(2i*t);
  
  u = conv(x,y,'same')/N;
  % u = conv(conv(conv(x,y,'same')/N,z,'same')/N,w,'same')/N;
  
  plot(t,u)
  </code></pre>
  
  <ul>
  <li><p>My result <code>u</code> appears to be correctly scaled when there's one convolution (I tested with <code>N=1e3</code> and <code>N=1e5</code> timesteps) -- but when I try to do more than one convolution, the <code>N</code> scaling doesn't seem to be right.</p></li>
  <li><p>If I change the <code>t</code> range to <code>linspace(-20,20,N)</code>, the height of <code>u</code> also appears to change.</p></li>
  </ul>
  
  <p>What am I doing wrong and how do I correctly normalize this resultant <code>u</code>?</p>
  
  <p><strong>Edit:</strong> If we normalise one of the functions like <code>u = conv(conv(conv(x,y/sum(y),'same'),z/sum(z),'same'),w/sum(w),'same');</code> this solves the problem from varying the number of timesteps <code>N</code>. (But I'm not sure if this mathematically valid.)</p>