How do I decode the mOPM logging binary floating point code data points?
Knowledge Base - FAQ
How do I decode the mOPM logging binary floating point code data points?
To convert the mOPM logging binary floating point code data points to dBm, they must be in hexadecimal only (actual raw bytes).
Below is noted in the mOPM user manual.
**************************************************************************************************************************************************
:SENSe:LOGging:DATA? [start] [len]
Use SCPI Binary Block Protocol
Returns array of IEEE floats with powers in dBm. This requires a user to capture the binary data and post-process to convert it to numeric value
**************************************************************************************************************************************************
As indicated in the description for the SCPI command ":SENSe:LOGging:DATA?", the output format is...
'#[d][L][8-bit 1][8-bit 2] … [8-bit L]'
The first byte [d] specifies the number of bytes for [L]
[L] is the number of 8-bits> or number of bytes following [L].
Every 4 [8-bits] is a floating point value of 1 data point. Note that the byte order is little endian which means the first byte returned in sequence is the least significant byte and the fourth is the most significant.
See IEEE Std 488-2 document for more info.
Section 9.3 of that standard describes the Binary Floating Point Code. Each point is 4 bytes (32 bits) so the 32 bit single format number is used. Section 9.3.4 also includes an example.
Sign field [s] width = 1 bit
Exponent field [e] width = 8 bits
Fraction field [f] width = 23 bits
Total width = 32 bits
Value [v] = (-1)^s * 2^(e-127) * (1.f)
Following are the first 25 bytes returned from the ":SENSe:LOGging:DATA?" query of 400 data points in one case.
23 33 34 30 30 D8 34 BA C0 8F 83 BA C0 AF 4D BA C0 F9 72 BA C0 1C 5A BA C0
Using this data as an example, following is how to decode.
0x23 = # (ASCII)
[d] = 0x33 = 3 (ASCII)
[L] = 0x34 0x30 0x30 = 400 (ASCII)
[data point1] = 0xC0BA34D8 = b1 10000001 01110100011010011011000
s = b1 = 1 (decimal)
e = b10000001 = 129 (decimal)
f = b01110100011010011011000 = 0.454737663269043 (decimal)
v = (-1)^1 * 2^(129-127) * (1.454737663269043) = -5.81895 dBm
[data point2] = 0xC0BA838F = b1 10000001 01110101000001110001111
s = b1 = 1 (decimal)
e = b10000001 = 129 (decimal)
f = b01110100011010011011000 = 0.457139849662781 (decimal)
v = (-1)^1 * 2^(129-127) * (1.457139849662781) = -5.82856 dBm
[data point3] = 0xC0BA4DAF = b1 10000001 01110100100110110101111
s = b1 = 1 (decimal)
e = b10000001 = 129 (decimal)
f = b01110100011010011011000 = 0.455495715141296 (decimal)
v = (-1)^1 * 2^(129-127) * (1.455495715141296) = -5.82198 dBm
[data point4] = 0xC0BA72F9 = b1 10000001 01110100111001011111001
s = b1 = 1 (decimal)
e = b10000001 = 129 (decimal)
f = b01110100011010011011000 = 0.456633687019348 (decimal)
v = (-1)^1 * 2^(129-127) * (1.456633687019348) = -5.82653 dBm
[data point5] = 0xC0BA5A1C = b1 10000001 01110100101101000011100
s = b1 = 1 (decimal)
e = b10000001 = 129 (decimal)
f = b01110100011010011011000 = 0.455874919891357 (decimal)
v = (-1)^1 * 2^(129-127) * (1.455874919891357) = -5.82350 dBm