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

13 vues (au cours des 30 derniers jours)
StSab
StSab le 11 Sep 2023
Commenté : StSab le 11 Sep 2023
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 ?

Réponses (1)

Walter Roberson
Walter Roberson le 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 commentaires
Walter Roberson
Walter Roberson le 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);
StSab
StSab le 11 Sep 2023
thanks !!
it works !
'ieee-be' big endian

Connectez-vous pour commenter.

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by