function get_Gq(t, prev, next, el, vnum)

global G;
global q;
global alpha;
global alpha2;
global C_inv;
global var_noise;
global FIR_length;
global Nusers;
global Memory;
global states;
global Nchips;
global FIR_0;
global z;
global Nsyms;
global GG;
global qq;

% set up A
%
a = zeros( FIR_length, Nusers);

for u = 1:Nusers
  ui = (u-1)*Memory + [1:Memory];
  a(:,u) = [states(ui,next); states(ui(Memory),prev)];
end

a = a(:);

q = zeros( FIR_length*Nusers, Nchips);        

% set up G and q
%
if( t == 1)

  G = inv( a*(a'/var_noise) + (1+alpha2)*C_inv );

  for j = 1:Nchips
    h = FIR_0(:,:,j);
    q(:,j) = a*(z(j,t)/var_noise) + C_inv*(alpha*h(:));
  end

else % t > 1

  if( t < Nsyms)
     G = inv( a*(a'/var_noise) + C_inv + alpha2*(C_inv-C_inv*GG(:,:,el,prev)*C_inv) );
  else
     G = inv( a*(a'/var_noise) + C_inv - alpha2*C_inv*GG(:,:,el,prev)*C_inv );
  end

  for j = 1:Nchips
     q(:,j) = a*(z(j,t)/var_noise) + C_inv*(GG(:,:,el,prev)*(alpha*qq(:,j,el,prev)));
  end

end
