function [ output ] = motion_compensation(  act_mb, ref, u, v, m, n  )

MB_size = size( act_mb, 1 );
ind_y = (m-1)*MB_size + 1 + v : m*MB_size + v;
ind_x = (n-1)*MB_size + 1 + u : n*MB_size + u;
ind_x(ind_x<=0) = 1;     ind_x(ind_x>=size(ref,2)) = size(ref,2);
ind_y(ind_y<=0) = 1;     ind_y(ind_y>=size(ref,1)) = size(ref,1);

output = act_mb +...
            ref( ind_y ,   ind_x , : );

end

