Code covered by the BSD License  

Highlights from
Huygens-Fresnel integral approximation, free-form apertures and rough surfaces

image thumbnail

Huygens-Fresnel integral approximation, free-form apertures and rough surfaces

by

 

Simulate wave propagation through free-form apertures, or off rough surfaces.

interpolateGrid(obj, field, nGrid)
function [X, Y, Z, E] = interpolateGrid(obj, field, nGrid)
% interpolateSurface - interpolate grid or surface with new resolution
%
% nGrid ... interpolate surface anew at [N M] points
% field ... 'grid' or 'surface'

% extract interesting field
if strcmp(field, 'surface')
	data = obj.surface;
elseif strcmp(field, 'grid')
	data = obj.grid;
else
	error('unknown field name');
end

M = obj.nGrid(1);

% get surface/grid
X = reshape(data(1,:), M, []);
Y = reshape(data(2,:), M, []);
Z = reshape(data(3,:), M, []);
E = reshape(obj.E, M, []);

% interpolate surface anew
if ~isempty(nGrid)
	if isnumeric(nGrid) && numel(nGrid) == 2 && obj.nGrid(1) ~= nGrid(1) && obj.nGrid(2) ~= nGrid(2)
		% normalized indexing vectors/grids, original size
		x0 = 0 : 1/(obj.nGrid(1) - 1) : 1;
		y0 = 0 : 1/(obj.nGrid(2) - 1) : 1;
		[X0 Y0] = ndgrid(x0,y0);
		
		% normalized indexing vectors/grids, new size
		x1 = 0 : 1/(nGrid(1) - 1) : 1;
		y1 = 0 : 1/(nGrid(2) - 1) : 1;
		[X1 Y1] = ndgrid(x1,y1);
		
		% interpolating functions
		FX = griddedInterpolant(X0, Y0, X);
		FY = griddedInterpolant(X0, Y0, Y);
		FZ = griddedInterpolant(X0, Y0, Z);
		FE = griddedInterpolant(X0, Y0, E);
		
		% interpolated data
		X = FX(X1, Y1);
		Y = FY(X1, Y1);
		Z = FZ(X1, Y1);
		E = FE(X1, Y1);
	end
end

Contact us