%Script to integrate charge depletion model %B. Kay 2/15/2016 et seq. %B. De Bari 12/2016 et seq. h_inc = 0.1; %integration step t0 = h_inc; tfinal = 100; tspan = t0:h_inc:tfinal; lts = length(tspan); %Set up noise, which is a force on the bead: noise_amp = 0.4; rng(1445834248); %Fixed seed for random number generator %rng('shuffle'); %New seed every time, based on system clock noise_func = noise_amp*randn(lts,1); % parameters for charge-distribution function & bead c1 = 1; %Conductance of bead c2 = 1; %Charge depletion denominator parameter sigma = 1.5; %Rate of charge saturation % cbase = 31; %baseline charge distribution over x q = -1; %charge carried by the bead b = 6; %damping parameter mu = 1; %dipole moment of bead nx = 1000; %Number of x (location) values xlimit_right = 10; xlimit_left = -10; incr = (xlimit_right-xlimit_left)/(nx-1); x = (xlimit_left:incr:xlimit_right); % magnet parameters global mp ton toff mon moff; mp = 0; %position of magnet in x-space ton = 0; %time magnet turns on toff = 400; %time magnet turns off mon = 0; %magnet strength when on moff = 0; %magnet strength when off mbase = 5; mmax_x = 1./(c2 + (x - mp).^2) + mbase; %magnet strength at each location in x. volt = (10:1:18); ampl = zeros(length(volt),2); ampl(:,1) = volt; volt_bif = zeros(1,3); for i = 1:length(volt) cbase = volt(i); cmax_x = 1./(0.5 + (x).^2) + cbase; %inverse-square steady-state charge distribution charge0 = cmax_x'; %Initial charge distribution indx = find(x>0,1,'first'); bead0 = [x(indx) 0 0]'; %Initial bead state (position, velocity, current) y0 = [charge0; bead0]; %Integrate: [t,y] = rk4(@charge_depletion_model,t0,tfinal,y0,h_inc,noise_func,x,c1,c2,sigma,cmax_x,b,mu, mmax_x, q); % envelope = abs(hilbert(y(:,nx+1))); % tmp_amp = mean(envelope); % tmp_amp = max(y(:,nx+1)); % ampl(i,2) = tmp_amp; tmp = horzcat(y(:,nx+1), t); v = zeros(1000,1); v(:,1) = volt(i); tmp = horzcat(tmp, v); volt_bif = vertcat(volt_bif, tmp); end plot(ampl(:,1),ampl(:,2)); % % current = [((diff(y(:,nx+3))).*h_inc)' 0]; %current through ground % pos = y(:,nx+1); %position of the bead % v = y(:,nx+2); %velocity of the bead % % tpos = tspan; % tcur = [0 (tspan(1:end-1) - h_inc/4)]; % % amp = max(abs(pos)); % % figure(1); % bead position and current through ground % clf; % % hold on; % % plot(tcur, (abs(current))) % % plot(tpos, (normalize(abs(pos(:,1))))); % % legend('Current (Normalized)','Bead Displacement (Normalized)') % % title('CDM Normalized Bead Displacement and Current') % plot(pos) % ylim([-10, 10]) % cdm_dat = [tpos', pos, tcur',current']; % % figure(2); % plot(current) %% Relative Phase of Position and Current pos_cdm = abs(current); %absolute value - more negative values for current = higher current cur_cdm = abs(pos); %position is now displacement from source pos_cdm = pos_cdm-mean(pos_cdm); %mean-centering time-series for Hilbert transform cur_cdm = cur_cdm-mean(cur_cdm); pos_cdm_wrapped = (angle(hilbert(pos_cdm))); cur_cdm_wrapped = (angle(hilbert(cur_cdm))); relphase_cdm = pos_cdm_wrapped - cur_cdm_wrapped; figure(4); clf; hold on; plot(relphase_cdm) title('CDM Wrapped Relative Phase Pos - Current'); xlabel('Time'); ylabel('Relative Phase (Radians)'); mean_relphase = mean(abs(relphase_cdm));