matlab: update tutorials and examples
parent
31ebb3f994
commit
6914d38985
|
@ -24,7 +24,7 @@ function DumpFF2VTK2(filename, farfield, thetaRange, phiRange, varargin)
|
|||
%
|
||||
% see also examples/NF2FF/infDipol.m
|
||||
%
|
||||
% See also CreateNF2FFBox, AnalyzeNF2FF
|
||||
% See also CreateNF2FFBox, CalcNF2FF
|
||||
%
|
||||
% openEMS matlab interface
|
||||
% -----------------------
|
||||
|
|
|
@ -179,19 +179,8 @@ thetaRange = sort( unique([ 0:1:50 50:2.:100 100:5:180 ]));
|
|||
disp( 'calculating 3D far field...' );
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f0, thetaRange*pi/180, phiRange*pi/180, 'Verbose',2,'Outfile','nf2ff_3D.h5');
|
||||
|
||||
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
|
||||
|
||||
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
|
||||
x = E_far_normalized .* sin(theta) .* cos(phi);
|
||||
y = E_far_normalized .* sin(theta) .* sin(phi);
|
||||
z = E_far_normalized .* cos(theta);
|
||||
figure
|
||||
surf( x,y,z, E_far_normalized, 'EdgeColor','none' );
|
||||
axis equal
|
||||
axis off
|
||||
xlabel( 'x' );
|
||||
ylabel( 'y' );
|
||||
zlabel( 'z' );
|
||||
plotFF3D(nf2ff); % plot liear 3D far field
|
||||
|
||||
%%
|
||||
DumpFF2VTK([Sim_Path '/Conical_Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);
|
||||
|
|
|
@ -198,19 +198,8 @@ thetaRange = sort( unique([ 0:1:50 50:2.:100 100:5:180 ]));
|
|||
disp( 'calculating 3D far field...' );
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f0, thetaRange*pi/180, phiRange*pi/180, 'Verbose',2,'Outfile','nf2ff_3D.h5');
|
||||
|
||||
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
|
||||
|
||||
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
|
||||
x = E_far_normalized .* sin(theta) .* cos(phi);
|
||||
y = E_far_normalized .* sin(theta) .* sin(phi);
|
||||
z = E_far_normalized .* cos(theta);
|
||||
figure
|
||||
surf( x,y,z, E_far_normalized, 'EdgeColor','none' );
|
||||
axis equal
|
||||
axis off
|
||||
xlabel( 'x' );
|
||||
ylabel( 'y' );
|
||||
zlabel( 'z' );
|
||||
plotFF3D(nf2ff);
|
||||
|
||||
%%
|
||||
DumpFF2VTK([Sim_Path '/Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);
|
||||
|
|
|
@ -41,7 +41,7 @@ SimBox = [200 200 150];
|
|||
%% setup FDTD parameter & excitation function
|
||||
f0 = 2e9; % center frequency
|
||||
fc = 1e9; % 20 dB corner frequency
|
||||
FDTD = InitFDTD( 30000 );
|
||||
FDTD = InitFDTD( 'NrTs', 30000 );
|
||||
FDTD = SetGaussExcite( FDTD, f0, fc );
|
||||
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
|
||||
FDTD = SetBoundaryCond( FDTD, BC );
|
||||
|
@ -154,25 +154,21 @@ disp( ['directivity: Dmax = ' num2str(nf2ff.Dmax) ' (' num2str(10*log10(nf2ff.Dm
|
|||
disp( ['efficiency: nu_rad = ' num2str(100*nf2ff.Prad./real(P_in(f_res_ind))) ' %']);
|
||||
|
||||
% normalized directivity
|
||||
D_log = 20*log10(nf2ff.E_norm{1}/max(max(nf2ff.E_norm{1})));
|
||||
% directivity
|
||||
D_log = D_log + 10*log10(nf2ff.Dmax);
|
||||
|
||||
%% display polar plot
|
||||
figure
|
||||
plot( nf2ff.theta, D_log(:,1) ,'k-' );
|
||||
xlabel( 'theta (deg)' );
|
||||
ylabel( 'directivity (dBi)');
|
||||
grid on;
|
||||
hold on;
|
||||
plot( nf2ff.theta, D_log(:,2) ,'r-' );
|
||||
legend('phi=0','phi=90')
|
||||
plotFFdB(nf2ff,'xaxis','theta','param',[1 2])
|
||||
% D_log = 20*log10(nf2ff.E_norm{1}/max(max(nf2ff.E_norm{1})));
|
||||
% D_log = D_log + 10*log10(nf2ff.Dmax);
|
||||
% plot( nf2ff.theta, D_log(:,1) ,'k-' );
|
||||
|
||||
|
||||
%%
|
||||
disp( 'calculating 3D far field pattern and dumping to vtk (use Paraview to visualize)...' );
|
||||
thetaRange = (0:2:180);
|
||||
phiRange = (0:2:360) - 180;
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180,'Verbose',1,'Outfile','3D_Pattern.h5');
|
||||
figure
|
||||
plotFF3D(nf2ff);
|
||||
|
||||
|
||||
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
|
||||
DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);
|
||||
|
|
|
@ -59,7 +59,7 @@ max_timesteps = 30000;
|
|||
min_decrement = 1e-5; % equivalent to -50 dB
|
||||
f0 = 0e9; % center frequency
|
||||
fc = 3e9; % 20 dB corner frequency (in this case 0 Hz - 3e9 Hz)
|
||||
FDTD = InitFDTD( max_timesteps, min_decrement );
|
||||
FDTD = InitFDTD( 'NrTS', max_timesteps, 'EndCriteria', min_decrement );
|
||||
FDTD = SetGaussExcite( FDTD, f0, fc );
|
||||
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
|
||||
if (use_pml>0)
|
||||
|
@ -106,7 +106,7 @@ CSX = AddBox(CSX,'gnd',10,start,stop);
|
|||
%% apply the excitation & resist as a current source
|
||||
start = [feed.pos-.1 -feed.width/2 0];
|
||||
stop = [feed.pos+.1 +feed.width/2 substrate.thickness];
|
||||
[CSX] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 0 1], 'excite');
|
||||
[CSX] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 0 1], true);
|
||||
|
||||
%% dump magnetic field over the patch antenna
|
||||
CSX = AddDump( CSX, 'Ht_', 'DumpType', 1, 'DumpMode', 2); % cell interpolated
|
||||
|
@ -184,69 +184,33 @@ f_res = freq(f_res_ind);
|
|||
|
||||
% calculate the far field at phi=0 degrees and at phi=90 degrees
|
||||
thetaRange = (0:2:359) - 180;
|
||||
r = 1; % evaluate fields at radius r
|
||||
phiRange = [0 90];
|
||||
disp( 'calculating far field at phi=[0 90] deg...' );
|
||||
[E_far_theta,E_far_phi,Prad,Dmax] = AnalyzeNF2FF( Sim_Path, nf2ff, f_res, thetaRange, [0 90], r );
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180);
|
||||
|
||||
Dlog=10*log10(Dmax);
|
||||
Dlog=10*log10(nf2ff.Dmax);
|
||||
|
||||
% display power and directivity
|
||||
disp( ['radiated power: Prad = ' num2str(Prad) ' Watt']);
|
||||
disp( ['radiated power: Prad = ' num2str(nf2ff.Prad) ' Watt']);
|
||||
disp( ['directivity: Dmax = ' num2str(Dlog) ' dBi'] );
|
||||
disp( ['efficiency: nu_rad = ' num2str(100*Prad./real(P_in(f_res_ind))) ' %']);
|
||||
disp( ['efficiency: nu_rad = ' num2str(100*nf2ff.Prad./real(P_in(f_res_ind))) ' %']);
|
||||
|
||||
% calculate the e-field magnitude for phi = 0 deg
|
||||
E_phi0_far = zeros(1,numel(thetaRange));
|
||||
for n=1:numel(thetaRange)
|
||||
E_phi0_far(n) = norm( [E_far_theta(n,1) E_far_phi(n,1)] );
|
||||
end
|
||||
|
||||
E_phi0_far_log = 20*log10(abs(E_phi0_far)/max(abs(E_phi0_far)));
|
||||
E_phi0_far_log = E_phi0_far_log + Dlog;
|
||||
|
||||
% display polar plot
|
||||
% display phi
|
||||
figure
|
||||
plot( thetaRange, E_phi0_far_log ,'k-' );
|
||||
xlabel( 'theta (deg)' );
|
||||
ylabel( 'directivity (dBi)');
|
||||
grid on;
|
||||
hold on;
|
||||
|
||||
% calculate the e-field magnitude for phi = 90 deg
|
||||
E_phi90_far = zeros(1,numel(thetaRange));
|
||||
for n=1:numel(thetaRange)
|
||||
E_phi90_far(n) = norm([E_far_theta(n,2) E_far_phi(n,2)]);
|
||||
end
|
||||
|
||||
E_phi90_far_log = 20*log10(abs(E_phi90_far)/max(abs(E_phi90_far)));
|
||||
E_phi90_far_log = E_phi90_far_log + Dlog;
|
||||
|
||||
% display polar plot
|
||||
plot( thetaRange, E_phi90_far_log ,'r-' );
|
||||
legend('phi=0','phi=90')
|
||||
plotFFdB(nf2ff,'xaxis','theta','param',[1 2]);
|
||||
drawnow
|
||||
|
||||
if (draw_3d_pattern==0)
|
||||
return
|
||||
end
|
||||
%% calculate 3D pattern
|
||||
phiRange = 0:15:360;
|
||||
thetaRange = 0:10:180;
|
||||
r = 1; % evaluate fields at radius r
|
||||
disp( 'calculating 3D far field...' );
|
||||
[E_far_theta,E_far_phi] = AnalyzeNF2FF( Sim_Path, nf2ff, f_res, thetaRange, phiRange, r );
|
||||
E_far = sqrt( abs(E_far_theta).^2 + abs(E_far_phi).^2 );
|
||||
E_far_normalized = E_far / max(E_far(:)) * Dmax;
|
||||
|
||||
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
|
||||
x = E_far_normalized .* sin(theta) .* cos(phi);
|
||||
y = E_far_normalized .* sin(theta) .* sin(phi);
|
||||
z = E_far_normalized .* cos(theta);
|
||||
%% calculate 3D pattern
|
||||
phiRange = 0:2:360;
|
||||
thetaRange = 0:2:180;
|
||||
disp( 'calculating 3D far field...' );
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180, 'Verbose',2,'Outfile','nf2ff_3D.h5');
|
||||
figure
|
||||
surf( x,y,z, E_far_normalized );
|
||||
axis equal
|
||||
xlabel( 'x' );
|
||||
ylabel( 'y' );
|
||||
zlabel( 'z' );
|
||||
plotFF3D(nf2ff);
|
||||
|
||||
|
||||
%% visualize magnetic fields
|
||||
|
|
|
@ -65,7 +65,7 @@ max_timesteps = 30000;
|
|||
min_decrement = 1e-5; % equivalent to -50 dB
|
||||
f0 = 0e9; % center frequency
|
||||
fc = 3e9; % 10 dB corner frequency (in this case 0 Hz - 3e9 Hz)
|
||||
FDTD = InitFDTD( max_timesteps, min_decrement );
|
||||
FDTD = InitFDTD( 'NrTS', max_timesteps, 'EndCriteria', min_decrement );
|
||||
FDTD = SetGaussExcite( FDTD, f0, fc );
|
||||
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
|
||||
if (use_pml>0)
|
||||
|
@ -133,7 +133,7 @@ for xn=1:array.xn
|
|||
% apply the excitation & resist as a current source
|
||||
start = [midX+feed.pos-feed.width/2 midY-feed.width/2 0];
|
||||
stop = [midX+feed.pos+feed.width/2 midY+feed.width/2 substrate.thickness];
|
||||
[CSX] = AddLumpedPort(CSX, 5, number,feed.R, start, stop,[0 0 1],['excite_' int2str(xn) '_' int2str(yn)]);
|
||||
[CSX] = AddLumpedPort(CSX, 5, number,feed.R, start, stop,[0 0 1],true);
|
||||
number=number+1;
|
||||
end
|
||||
end
|
||||
|
@ -221,74 +221,35 @@ f_res = freq(f_res_ind);
|
|||
|
||||
% calculate the far field at phi=0 degrees and at phi=90 degrees
|
||||
thetaRange = (0:2:359) - 180;
|
||||
phiRange = [0 90];
|
||||
r = 1; % evaluate fields at radius r
|
||||
disp( 'calculating far field at phi=[0 90] deg...' );
|
||||
[E_far_theta,E_far_phi,Prad,Dmax] = AnalyzeNF2FF( Sim_Path, nf2ff, f_res, thetaRange, [0 90], r );
|
||||
|
||||
Dlog=10*log10(Dmax);
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180);
|
||||
|
||||
Dlog=10*log10(nf2ff.Dmax);
|
||||
|
||||
% display power and directivity
|
||||
disp( ['radiated power: Prad = ' num2str(Prad) ' Watt']);
|
||||
disp( ['radiated power: Prad = ' num2str(nf2ff.Prad) ' Watt']);
|
||||
disp( ['directivity: Dmax = ' num2str(Dlog) ' dBi'] );
|
||||
disp( ['efficiency: nu_rad = ' num2str(100*Prad./real(P_in(f_res_ind))) ' %']);
|
||||
disp( ['efficiency: nu_rad = ' num2str(100*nf2ff.Prad./real(P_in(f_res_ind))) ' %']);
|
||||
|
||||
% calculate the e-field magnitude for phi = 0 deg
|
||||
E_phi0_far = zeros(1,numel(thetaRange));
|
||||
for n=1:numel(thetaRange)
|
||||
E_phi0_far(n) = norm( [E_far_theta(n,1) E_far_phi(n,1)] );
|
||||
end
|
||||
|
||||
E_phi0_far_log = 20*log10(abs(E_phi0_far)/max(abs(E_phi0_far)));
|
||||
E_phi0_far_log = E_phi0_far_log + Dlog;
|
||||
|
||||
% display radiation pattern
|
||||
% display phi
|
||||
figure
|
||||
plot( thetaRange, E_phi0_far_log ,'k-' );
|
||||
xlabel( 'theta (deg)' );
|
||||
ylabel( 'directivity (dBi)');
|
||||
grid on;
|
||||
hold on;
|
||||
|
||||
% calculate the e-field magnitude for phi = 90 deg
|
||||
E_phi90_far = zeros(1,numel(thetaRange));
|
||||
for n=1:numel(thetaRange)
|
||||
E_phi90_far(n) = norm([E_far_theta(n,2) E_far_phi(n,2)]);
|
||||
end
|
||||
|
||||
E_phi90_far_log = 20*log10(abs(E_phi90_far)/max(abs(E_phi90_far)));
|
||||
E_phi90_far_log = E_phi90_far_log + Dlog;
|
||||
|
||||
plot( thetaRange, E_phi90_far_log ,'r-' );
|
||||
legend('phi=0','phi=90')
|
||||
|
||||
plotFFdB(nf2ff,'xaxis','theta','param',[1 2]);
|
||||
drawnow
|
||||
|
||||
if (draw_3d_pattern==0)
|
||||
return
|
||||
end
|
||||
|
||||
%% calculate 3D pattern
|
||||
tic
|
||||
phiRange = 0:3:360;
|
||||
thetaRange = unique([0:0.5:15 10:3:180]);
|
||||
r = 1; % evaluate fields at radius r
|
||||
disp( 'calculating 3D far field...' );
|
||||
[E_far_theta,E_far_phi] = AnalyzeNF2FF( Sim_Path, nf2ff, f_res, thetaRange, phiRange, r );
|
||||
E_far = sqrt( abs(E_far_theta).^2 + abs(E_far_phi).^2 );
|
||||
|
||||
E_far_normalized = E_far / max(E_far(:)) * Dmax;
|
||||
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
|
||||
x = E_far_normalized .* sin(theta) .* cos(phi);
|
||||
y = E_far_normalized .* sin(theta) .* sin(phi);
|
||||
z = E_far_normalized .* cos(theta);
|
||||
|
||||
%%
|
||||
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180, 'Verbose',2,'Outfile','nf2ff_3D.h5');
|
||||
figure
|
||||
surf( x,y,z, E_far_normalized );
|
||||
axis equal
|
||||
xlabel( 'x' );
|
||||
ylabel( 'y' );
|
||||
zlabel( 'z' );
|
||||
toc
|
||||
plotFF3D(nf2ff);
|
||||
|
||||
%% visualize magnetic fields
|
||||
% you will find vtk dump files in the simulation folder (tmp/)
|
||||
|
|
|
@ -111,7 +111,6 @@ legend( 'e-field magnitude', 'Location', 'BestOutside' );
|
|||
%% calculate the far field at theta=90 degrees
|
||||
phiRange = 0:2:359;
|
||||
disp( 'calculating far field at theta=90 deg..' );
|
||||
%[E_far_theta,E_far_phi] = AnalyzeNF2FF( Sim_Path, nf2ff, f_max, 90, phiRange, 1 );
|
||||
nf2ff = CalcNF2FF( nf2ff, Sim_Path, f_max, 90, phiRange/180*pi, 'Mode', 1 );
|
||||
Prad = nf2ff.Prad;
|
||||
Dmax = nf2ff.Dmax;
|
||||
|
@ -129,19 +128,8 @@ phiRange = 0:5:360;
|
|||
thetaRange = 0:5:180;
|
||||
disp( 'calculating 3D far field...' );
|
||||
nf2ff = CalcNF2FF( nf2ff, Sim_Path, f_max, thetaRange/180*pi, phiRange/180*pi, 'Mode', 1 );
|
||||
|
||||
E_far = nf2ff.E_norm{1};
|
||||
E_far_normalized = E_far / max(E_far(:));
|
||||
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
|
||||
x = E_far_normalized .* sin(theta) .* cos(phi);
|
||||
y = E_far_normalized .* sin(theta) .* sin(phi);
|
||||
z = E_far_normalized .* cos(theta);
|
||||
figure
|
||||
surf( x,y,z, E_far_normalized );
|
||||
axis equal
|
||||
xlabel( 'x' );
|
||||
ylabel( 'y' );
|
||||
zlabel( 'z' );
|
||||
plotFF3D(nf2ff)
|
||||
|
||||
%%
|
||||
DumpFF2VTK([Sim_Path '/FF_pattern.vtk'],E_far_normalized, thetaRange, phiRange);
|
||||
|
|
Loading…
Reference in New Issue