enhering

Untitled

Sep 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. void COM::ReadAndFuse(uint8_t nCapacityBit, uint8_t nValueSelectOption, uint8_t nSDSelectOption, uint8_t nSlot) {
  2.  
  3. int32_t nValue, nStdDev;
  4. bool bFirst = true;
  5.  
  6. if (m_anSlotListPerCapacity[nCapacityBit] & (1UL << nSlot)) {
  7.  
  8. nValue = m_cSPIProtocol.ReadLongViaSPI(nValueSelectOption, nSlot);
  9. nStdDev = m_cSPIProtocol.ReadLongViaSPI(nSDSelectOption, nSlot);
  10.  
  11. if (bFirst) {
  12. bFirst = false;
  13. m_anDataArray[nValueSelectOption] = nValue;
  14. m_anDataArray[nSDSelectOption] = nStdDev;
  15. }
  16. else {
  17. int32_t nFusedSigma;
  18. m_anDataArray[nValueSelectOption] = FuseValues(m_anDataArray[nValueSelectOption],
  19. m_anDataArray[nSDSelectOption],
  20. nValue,
  21. nStdDev,
  22. nFusedSigma);
  23. m_anDataArray[nSDSelectOption] = nFusedSigma;
  24. }
  25. }
  26. }
  27.  
  28. int32_t COM::FuseValues(int32_t nZ1, int32_t nSigma1, int32_t nZ2, int32_t nSigma2, int32_t &nFusedSigma) {
  29. int32_t nVariance1 = pow(nSigma1, 2);
  30. int32_t nVariance2 = pow(nSigma2, 2);
  31.  
  32. int32_t nSumVariances = nVariance1 + nVariance2;
  33.  
  34. int32_t nFusedVariance = (nVariance1 * nVariance2) / (nVariance1 + nVariance2);
  35.  
  36. nFusedSigma = isqrt(nFusedVariance);
  37.  
  38. return ((nVariance2 / nSumVariances) * nZ1 + (nVariance1 / nSumVariances) * nZ2);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment