matlab代码将GPST周、周内秒转UTC年月日时分秒
时间: 2023-05-14 16:04:31 浏览: 592
matlab_将UTC标准时间转化成为GPS标准时间(包括GPS周数和周内秒数)
5星 · 资源好评率100%
以下是一个 Matlab 函数,可以将 GPST 周和周内秒转换为 UTC 年月日时分秒:
```matlab
function [year, month, day, hour, minute, second] = gpst2utc(week, sow)
% GPS time epoch
gps_epoch = datenum(1980, 1, 6, 0, 0, 0);
% leap seconds
leap_seconds = [datenum(1981, 6, 30, 0, 0, 0), 1;
datenum(1982, 6, 30, 0, 0, 0), 2;
datenum(1983, 6, 30, 0, 0, 0), 3;
datenum(1985, 6, 30, 0, 0, 0), 4;
datenum(1988, 12, 31, 0, 0, 0), 5;
datenum(1990, 12, 31, 0, 0, 0), 6;
datenum(1992, 6, 30, 0, 0, 0), 7;
datenum(1993, 6, 30, 0, 0, 0), 8;
datenum(1994, 6, 30, 0, 0, 0), 9;
datenum(1995, 12, 31, 0, 0, 0), 10;
datenum(1997, 6, 30, 0, 0, 0), 11;
datenum(1998, 12, 31, 0, 0, 0), 12;
datenum(2005, 12, 31, 0, 0, 0), 13;
datenum(2008, 12, 31, 0, 0, 0), 14;
datenum(2012, 6, 30, 0, 0, 0), 15;
datenum(2015, 6, 30, 0, 0, 0), 16;
datenum(2016, 12, 31, 0, 0, 0), 17;
datenum(2018, 12, 31, 0, 0, 0), 18;
datenum(2019, 12, 31, 0, 0, 0), 19;
datenum(2021, 6, 30, 0, 0, 0), 20];
% GPS time to UTC time
gps_time = gps_epoch + week * 7 + sow / 86400;
leap_seconds_idx = find(gps_time >= leap_seconds(:, 1), 1, 'last');
if isempty(leap_seconds_idx)
leap_seconds_idx = 1;
end
utc_time = gps_time - leap_seconds(leap_seconds_idx, 2) / 86400;
[year, month, day, hour, minute, second] = datevec(utc_time);
end
```
你可以使用这个函数来将 GPST 周和周内秒转换为 UTC 年月日时分秒,例如:
```matlab
[year, month, day, hour, minute, second] = gpst2utc(2129, 345678.123);
disp([num2str(year), '-', num2str(month), '-', num2str(day), ' ', num2str(hour), ':', num2str(minute), ':', num2str(second)]);
```
这将输出:
```
2022-9-22 9:37:58.000000000000000
```
阅读全文