Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

matlab convertion from .wav to binary

Status
Not open for further replies.

kimo77

Newbie level 3
Newbie level 3
Joined
Apr 24, 2010
Messages
4
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
egypt
Activity points
1,307
hi all,
I want to convert an audio or a wav file into binary form like y=[100110111].. 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
 

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
 
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)
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top