function result = paper_code_bridge_idle_memory % Isolate idle forgetting from the active-reference level change. % Start with known remembered gain 2 and zero input. Retain/release output % power evidence separately. Hold lambda fixed. Eight updates = one second. here=fileparts(mfilename('fullpath')); main=fileparts(here); addpath(fullfile(main,'control_and_HS','OSI')) E0=load(fullfile(main,'saved_results','exp_tf','tf_sp1_7000_20260627_210411.mat')); Ed=load(fullfile(main,'saved_results','exp_tf','tf_sp1_5000_20260627_233333.mat')); dt=1/2048; pv=Ed.pid_values; C=pid(pv.P,pv.I,pv.D,1/pv.derivative_filter_N,dt,'IFormula','ForwardEuler','DFormula','ForwardEuler'); H0=ss(c2d(E0.H_dc_dm,dt,'zoh')); p=struct('fs',1/dt,'dt',0.125,'Tw',0.5,'band',[2 80],'eta_s',0.39, ... 'eta_A',4.54,'sigma_u',0.0575/4.54,'l_floor',1e-3,'eta_g',0.12,'r_g',0.73, ... 'g_th',1.75,'b_tar',0.4,'kappa',0.625,'lambda_min',0.2,'t_ref',1.5); methods={'Code',struct('code',true);'Paper',struct(); ... 'Previous rho recovery',struct('recovery','drive'); ... 'Reference + gate',struct('c_ref',true,'c_gate',true); ... 'Reference + gate + upward gain',struct('c_ref',true,'c_gate',true,'c_up',true); ... 'Reference + gate + activity',struct('c_ref',true,'c_gate',true,'c_activity',true)}; result=struct('description','Fraction of initial log-gain remaining after one second at zero excitation', ... 'methods',{methods},'referencePowers',[1e-10 1e10]); result.retained=zeros(size(methods,1),2); for j=1:size(methods,1) for cond=1:2 opt=methods{j,2}; ref=result.referencePowers(cond); if isfield(opt,'code') cfg=sol_osi('config',dt,C*H0,struct()); st=sol_osi('state',cfg); st.samples_in=cfg.segment_n; st.step_count=100; st.spectral_count=100; st.Suu(:)=1; st.Syy(:)=1; st.Syu(:)=0; st.q_ref(:)=ref; st.q_ref_count=3; st.log_rho(:)=log(2); else prm=p; for f=fieldnames(opt)',prm.(f{1})=opt.(f{1});end st=paper_osi('init',@(f)squeeze(freqresp(C*H0,2*pi*f)),prm); st.filled=st.N; st.n=100; st.puu=ones(size(st.f)); st.pyy=st.puu; st.pyu=zeros(size(st.f)); st.pyyq=st.pyy; st.pyy0=ref*st.pyy; st.lgs(:)=log(2); end rng(451,'twister'); for n=1:8 u=zeros(256,1); y=0.01*randn(256,1); if isfield(opt,'code') st.a_cmd=1; [~,st]=sol_osi(u,y,cfg,st); else st.lambda=1; [~,st]=paper_osi(u,y,st); end end if isfield(opt,'code'),z=st.log_rho;else,z=st.lgs;end result.retained(j,cond)=mean(z)/log(2); end end result.table=table(methods(:,1),100*result.retained(:,1),100*result.retained(:,2), ... 'VariableNames',{'Method','EvidenceStillHighPct','EvidenceBelowReferencePct'}); disp(result.table) save(fullfile(here,'paper_code_bridge_idle_memory.mat'),'result') end