How to read binary data using matlab.

12 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-4-25
What exactly is your question?
Habtamu Wubie
Habtamu Wubie 2017-4-26
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

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2017-4-26
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 个评论
Habtamu Wubie
Habtamu Wubie 2017-4-26
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 2017-4-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by