octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54264] Plot windows are not closable


From: anonymous
Subject: [Octave-bug-tracker] [bug #54264] Plot windows are not closable
Date: Tue, 10 Jul 2018 06:50:30 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0

Follow-up Comment #4, bug #54264 (project octave):

This is the scriptcausing problems. Afaik it was originally written for
Matlab. 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) address@hidden %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
% -----------------------------------------------------
% Simple Kalman filtering example:
% 1-dim. calculation of position from accelerometer 
% and GPS measurements. Total State Space.
% -----------------------------------------------------
N  = 1000;               % total number of acc measurements
dt = 0.1;                % time interval of acc measurement      
data = zeros(N,9);       % store results: time, pos, velo, acc
                                                                 % 
p11,p22,p33,p44
timestamp_gps = 10;      % how often does a gps measurement occur 
                         % relative to an accelerometer measurement
        
% -----------------------------------------------------
% Specifications related to the measurements
% -----------------------------------------------------
Var_AccNoise = 0.01;  % 10 mg standard deviation 
Var_GpsNoise = 100;   % 10 m standard deviation 
AccBias      = 0.1;   % 10 mg bias 

R_Acc = Var_AccNoise; % tell the Filter the correct
R_Gps = Var_GpsNoise; % measurement noise variances

% -----------------------------------------------------
% Generate a trajectory
% -----------------------------------------------------
disp('Generating ideal measurement data...')
real_acc = zeros(N,1);
real_velo = zeros(N,1);
real_pos = zeros(N,1);
for i=1:N;
   real_acc(i) = sin(4*pi*i/N);
   data(i,1) = (i-1)*dt;   
end;
for i = 2:N
   real_pos(i) = real_pos(i-1) + real_velo(i-1)*dt + 1/2*real_acc(i)*dt^2;
   real_velo(i) =                real_velo(i-1)    +     real_acc(i)*dt;
end;

% -----------------------------------------------------
% Initialization of the Kalman filter
% -----------------------------------------------------
X = [-50; -2; 0; 0];                         % Kalman state x,v,a,da
Phi = [1     dt 1/2*dt^2 0;     % State transition matrix 
       0     1     dt    0;
       0     0     1     0;
       0     0     0     1];
H_Gps = [1 0 0 0];                                % Gps measurement matrix
H_Acc = [0 0 1 1];              % Acc measurement matrix
P = [   1000    0               0               0;      % Covariance matrix of 
Kalman state
           0    100     0               0;
           0    0               1               0; 
                   0    0               0               0.1];
Q = [ 0.01     0     0     0;             % Covariance matrix of system noise 
        0     0.01     0     0;           % to take into account model 
imperfections
      0     0     0.01   0;        % 0.1 well tuned, 0.0001 badly tuned, 0
causes divergence
      0     0     0     0.01];
   
   
% -----------------------------------------------------
% Simulation:
% -----------------------------------------------------

disp('Simulation ...')
for k = 1:N             
   
   % -----------------------------------------------------
   % estimation
   % -----------------------------------------------------

   % Gps measurement available ?
   if (mod(k,timestamp_gps) == 0)       % Gps measurement if available
      Gps_measurement = real_pos(k,1) + sqrt(Var_GpsNoise) * randn(1);  
      
      K = P * H_Gps' * inv(H_Gps * P * H_Gps' + R_Gps);
           X = X - K * (H_Gps*X - Gps_measurement);
      P = P - K*H_Gps*P;
         
   end;
   
   % Acc measurement always available
   if (mod(k,1) == 0) 
           Acc_measurement = real_acc(k,1) + AccBias + sqrt(Var_AccNoise) *
randn(1);
        
           K  = P * H_Acc' * inv(H_Acc * P * H_Acc' + R_Acc);
      X = X - K * (H_Acc*X - Acc_measurement);
      P = P - K*H_Acc*P;
      
   end;  
   
   % ----------------------------------------------------   
   % prediction
   % ----------------------------------------------------   
   
   X = Phi * X;
   P = Phi * P * Phi' + Q;
   
   data(k,2:5) = X';  
   data(k,6) = P(1,1);data(k,7) = P(2,2);data(k,8) = P(3,3);data(k,9) =
P(4,4);

end;

% ----------------------------------------------------   
% plot the results
% ----------------------------------------------------   

newplot;
subplot(2,2,1)
plot(data(:,1),data(:,2),'r',data(:,1),real_pos(:,1),'b');
title 'pos (m) r=est, b=real'
xlabel('time (s)');
subplot(2,2,2)
plot(data(:,1),data(:,3),'r',data(:,1),real_velo(:,1),'b');
title 'velo (m/s) r=est, b=real'
xlabel('time (s)');
subplot(2,2,3)
plot(data(:,1),data(:,4),'r',data(:,1),real_acc(:,1),'b');
title 'acc (m/s^2) r=est, b=real'
xlabel('time (s)');
subplot(2,2,4)
plot(data(:,1),data(:,5),'r',data(:,1),ones(N,1)*AccBias,'b');
title 'acc bias (m/s^2) r=est, b=real'
xlabel('time (s)');

disp('Press a key...');
pause

newplot;
subplot(1,1,1)
plot(data(:,1),data(:,2)-real_pos(:,1),'r',data(:,1),zeros(N,1),'b',data(:,1),sqrt(data(:,6)),'g',data(:,1),-sqrt(data(:,6)),'g');
title 'position error (m)'
xlabel('time (s)');
disp('Press a key...');
pause
plot(data(:,1),data(:,3)-real_velo(:,1),'r',data(:,1),zeros(N,1),'b',data(:,1),sqrt(data(:,7)),'g',data(:,1),-sqrt(data(:,7)),'g');
title 'velocity error (m/s)'
xlabel('time (s)');
disp('Press a key...');
pause
plot(data(:,1),data(:,4)-real_acc(:,1),'r',data(:,1),zeros(N,1),'b',data(:,1),sqrt(data(:,8)),'g',data(:,1),-sqrt(data(:,8)),'g');
title 'acceleration error (m/s^2)'
xlabel('time (s)');
disp('Press a key...')
pause
plot(data(:,1),data(:,5)-ones(N,1)*AccBias,'r',data(:,1),zeros(N,1),'b',data(:,1),sqrt(data(:,9)),'g',data(:,1),-sqrt(data(:,9)),'g');
title 'accelerometer bias error (m/s^2)'
xlabel('time (s)')
disp('Press a key...');
pause


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54264>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]