I have an RIR vector $h[n]$ with $N$ samples and an audio source $x[n]$ with $M$ samples. I wish to simulate a 5 seconds audio segment with $x[n]$ randomly located within (timewise).

Using MATLABs conv(x,h) I am getting a result with vales in the range $[-0.3852,0.3242]$.

Using pythons np.convolve(x,h) I get a result with vales in the range $[-12621.9,10624.08]$, which also sounds bad on the headset (I am assuming due to cutoffs).

I do not know where is the difference comming from, as both $h$ and $x$ are the same before the convolution. Normalizing the output of the python version by:


fixes the values. This is true for normalizing by either len(output), len(x) or len(h).

Now I am confused about the best method of action.

  • For a 5-second segment recording, do I have to generate a 5 - second length $h$?
  • Is it best to first pad both $h$ and $x$ with zeros and then convolve or should I convolve and than allocate randomly within a 5 seconds zeros vector?
  • Is it at all reasonable to normalize here?
  • with respect to the former 3 questions, do I normalize by len(output), len(x), len(h) or the number of samples within a 5 seconds segment?

I am aware that there may be more than one correct answer. I am looking for the pros and cons of each course of action and what is the best way to achieve my target.

  • $\begingroup$ What's cinv() in MATLAB? I can't find such function. $\endgroup$
    – Royi
    Sep 3, 2019 at 7:31

1 Answer 1


The scaling difference between your two output is exactly $32767= 2^{15}-1$ which is exactly the maximum amplitude of a 16-bit signed integer. I'm guessing, the difference is how you import the audio into the program: Matlab's $audioread()$ typically normalize the data to $[-1,1]$, i.e. divide by 32767. It would seem that whatever Python method you are using doesn't do this.

Normalization has nothing to do with the length of the filters and it isn't affected by any zero padding. It's all about the scaling conventions of your inputs and outputs, how do you interface with drivers and/or files.

  • $\begingroup$ Got it, thanks a lot. Can you give an additional note on the order of operations regardless of scaling? $\endgroup$
    – havakok
    Sep 4, 2019 at 6:34
  • 1
    $\begingroup$ as long as you use floating point, order of operation doesn't matter. You just need to scale before you output. $\endgroup$
    – Hilmar
    Sep 4, 2019 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.