📄 xuclock.m
字号:
% xuclock.m
% Scope: This MATLAB program generates and saves the user clock bias and drift
% for a specified number of time steps and number of users (receivers), by
% using a simplified second order model [1]. WGS-84 constants are used.
% Usage: xuclock
% Inputs: - from keyboard the user should enter the following data:
% - maximum number of users (receivers), nru (default is 6)
% - number of time steps to be generated, nrsteps (default is 1800)
% - time step value, in seconds (default is 1 second)
% - white noise spectral density amplitude (Sb) for the first component
% corresponding to clock bias, in seconds
% - white noise spectral density amplitude (Sd) for the second component
% corresponding to clock drift, in second/second
% - random number seed value (default is 0)
% - selection of the storage data file
% - mat-files: ucbfile.mat and ucdfile.mat
% - selected name for two ASCII data files
% - none, no storage (default)
% - selection of user clock bias and drift plots from generated data
% - some application specific parameters are initialized by default (see Sb
% and Sd for a clock with crystal oscillator)
% Outputs: - output file storing the generated user clock bias and drift,
% mat-files ucbfile.mat and ucdfile.mat, or two selected ASCII data file;
% each output array has nrsteps rows and nru columns
% - plot of clock bias and drift versus time step
% External Matlab macros used: uclock, rms, wgs84con
% References: [1] Brown, Grover R., Hwang, P.Y.C., Introduction to random signals
% and applied Kalman filtering. Third Edition. John Wiley $ Sons,
% New York, 1997, pp. 428-431
% Last update: 01/17/01
% Copyright (C) 1999-01 by LL Consulting. All Rights Reserved.
clear
close all
yes = 'y';
disp(' ');
nru = input('Enter maximum number of users (receivers), nru (default is 6) -- > ');
if isempty(nru)
nru = 6;
end
disp(' ');
nrsteps = input('Enter number of steps to be generated, nrsteps (default is 1800) -- > ');
if isempty(nrsteps)
nrsteps = 1800;
end
ucerror = zeros(nrsteps,2);
disp(' ');
dt = input('Enter time step value, in seconds (default is 1 second) -- > ');
if isempty(dt)
dt = 1.;
end
disp(' ');
% Selection of clock moodel parameters
sb = 4.e-19; % in seconds , for a clock with crystal oscillator
sf = 1.5791e-18; % in second/second, for a clock with crystal oscillator
% Selection of random number seed
iseed = input('Enter random number seed value (default is 0.) -- > ');
if isempty(iseed)
iseed = 0.;
end
randn('seed',iseed);
disp(' ');
% Determine user clock bias and drift errors for all users
for kk = 1:nru
[cbias,cdrift] = uclock(nrsteps,sb,sf,dt);
ucbias(:,kk) = cbias;
ucdrift(:,kk) = cdrift;
end
% Store the multipath generated data into ucfile.mat or selected ASCII data file
disp('Specify where you want to save the generated data ');
disp(' Enter 1 for the file ucfile.mat');
disp(' Enter 2 for the ASCII data files to be selected');
disp(' Enter 3 for NOT saving');
answer1 = input('Enter your selection (default is 3) -- > ');
if isempty(answer1)
answer1 = 3;
end
if (answer1 == 1)
save ucbfile ucbias
save ucdfile ucdrift
elseif (answer1 == 2)
f2 = input('Enter the user clock bias ASCII data file (with extension) -- > ','s');
for k = 1:nrstep
for kk = 1:nru
fprintf(f2,'%14.7e %14.7e',ucbias(k,kk));
end
fprintf(f2,'\n');
end
f3 = input('Enter the user clock drift ASCII data file (with extension) -- > ','s');
for k = 1:nrstep
for kk = 1:nru
fprintf(f3,'%14.7e %14.7e',ucdrift(k,kk));
end
fprintf(f3,'\n');
end
else
fprintf('\nThe generated data is NOT saved\n');
end
% Execute user clock bias and drift plots
disp(' ');
answer2 = input('Execute user clock plots? (y/n)[y] ','s');
disp(' ');
if isempty(answer2)
answer2 = yes;
end
kfig = 1;
while strcmp(answer2,yes)
usel = input('Select the user (receiver) number (1 to nru) --> ');
xucbias = ucbias(:,usel);
xucdrift = ucdrift(:,usel);
x = 1:nrsteps;
xmean_b = mean(xucbias);
xstd_b = std(xucbias);
xrms_b = rms(xucbias);
temp1 = ['mean = ',num2str(xmean_b)];
temp2 = ['st.dev. = ',num2str(xstd_b)];
temp3 = ['rms = ',num2str(xrms_b)];
gb = [temp1,' ; ',temp2,' ; ',temp3];
xmean_d = mean(xucdrift);
xstd_d = std(xucdrift);
xrms_d = rms(xucdrift);
temp1 = ['mean = ',num2str(xmean_d)];
temp2 = ['st.dev. = ',num2str(xstd_d)];
temp3 = ['rms = ',num2str(xrms_d)];
gd = [temp1,' ; ',temp2,' ; ',temp3];
figure(kfig)
subplot(2,1,1)
plot(x,xucbias), grid
ylabel('User clock bias, in meters');
title(['User clock bias versus Time step, for user ' num2str(usel) ]);
disp('Select the mouse position to insert statistics for clock bias');
disp('Press a key to continue...');
pause
gtext(gb); % mouse placement of the text on a graph
disp(' ');
subplot(2,1,2)
plot(x,xucdrift), grid
xlabel(['Time step number (time step = ' num2str(dt) 'second(s))']);
ylabel('User clock drift, in meters/second');
title(['User clock drift versus Time step, for user ' num2str(usel) ]);
disp('Select the mouse position to insert statistics for clock drift');
disp('Press a key to continue...');
pause
gtext(gd); % mouse placement of the text on a graph
disp(' ');
answer2 = input('Do you want to execute another plot? (y/n)[n] --> ','s');
if isempty(answer2)
answer2 = 'n';
end
kfig = kfig + 1;
disp(' ');
end
disp('End of the program XUCLOCK ');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -