1

I want to normalize the result of the read function in wave package in Python. I thought, it should be done by dividing it by 32767. But when I compare the result with the results from MATLAB, dividing it by 32768, gives a better result. So ideally, should it be divided by 32768?

Python code:

a = read('male 1.wav')
data = np.array(a[1],dtype=float)
dataDivide32768 = data/32768
dataDivide32767 = data/32767
print(dataDivide32768)
print(dataDivide32767)

Result:

dataDivide32768:
[ -3.05175781e-05   6.10351562e-05   9.15527344e-05 ...,  ]
dataDivide32767:
[ -3.05185095e-05   6.10370190e-05   9.15555284e-05 ...,   ]

MATLAB code:

filename = 'male 1.wav';
[y,Fs] = wavread(filename);

Result:

[-3.05175781250000e-05 6.10351562500000e-05  9.15527343750000e-05  ...]
user3852441
  • 310
  • 3
  • 14
  • @huon-dbaupp Could you please help me with this. in the answer for the question, http://stackoverflow.com/questions/10357992/how-to-generate-audio-from-a-numpy-array you have mentioned multiplying by 32767 to unnormalize the values? But is 32768 the right value for normalizing/unnormalizing? I do not have enough reputation to comment on the original post. Thanks in advance – user3852441 Aug 19 '15 at 09:51

1 Answers1

3

Assuming that the wav-file is 16 bit integer, the range is [-32768, 32767], thus dividing by 32768 (2^15) will give the proper twos-complement range of [-1, 1-2^-15]

Jørgen
  • 853
  • 9
  • 16
  • Thanks for the anwer. In the accepted answer for the question http://stackoverflow.com/questions/10357992/how-to-generate-audio-from-a-numpy-array, it is mentioned that it has to be multiplied by 32767 to unnormalize. So shouldn't the reverse for normalizing? Or is that answer wrong? Any help? – user3852441 Aug 19 '15 at 10:56
  • 1
    The range is not symmetric as assummed in http://stackoverflow.com/questions/10357992/how-to-generate-audio-from-a-numpy-array where the random values are chosen between [-1, 1]. Actually by multiplying by 32767, the most negative value you will get is -32767 and not -32678 as the integer range provides. In practice it does not matter much :) – Jørgen Aug 19 '15 at 11:33