Read a binary file with many type of data (Int64-int​32-int64-i​nt32....)

13 views (last 30 days)
Hi,
i have a binary file generated by a DAQ equipment
This file contains header + data
this is the structure of the Header
64 bit 32 bit 64 bit 32 bit 32 bit 32 bit
The data is structured : Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 ......
The type of data is int32
sampling rate depends of the configuration in my case is : 4Khz.
any idea ?
i have to read it bit by bit ?

Answers (1)

Walter Roberson
Walter Roberson on 11 Sep 2023
fid = fopen('filename');
H1 = fread(fid, 1, '*uint64');
H2 = fread(fid, 1, '*uint32');
H3 = fread(fid, 1, '*uint64');
H4 = fread(fid, 3, '*uint32');
data = fread(fid, [8 inf], 'int32') .';
fclose(fid);
You might need to adjust the datatypes of the header items.
You might need to use swapbytes
  3 Comments
Walter Roberson
Walter Roberson on 11 Sep 2023
fid = fopen('filename', 'r', 'ieee-be'); %big endian
header.firstDate_s = fread(fid, 1, '*uint64');
header.firstDate_ns = fread(fid, 1, '*int32');
header.secondDate_s = fread(fid, 1, '*uint64');
header.secondDate_ns = fread(fid, 1, '*int32');
header.maskVoi = fread(fid, 1, '*int32');
header.size = fread(fid, 1, '*int32');
data = fread(fid, [8 inf], 'int32') .';
fclose(fid);

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!