%%%current source calculations for 2nd order CT Sigma-Delta
%%%selects RZ DAC currents to cancel delay
%%%(alpha,beta) = (tau_d,tau_d+pulse_width)

clear all 
clc

pulsewidth = 0.5; %RZ DAC pulses that are Ts/2 wide
alpha = 0.08; %delay for DAC to be clocked
beta = alpha+pulsewidth;

y01 = beta-alpha;
y12 = 0.5*(beta*(2-beta)-alpha*(2-alpha));
y02 = 0.5*((beta^2)-(alpha^2));

exp1a = strcat('(k2a*',num2str(y12),'+k1a*',num2str(y01),') = -2');
exp2a = strcat('(k2a*',num2str(y02),'-k1a*',num2str(y01),') = 1');
[k1a,k2a]=solve(exp1a,exp2a)

I1 = 800e-6; %differential input current
C1 = 10e-12; %first integrator capacitor value
av1 = I1/C1; 
fs = 200e6; %Sigma-Delta sampling rate
gm2 = 157e-6; %Effective transconductance of second integrator
I2 = gm2/(fs/av1); %Second DAC current

I_DAC1 = k2a*I1
I_DAC2 = k1a*I2
