user2702110
user2702110

Reputation: 1

how to get hex or binary values from a wavefile in matlab?

i want to compute bit error rate of actual and reconstructed files. For that, what is the way to get binary or hex values from a wave file in mat lab?

Upvotes: 0

Views: 1140

Answers (2)

Eitan T
Eitan T

Reputation: 32930

It seems you're looking for a way to read the file in binary form (that is, not ASCII). You can use fread. For example, consider the following example:

fid = fopen('sample.wav', 'r');  %// Open the file
A = fread(fid, 'uint8');         %// Read binary contents
fclose(fid);                     %// Close the file

This will read the input file "sample.wav" byte by byte (as unsigned 8-bit integers) into array A. Note that when you display the contents of A you'll see its decimal value. For instance, the byte 0x1A would be read as decimal 26 ("hexadecimal" and "binary" are only alternative ways to represent the same value).

Once you have populated A, you can manipulate it by comparing it to another array of values (possibly read from another .WAV file), etc...

Upvotes: 1

Buck Thorn
Buck Thorn

Reputation: 5073

You can obtain hexadecimal string representation of a number using function dec2hex. For binary representation there is dec2bin.

In general, you can find a representation for a number d in digit base format as follows:

d = 97; % example
base = 2; % can be 10, 16, whatever...

rep=rem(floor(d*base.^(1-ceil(log(d)/log(base)):0)),base)

% check:
rep*base.^[length(rep)-1:-1:0]'

It works on column vectors too.

Upvotes: 0

Related Questions