5
$\begingroup$

When processing wav files, I encounter this problem: the what I extract PCM from a 8-bit encoded .wav file, I got a sequence of integers. However, when verifying my implementation with wavread in Matlab, the PCM code is represented with so-called double-precision normalized samples. My question is what's the difference between these two format. For example, the hex number is 0x80 0x81, the corresponding double-precision normalized samples are 0, 0.0078. IIRC, PCM code in .wav file records sound pressure value of audio. Is double-precision normalized samples sound pressure level? If so the value should be $10log(P_1/P_2)$ (based 10). But $10log(129/128)$is not 0.078 instead $10ln(129/128)$(based $e$) is. Anything wrong with my intuition?

Thanks and best regards.

$\endgroup$
7
$\begingroup$

The PCM values are proportional to the sound pressure. 8-bit PCM is stored with an offset of 128, so PCM coded values from 0 to 255 code for 'pressure values' from -128 to 127. These values are often normalized to the range -1.0..+1.0. The PCM values are linear representation of the sound pressure, and a log operation is only required if you want to express the sound pressure in decibels. To get actual sound pressure levels in Pascal or dB(A) you would need a calibrated .wav signal.

$\endgroup$
  • 1
    $\begingroup$ Thanks for the reply. So the 0.0078 comes from $(129-128)/128$? $\endgroup$ – Summer_More_More_Tea Mar 11 '12 at 11:19
  • $\begingroup$ Yes, the [0, 255] range is mapped to [-1, 1 - 1 / 256.0] using the transformation you gave. $\endgroup$ – pichenettes Mar 11 '12 at 11:46
  • $\begingroup$ @pichenettes Thanks. Thank you all. That's what I need! $\endgroup$ – Summer_More_More_Tea Mar 11 '12 at 12:08
  • 1
    $\begingroup$ You need to calibrate the microphone for that. A calibrator generates a signal with a precisely known sound pressure level, then from the recorded PCM levels you can calculate the scale factor. $\endgroup$ – Han Mar 12 '12 at 8:33
  • 1
    $\begingroup$ @endolith -1 in 2's-complement is 1111110 binary. In 8-bit PCM -1 is 01111111. $\endgroup$ – Han Mar 12 '12 at 20:59
3
$\begingroup$

http://www.mathworks.com/help/techdoc/ref/wavread.html

waveread() has an extra argument that will allow to read data in it's "native" format so you can avoid the output scaling and conversion to double precision. It has also optional output arguments that describe the exact format (sample rate, word width, etc.).

The data is supposed to be proportional to the linear sound pressure but with an arbitrary scale factor. 8 bit is rather poor resolution for audio, this may not be good enough to do any sound pressure level calculation

$\endgroup$

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.