简体   繁体   English

如何解码 IEEE754 标准中的 16 位带符号二进制文件

[英]How to decode 16-bit signed binary file in IEEE754 standard

I have a file format called.ogpr (openGPR, a dead format used for Ground Radar data), I'm trying to read this file and convert it into a matrix using Matlab(R).我有一个名为 .ogpr 的文件格式(openGPR,一种用于地面雷达数据的无效格式),我正在尝试读取该文件并使用 Matlab(R) 将其转换为矩阵。

In the first part of file there is a JSON Header where are explained the characteristics of data acquisition (number of traces, position etc), and on the second part there are two different data blocks.在文件的第一部分有一个 JSON Header,其中解释了数据采集的特征(迹线数,position 等),在第二部分有两个不同的数据块。 First block contains the 'real' GPR data and I know that they are formatted as:第一个块包含“真实”探地雷达数据,我知道它们的格式为:

  1. Multibyte binary data are little-endian多字节二进制数据是小端
  2. Floating point binary data follow the IEEE 754 standard浮点二进制数据遵循 IEEE 754 标准
  3. Integer data follow the two's complement encoding Integer数据按照二进制补码编码

I know also the total number of bytes and also the relative number of bytes for each single 'slice' (we have 512 samples * 10 channel * 3971 slices [x2 byte per sample]).我还知道字节总数以及每个“切片”的相对字节数(我们有 512 个样本 * 10 个通道 * 3971 个切片 [每个样本 x2 字节])。 Furthermore: 'A Data Block of type Radar Volume stores a 3D array of radar Samples At the moment, each sample value is stored in a 16-bit signed integer. Each Sample value is in volts in the range [-20, 20].'此外:'雷达卷类型的数据块存储雷达样本的 3D 数组目前,每个样本值存储在 16 位带符号的 integer 中。每个样本值以伏特为单位,范围为 [-20, 20]。 '

Second block contains geolocation infos.第二个块包含地理位置信息。

I'd like to read and convert the Data Block from that codification but it ain't clear especially how many bytes break the data and how to convert them from that codification to number.我想从该编码中读取和转换数据块,但不清楚有多少字节破坏了数据以及如何将它们从该编码转换为数字。

I tried to use this part of code:我尝试使用这部分代码:

bin_data = ogpr_data(48:(length(ogpr_data)-1),1);
writematrix(bin_data, 'bin_data.txt');
fileID = fopen('bin_data.txt', 'r', 'ieee-le');
format = 'uint16';
Data = fread(fileID, Inf, format);fclose(fileID)

Looks like your posted code is mixing text files and binary files.看起来您发布的代码混合了文本文件和二进制文件。 The writematrix( ) routine writes values as comma delimited text. writematrix( ) 例程将值写入逗号分隔文本。 Then you turn around and try to use fopen( ) and fread( ) to read this as a binary file in IEEE Little Endian format.然后你转身并尝试使用 fopen() 和 fread() 将其读取为 IEEE Little Endian 格式的二进制文件。 These are two totally different things.这是完全不同的两件事。 You need to pick one format and use it consistently, either human readable comma delimited text files, or machine readable binary IEEE format files.您需要选择一种格式并始终如一地使用它,可以是人类可读的逗号分隔文本文件,也可以是机器可读的二进制 IEEE 格式文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM