필터 지우기
필터 지우기

Need help to translate Lat/long as signed 32bit integer to decimal degrees.

조회 수: 22 (최근 30일)
This one is for you math lovers.
I need to convert latitude and longitude given as:
"In WGS.84 in two’s complement. Range -90 <= latitude <= 90 deg. LSB = 180/230 degrees. = 1.6764 * 10-07 degrees."
I can't quite get my head around the order of operations I need to do to get this to decimal degrees. Clearly I need to deal with the two's compliment and figure out the sign and honestly, I'm not sure what "LSB=180/230" is trying to tell me.
Example from Wireshark, which has a built-in disector for the ASTERIX protocol.
  • Latitude packet: 0f3b3111 // Latitude disected value: 42.8377990610898
  • Longitude packet: e4d742fa // Longitude disected value: -76.3850651308894
Wireshark's values are correct. But I haven't found the right magic to translate the hex to decimal degrees in Matlab.
Any help would be much appreciated.
  댓글 수: 4
Roger Pierson
Roger Pierson 2020년 4월 13일
The line in bold comes from the interface specification for the protocol I'm dealing with (ASTERIX). It explans how the data is encoded.
I'm trying to figure out how to decode that and get human understandable coordinates out of it.
Adam Danz
Adam Danz 2020년 4월 13일
I'm not familiar with Asterix. If your question is how to interpret that, perhaps there's are some online resources or a forum for Asterix that would be helpful. If you can explain that line and what you need to do with it in Matlab, I'd be glad to help.

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 4월 13일
편집: James Tursa 2020년 4월 13일
The LSB is probably telling you that the value of the Least Significant Bit of the integer value is 1.6764e-07. Since MATLAB already uses 2's complement storage for its signed integer classes, all you have to do is some calls with cast( ) and typecast( ) to get the conversion. E.g., on WIN64 I get this result using your posted conversion factor:
>> double(typecast(uint32(hex2dec('0f3b3111')),'int32'))*1.6764e-07
ans =
42.838293927
>> double(typecast(uint32(hex2dec('e4d742fa')),'int32'))*1.6764e-07
ans =
-76.38594753768
Not exactly matching your numbers, but pretty close and probably all that can be expected given the number of significant digits of the conversion factor that I am using. If I had the full precision of the conversion factor I could probably get an exact match. Backing out the conversion factor from your examples I get an exact match:
>> double(typecast(uint32(hex2dec('0f3b3111')),'int32'))*1.6763806343078619e-07
ans =
42.8377990610898
>> double(typecast(uint32(hex2dec('e4d742fa')),'int32'))*1.6763806343078619e-07
ans =
-76.3850651308894
On your machine there might need to be a swapbytes( ) thrown in before the double( ) conversion.
I'm still not sure what that 180/230 means or how it is related to the conversion factor ...
  댓글 수: 3
Roger Pierson
Roger Pierson 2020년 4월 13일
Positively brilliant. It works in my application perfectly. Thank you!
Roger Pierson
Roger Pierson 2020년 4월 13일
For future readers: I ran this code on a MacBook and it ran fine without any changes.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam Danz
Adam Danz 2020년 4월 13일
편집: Adam Danz 2020년 4월 13일
  댓글 수: 1
Roger Pierson
Roger Pierson 2020년 4월 13일
Thanks, but I do not have the mapping toolbox.
Also, wouldn't i have to manipulate the raw values somehow to reverse the two's compliment?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by