# Convolution between two vectors. Length and normalization

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:

output=np.convolve(x,h)
output=output/len(output)


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.

• What's cinv() in MATLAB? I can't find such function. – Royi Sep 3 '19 at 7:31

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.