The scaling is a little off when calculating the g-factor.
Line 84 is
W = ifftdim(W,3:5)*sqrt(Mx*My*Mz);
when it should be
W = ifftdim(W,3:5)*(Mx*My*Mz);
And Line 87 likewise needs the scale factor
data = shiftdim(ifftdim(data,2:4),-1)*(Mx*My*Mz);
Also, in line 96
g = reshape(sqrt(abs(W)./abs(p)), [Mx,My,Mz])/prod(R);
Should be normalized by the root of the reduction factor
g = reshape(sqrt(abs(W)./abs(p)), [Mx,My,Mz])/sqrt(prod(R));
The scaling is a little off when calculating the g-factor. Line 84 is
W = ifftdim(W,3:5)*sqrt(Mx*My*Mz);
when it should beW = ifftdim(W,3:5)*(Mx*My*Mz);
And Line 87 likewise needs the scale factor
data = shiftdim(ifftdim(data,2:4),-1)*(Mx*My*Mz);