I've been trying to read an audio file in Matlab using this code --

q = audioread('C:\Users\DELL\Downloads\cha1.wav'); figure; plot(q);

Translated to Python, the code looks like this --

import scipy.io.wavfile

tup = scipy.io.wavfile.read("C:/Users/DELL/Downloads/cha1.wav")
orig_sample_rate = tup[0]
q = tup[1]

When I try to plot these in Matlab, they produce the same waveform with different amplitudes.

Figure 1: Matlab code, Figure 2: Python code

How can I make the amplitudes the same? Scaling down did not produce accurate results.

Matlab vs Python

  • 1
    $\begingroup$ what's there to solve? Two different programs interpret the same file differently, but with a factor? That's not a problem, that's just interpretation. $\endgroup$ – Marcus Müller Oct 21 '17 at 19:54
  • $\begingroup$ Sorry, my question wasn't very clear. I want to know how to make the amplitudes the same. Scaling down by a factor did not give accurate results. $\endgroup$ – Aishwarya A R Oct 21 '17 at 20:00
  • $\begingroup$ "not accurate" in which way? What's the difference? (please try to give all relevant info) $\endgroup$ – Marcus Müller Oct 21 '17 at 20:03
  • 1
    $\begingroup$ Is it just that Matlab normalizes with a factor of $2^{15}$ or so? $\endgroup$ – Peter K. Oct 21 '17 at 20:36
  • $\begingroup$ How are you moving from Python to Matlab to plot the second signal ? There might be some spurious gain in the conversion $\endgroup$ – itismeghasyam Oct 21 '17 at 21:41

I suspect python is reading signed 16 bit int values from the wav file whereas Matlab is rescaling it to floating point numbers between [-1,1]. Try the "native" option with audioread in Matlab. https://www.mathworks.com/help/matlab/ref/audioread.html#inputarg_dataType

| improve this answer | |

This function of Matlab use an algorithm that normalized every data of an external medium while Pyhton doesn't do that. You just need multiply the Matlab values to 32,767.0 or divide Python values to the same value. That's number is because you are using a file with each value has 16 bits, but with sign, so $$2^{16}/2 = 32767$$

I Hope you understand me, sorry for my English.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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