function [t_k,xtruth,z] = sect_6_1_gen_xz(k_1, k_2, k_3u, mu_q, var_q, R, t_0, t_final, N) % % Generates the truth (xtruth) and measurements (z) for the specified nonlinear model. % % Inputs: % N = the number of measurements to process (xtruth has then one more sample corresponding to \hat{x](0)) % between the times t_0 and t_final. % % Written by: % -- % John L. Weatherwax 2005-08-14 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- t_k = linspace( t_0, t_final, N+1 ); % Generate the *true* state history xtruth = zeros(1,N+1); xtruth(1) = 0; % the initial condtion on the state for km1 = 1:N % integrate the nonlinear system from t_{k-1} to t_k: [t,x_t] = ode45( @(t,x) ( -k_1*x - k_2*(x^4) + k_3u + mu_q ), [t_k(km1), t_k(km1+1)], xtruth(km1) ); % add process noise to the state: deltaT = t_k(km1+1) - t_k(km1); q = (var_q/(2*(-k_1)))*(exp(2*(-k_1)*deltaT) - 1); % the process noise covariance w = sqrt(q) * randn(1); % accumulate the two terms: xtruth(km1+1) = x_t(end) + w; end % Generate the measurements (off of the true state): z = xtruth + sqrt(R)*randn(size(xtruth));