function m = grid2w(d,k,w,n) % function m = grid2w(d,k,w,n) % d -- k-space data % k -- k-trajectory, scaled -0.5 to 0.5 % w -- k-space weighting % n -- image size (m will be 2n X 2n) % % m -- gridded k-space data % % convert to single column d = d(:); k = k(:); w = w(:); % preweight dw = d.*w; % convert k-space samples to matrix indices nx = (n+1) + 2*n*real(k); ny = (n+1) + 2*n*imag(k); m = zeros(2*n,2*n); % loop over samples in kernel for lx = -2:2, for ly = -2:2, % find nearest samples nxt = round(nx+lx); nyt = round(ny+ly); % seperable triangular window kwx = max(1-0.5*abs(nx-nxt),0); kwy = max(1-0.5*abs(ny-nyt),0); % if data falls outtside matrix, put it at the edge nxt = max(nxt,1); nxt = min(nxt,2*n); nyt = max(nyt,1); nyt = min(nyt,2*n); % accumulate gridded data m = m+sparse(nxt,nyt,dw.*kwx.*kwy,2*n,2*n); end; end; % zero out data at edges m(:,1) = 0; m(:,2*n) = 0; m(1,:) = 0; m(2*n,:) = 0;