Skip to content

Decoding spectra and waveforms

GetFFT_Base64 returns a series packed as a base64 string rather than as coordinate pairs. It is far smaller over the wire, but you have to unpack it.

The bytes decode to a 32-bit little-endian float array.

function base64ToFloatArray(base64) {
const binary = atob(base64)
const bytes = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
return new Float32Array(bytes.buffer)
}
import base64, numpy as np
def base64_to_floats(b64: str) -> np.ndarray:
return np.frombuffer(base64.b64decode(b64), dtype="<f4")
static float[] Base64ToFloats(string base64)
{
var bytes = Convert.FromBase64String(base64);
var values = new float[bytes.Length / sizeof(float)];
Buffer.BlockCopy(bytes, 0, values, 0, bytes.Length);
return values;
}

The response gives you amplitudes and a sample rate (SR), not frequencies. For a spectrum, bin i sits at:

frequency = i * (SR / 2) / (numberOfBins - 1)

That is in Hz. If you requested hz: true the service already returns CPM — see Enumerators.

GetThermoData also returns base64, but its payload is a JPEG, not floats. Decode to bytes and write them out as an image file.