⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xgmp1.m

📁 GPS TOOLBOX包含以下内容: 1、GPS相关常量和转换因子; 2、角度变换; 3、坐标系转换: &#61656 点变换; &#61656 矩阵变换; &#61656 向量变换
💻 M
字号:
%                                xgmp1.m
%  Scope:   This MATLAB program generates first order Gauss-Markov sequence, 
%           plots the generated sequence, histogram, and the normalized auto-
%           correlation sequence (optional). 
%  Usage:   xgmp1
%  Inputs:  - number of steps in the sequence to be generated (nstep)
%           - value of the time constant (1./beta), in seconds
%           - standard deviation of the Gauss-Markov process (sigx)
%           - time interval between samples (deltat), in seconds
%           - value of the initial seed, e.g. 0
%           - name of the output file (optional), if the generated data are 
%             saved
%  Outputs: - plot of the first order Gauss-Markov sequence
%           - histogram plot
%           - plot of the normalized auto-correlation sequence (optional)
%  Remark:  A default set of data for beta, sigx, and deltat is provided.
%  External Matlab macros used:  genrn, gmp1, rms, xcorr (from Signal 
%                                Processing Toolbox) - optional
%  Last update: 06/27/00
%  Copyright (C) 1996-00 by LL Consulting. All Rights Reserved.

clear
close all
yes = 'y';

%  Initialization - input data for first order Gauss-Markov process

disp('  ');
disp('Specify the number of steps in the sequence.');
nstep = input('Example: 256, 512, 1024, 2048, 4096;  Selection --> ');
disp('  ');
answer1 = input('Do you want to use the default data ? (y/n)[y] --> ','s');
if  isempty(answer1)
   answer1 = yes;
end 
if (strcmp(answer1,yes) == 1)
   beta = 1.0/300.0;     %  reciprocal time constant 
   sigx = 15.0;          %  standard deviation of the Gauss-Markov process
   deltat = 1.0;         %  time interval between samples
else
   betainv = input('Specify the value of time constant (1/beta) -->  ');
   sigx = input('Specify the value of sigx -->  ');
   deltat = input('Specify the value of deltat -->  ');
   beta = 1. / betainv;
end
disp('  ');
iseed = input('Specify the value of the initial seed, iseed, e.g. 0 --> ');
rand('seed',iseed);
disp('  ');

%  Generate the first order Gauss-Markov sequence

x = gmp1(nstep,beta,sigx,deltat);

%  Determine mean, standard deviation and root mean square (rms) for the 
%  generated random numbers

xmean = mean(x);
xstd = std(x);
xrms = rms(x);
temp1 = ['mean = ',num2str(xmean)];
temp2 = ['st.dev. = ',num2str(xstd)];
temp3 = ['rms = ',num2str(xrms)];
g = [temp1,' ;   ',temp2,' ;   ',temp3];

%  Plot the Gauss-Markov time sequence 

dd = num2str(nstep);
aa = 'First order Gauss-Markov process - with ';
aa = [aa dd ' time sequences'];
ee = 'First order Gauss-Markov sequence';
ff = ['Time sequence  (initial seed = ' num2str(iseed) ')'];
disp('Execute first order Gauss-Markov process graph ... ');
disp('Select the mouse position to insert text on the graph.');
disp('Press a key to continue...');
pause
figure(1)
plot(x),...
title(aa), ylabel(ee), xlabel(ff), grid,...
gtext(g);                   %  mouse placement of the text on a graph
disp('  ');
disp('Executed graph - check the window associated to this figure.');
disp('Press a key to continue...');
pause

%  Plot the histogram

aaa = 'Histogram for the First order Gauss-Markov process - with ';
aaa = [aaa dd ' time sequences'];
eee = ['Gauss-Markov number value  (initial seed = ' num2str(iseed) ')'];
fff = 'Number of Gauss-Markov numbers '; 
figure(2)
hist(x,33),...              %  number of bins is selected as 33
title(aaa), xlabel(eee), ylabel(fff), grid
disp('  ');
disp('Histogram graph - check the window associated to this figure.');
disp('Press a key to continue...');
pause
   
%  Plot the normalized auto-correlation sequence

disp('  ');
disp('For the auto-correlation sequence - the function XCORR from  ');
disp('Signal Processing Toolbox is required.');
answer2 = input('Plot the auto-correlation sequence? (y/n)[y] --> ','s');
if  isempty(answer2)
   answer2 = 'y';
end 
if strcmp(answer2,yes) == 1
   b = -(nstep-1):1:(nstep-1);
   a = xcorr(x','coeff');
   bb = 'Normalized auto-correlation sequence';
   cc = ['Sequence lag   (initial seed = ' num2str(iseed) ')'];
   figure(3)
   plot(b,a'),...
   title(aa), ylabel(bb), xlabel(cc), grid;
   disp('  ');
   disp('Auto-correlation graph - check the window associated to this figure.');
   disp('Press a key to continue...');
   pause
end

%  Save the generated data into a specified file if desired

disp('  ');
answer3 = input('Do you want to save the generated data ? (y/n)[y] ','s');
if  isempty(answer3)
   answer3 = yes;
end
if strcmp(answer3,yes) == 1
   disp('  ');
   f2 = input('Specify the output filename  -->  ','s');
   for  k = 1:nstep
      fprintf(f2,'%24.14e\n',x(k));
   end
end

disp('   ');
disp('End of the program XGMP1');
disp('  ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -