function [M_2h] = downscale(M) % This function takes a staggered grid and creates a downscaled grid % ==================================================== % Boundaries are zero for all meshes but the first one % ==================================================== s = size(M); rows = s(1) ; cols = s(2); new_rows = (rows - 1)/2 + 1; new_cols = (cols - 1)/2 + 1; R = calc_error(M); M_2h = zeros([new_rows,new_cols]); %=========================================== % Transfer the F error (Full Weighting) mask_F = [.25 0 .25 ; 0 0 0; .25 0 .25]; tmp_residual_F = conv2(R,mask_F,'same'); for i=2:2: new_rows-1 for j=2:2: new_cols -1 M_2h(i,j) = tmp_residual_F(2*i-1,2*j-1); end end %============================================ % Transfer the G error (Full Weighting) mask_G = [ 1/16 0 1/8 0 1/16 0 0 0 0 0 1/8 0 1/4 0 1/8 0 0 0 0 0 1/16 0 1/8 0 1/16 ]; tmp_residual_G = conv2(R,mask_G,'same'); for i=3:2: new_rows-2 for j=3:2: new_cols -2 i1 = 1 + (i - 1)*2 ; j1 = 1 + (j-1)*2; M_2h(i,j) = tmp_residual_G(i1,j1); end end