%%% %%% Simulation of sampled data system %%% K = 0.01; %% try 0.05, 0.02, 0.01, 0.001 T = 1; %% Discrete time increments in seconds dt = 1/1000; %% ``continuous'' time increments in seconds NT = 30; %% Experiment duration in T periods N_TICS = round(T*NT/dt); %% Tot n. of tics in exper. alpha = exp(log(2)*dt);%% exponent of continous time system %% Set up the arrays and plots that are necessary for the simulation y = zeros(1,N_TICS); t_tics = [1:N_TICS]*dt; pt = zeros(1,NT); %% Array of pointers to data markers y(1)=0; figure(1); clf; title(['K=' num2str(K) ' T=' num2str(T)]); hold on; for TT = 1:NT, tti = (TT-1)*T/dt + [1:(1/dt)]; pt(TT) = plot(t_tics(tti),y(tti),'.w','MarkerSize',5); end; hold off; xs = zeros(1,NT); xs(3)=1; %% Sampled input ys = zeros(1,NT); TT=1; ys(TT)=0; %% Sampled output for tt=2:N_TICS, %% tt is is the `continuous' time tic e = xs(TT) - K*ys(TT); %% Error signal y(tt)=alpha*y(tt-1)+e; %% Output of continuous systems if mod((tt*dt),T)==0, %% If the time is equal to one of the discrete system's sampling times TT = (tt*dt)/T; %% sample number is it tti = (TT-1)*T/dt + [1:(1/dt)]; %% All the tics in the preceding period ys(TT) = y(tt); %% Sample the output set(pt(TT),'YData',y(tti),'Color','b'); pause(0.1); end; drawnow; end;