# matlab convertion from .wav to binary

Status
Not open for further replies.

#### kimo77

##### Newbie level 3 hi all,
I want to convert an audio or a wav file into binary form like y=.. i found the fun wavread but it give me result from -1 to 1 and not a a form of vector... so can any one help me how to convert the wave file to the binary
thank u

#### Communications_Engineer • Points: 2

#### kimo77

##### Newbie level 3 ok ..any suggestion about the function using in matlab for adc & codec.....Thx for ur help

• Points: 2

#### mowgli

##### Full Member level 2 Hello kimo77

I don't know the function wavread but from what you wrote ("... result from -1 to 1 ") I suppose that it returns the numeric values of the audio samples encoded in the .wav file. The range (-1,1) is normal if you are considering a stream of fixed point values in Q1.xx format, where xx stands for the bits used to represent the decimals digits (e.g. Q1.15 for 16 bit numbers)
If you want a binary stream you have to convert the numeric array obtained by the wavread function from decimal to binary format (check in Mlab the usage of functions num2hex, num2bin, hex2bin or similar, sorry but I don't remember the exact names).
Be careful in specifying the quantizer when using those functions, to represent correctly the format used to acquire the samples.

Regards
Mowgli

• ### kimo77

Points: 2

Points: 2

#### Jack// ani mowgli said:
The range (-1,1) is normal if you are considering a stream of fixed point values in Q1.xx format, where xx stands for the bits used to represent the decimals digits (e.g. Q1.15 for 16 bit numbers)

Sorry if this is going off topic, but according to Wikipedia Q1.15 will be 17bit, here is an example provided, can you please explain how?

For example, a Q14.1 format number:

* requires 14+1+1 = 16 bits
* its range is [-2^14, 2^14 - 2^-1] = [-16384.0, +16383.5] = [0x8000, 0x8001 … 0xFFFF, 0x0000, 0x0001 … 0x7FFE, 0x7FFF]
* its resolution is 2^-1 = 0.5

https://en.wikipedia.org/wiki/Q_(number_format)

• ### kimo77

Points: 2

Points: 2

#### mowgli

##### Full Member level 2 Sorry for the disguise: Q1.15 is equal to Q15 definition found in Wikipedia
It defines 16 bit fixed point format with one sign bit and 15-bits fractional part
-1^B15 x Sum(2^-Bn)
where B15 is MSB and B0 is LSB

So the range for this format is [-1, 0.99996948242188] or which is represented by hex coded numbers in the range [0x8000, ox7FFF]. For simplicity this range is typically referred to as -1 to 1.

If you are curious try this in Matlab
q = quantizer([16,15])
hex2num(q,'7FFF')
hex2num(q,'8000')
num2hex(q,1)
num2hex(q,-1)
num2hex(q,2)
num2hex(q,-2)

Regards
Mowgli

• 