How to read binary data using matlab.

11 views (last 30 days)
Habtamu Wubie
Habtamu Wubie on 25 Apr 2017
Commented: Image Analyst on 26 Apr 2017
I have a 55.4 GB binary data with a file name hab.bin. Its corresponding mettadata file contains the following information.
Start Time: 03/25/17 - 07:04:24:972357994
Channels: 8
TX Sample Rate: 13000000 Hz
TX Center Frequency: 49900000 Hz
RX Sample Rate: 200000 Hz
RX Center Frequency: 49900000 Hz
Baud Width: 20 usec
Inter-pulse Period: 5 msec
Number of Baud: 13
Phase Code: 1,-1,1,-1,1,1,-1,-1,1,1,1,1,1
Phase Increments:
Increment: 0 deg, Pulses: 100
Sampling Period: 5 usec
Num Sampling Periods: 300
Front Porch Time: 15 usec
Back Porch Time: 30 usec
To say something about the data: it is obtained from coherent backscatter radar with operating parameters given above in the metadata file. I tried to read the data in the command window and results in
>> fid=fopen('hab.bin');
>> a=fread(fid)
a =
[]
>> a=fopen(fid)
a =
/home/virtual/Desktop/data/hab.bin
>>
As you can see the final result is only the path of my binay data, hab.bin. Any help please?
  2 Comments
Jan
Jan on 25 Apr 2017
What exactly is your question?
Habtamu Wubie
Habtamu Wubie on 26 Apr 2017
Jan Simon:
Just simply, I want to convert the binary data to base 10. If it is not clear still, please ask me again. thanks

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Apr 2017
Use more input arguments for fread(). For example, here is a snippet from my code where I read the header of a binary file into a structure called stHeader:
% Read in the dimensions for the different directions.
% They'll be in bytes 9-20.
stHeader.x_size = fread(fileHandleID, 1, '*int32');
stHeader.y_size = fread(fileHandleID, 1, '*int32');
stHeader.z_size = fread(fileHandleID, 1, '*int32');
stHeader.TotalVoxels = stHeader.x_size * stHeader.y_size * stHeader.z_size;
% Read in the position of the center of the first pixel.
% They'll be in bytes 21-32.
stHeader.XStart = fread(fileHandleID, 1, '*float');
stHeader.YStart = fread(fileHandleID, 1, '*float');
stHeader.ZStart = fread(fileHandleID, 1, '*float');
Note the second and third arguments I used with fread().
  2 Comments
Habtamu Wubie
Habtamu Wubie on 26 Apr 2017
Image Analyst :
I tried to apply your suggestion but still it is not working. According to your code the value of the variable stHeader.x_size is empty vector/matrix.
To clarify my question: At the end of the matlab script I should get a vector or a matrix whose elements are obtained by converting the binary file into base 10.Any way thank you for your suggestion.
Image Analyst
Image Analyst on 26 Apr 2017
Nonetheless, that's the way to do it. You have to know the format, like how many bits there are for each attribute, what data type they are, and what order they're in.
fread(fileHandleID, 1, '*int32') should return something so I'm surprised that you say it's empty. Even if it's being interpreted wrong or pointing to the wrong location, it should return 4 bytes, not an empty array. Perhaps if you attach hab.bin and your format (bytes, order, and class) we can see what we can do.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!