This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

VoxelSDK bug, ToFTintinCamera::_getIlluminationFrequency(...) most often produces a wrong result.

Hello TI,

In VoxelSDK 6.3, after this commit there was a change in the gcd function, now using floats instead of integer arguments. The sole purpose was to make (a new version of) ToFTintinCamera::_getIlluminationFrequency(float& frequency) now also work correctly for "fractional frequencies" (so when MOD_M_FRAC1 and/or MOD_M_FRAC2 are non-zero). This approach is however seriously flawed! To see this yourself, try to set base frequency f1 to 40.2 MHz, and take MA=2, MB=3. With these we get:

QUAD_CNT_MAX = 6, MOD_N1 = 2, MOD_N2 = 2, MOD_PS1 = 1, MOD_PS2 = 0, MOD_M1 = 20, MOD_M2 = 15;
MOD_M_FRAC1 = 6553, MOD_M_FRAC2 = 4915; // f1 = 40.2 MHz;


Using ToFTintinCamera::_getIlluminationFrequency(frequency) when these parameters are set, gives:  frequency = 0.000031 (MHz) !!!

This is obviously bogus. For some "lucky" choices of f1 we may not see the bug: if we want to make f1 = 40.1, we use MOD_M_FRAC1 = 3276, MOD_M_FRAC2 = 2457, in that case the function gives frequency = 20.049988 which is OK (given the accuracy of a 32-bit float).
The correct value for "frequency" should of course be f1/MA, so my strong suggestion is to not use the gcd function at all, but simply use this formula.


So we could use the following as a bug fix:

frequency = systemClockFrequency * (2.0f / (1 << MOD_N1)) * (MOD_M1 + (float)MOD_M_FRAC1 / (1 << 16)) / (QUAD_CNT_MAX*(1 + MOD_PS1)*MA);


Notice that here I used the correct meaning of the MOD_N1 parameter, (according to the 9221 spec). (The bug that I reported 4 months ago is still in the SDK...)

With this bug fix we would get the following results:

@f1=40.1 MHz:   frequency=20.049988 (MHz)

@f1=40.2 MHz:    frequency=20.099991 (MHz)


Also I would very much like you to revert the change in the gcd function to the old version having integer arguments. Using a "floating point" version is asking for numerical trouble! Try for instance

float a = 2.3f;
float b = 2.3f * 0.333f;
float r = Voxel::gcd(a, b);

We would "hope" to see that r == 0.0023, however, due to the limited precision of the arguments we get as result: r == 0.00000012 (approximately).


Kind regards,

Age