function [g tE] = fd(x)
% Compute horizontal and vertical finite differences on the 
% current estimate x and then compute the absolute of the 
% finite-difference-gradient
% 
% Use periodic boundaries

g = zeros([size(x) 2]);
g(:, :, 1) = imfilter(x, [-1 1], 'circular'); %% Horizontal finite difference
g(:, :, 2) = imfilter(x, [-1 1]', 'circular'); %% Vertical finite difference