Contents
RC oscilloscope data
vpp = 2.0;
t = time*1000; % convert to milliseconds
Find 90% crossings
v90 = vpp*0.9-vpp/2; n = length(vcap); fall = vcap(1:n-1)>=v90 & vcap(2:n)<=v90; rise = vcap(1:n-1)<=v90 & vcap(2:n)>=v90; ndx1 = find(rise|fall); tc1 = t(ndx1) + (t(ndx1+1)-t(ndx1))./(vcap(ndx1+1)-vcap(ndx1)).*(v90-vcap(ndx1));
find 10% crossings
v10 = vpp*0.1-vpp/2; fall = vcap(1:n-1)>=v10 & vcap(2:n)<=v10; rise = vcap(1:n-1)<=v10 & vcap(2:n)>=v10; ndx2 = find(rise|fall); tc2 = t(ndx2) + (t(ndx2+1)-t(ndx2))./(vcap(ndx2+1)-vcap(ndx2)).*(v10-vcap(ndx2));
show plot and cursors
m = min([length(ndx1),length(ndx2)]); plot(t,vcap); %grid on; xlabel('time (msec)'); ylabel('vcap (Volts)'); hold on x = [t(1) t(n)]; y = [-vpp vpp]/2; plot(x,[v90 v90],'k--'); plot(x,[v10 v10],'k--'); for k=1:m x = tc1(k); plot([x x],y,'k--'); x = tc2(k); plot([x x],y,'k--'); diff = (tc2(k)-tc1(k)); if (diff>0.0) fprintf('fall %.4g msec\n',diff); else fprintf('rise %.4g msec\n',-diff); end end hold off
fall 2.495 msec rise 2.343 msec
See how good the exponential decay is
ndx = [5:105]; ratio = (vcap(ndx)+1)/2; p = polyfit(t(ndx),log(ratio),1); plot(t(ndx),ratio); yfit = polyval(p,t(ndx)); hold on plot(t(ndx),exp(yfit),'k','LineWidth',2); set(gca,'YScale','log'); hold off tau = -1/p(1); fprintf('time constant = %g msec\n',tau); fprintf('predicted rise/fall time = 2.2*tc = %g msec\n',2.2*tau); xlabel('time (msec)'); ylabel('scaled response');
time constant = 1.16715 msec predicted rise/fall time = 2.2*tc = 2.56773 msec