From 8e8351d03842c7d95300026339ce753320d48a47 Mon Sep 17 00:00:00 2001 From: Stefan Mahr Date: Wed, 29 May 2013 14:05:46 +0200 Subject: [PATCH] matlab: add logarithmic option to VTK export --- matlab/DumpFF2VTK.m | 50 +++++++++++++++++++++---- matlab/Tutorials/CRLH_LeakyWaveAnt.m | 2 +- matlab/Tutorials/Conical_Horn_Antenna.m | 2 +- matlab/Tutorials/Helical_Antenna.m | 6 +-- matlab/Tutorials/Horn_Antenna.m | 2 +- matlab/Tutorials/Simple_Patch_Antenna.m | 2 +- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/matlab/DumpFF2VTK.m b/matlab/DumpFF2VTK.m index 3d1d9fe..db6a75a 100644 --- a/matlab/DumpFF2VTK.m +++ b/matlab/DumpFF2VTK.m @@ -1,10 +1,28 @@ -function DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale) -% DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale) +function DumpFF2VTK2(filename, farfield, thetaRange, phiRange, varargin) +% DumpFF2VTK(filename, farfield, thetaRange, phiRange, varargin) % % Dump 3D far field pattern to a vtk file % +% input: +% filename: filename of VTK file, existing file will be overwritten +% farfield: farfield in V/m +% thetaRange: theta range in deg +% phiRange: phi range in deg +% +% variable input: +% 'scale': - linear scale of plot, doesn't affect gain values +% 'logscale': - if set, show farfield with logarithmic scale +% - set the dB value for point of origin +% - values below will be clamped +% 'maxgain': - add max gain in dB to normalized farfield +% - only valid if logscale is set +% - default is 0dB +% % example: -% see examples/NF2FF/infDipol.m +% DumpFF2VTK(filename, farfield, thetaRange, phiRange, ... +% 'scale', 2, 'logscale', -20, 'maxgain', 3) +% +% see also examples/NF2FF/infDipol.m % % See also CreateNF2FFBox, AnalyzeNF2FF % @@ -13,8 +31,27 @@ function DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale) % author: Thorsten Liebig -if (nargin<5) - scale = 1; +% defaults +scale = 1; +maxgain = 0; +logscale = []; + +for n=1:2:numel(varargin) + if (strcmp(varargin{n},'maxgain')==1); + maxgain = varargin{n+1}; + elseif (strcmp(varargin{n},'logscale')==1); + logscale = varargin{n+1}; + elseif (strcmp(varargin{n},'scale')==1); + scale = varargin{n+1}; + end +end + +if ~isempty(logscale) + farfield = 20*log10(farfield) + maxgain; + ind = find(farfield<0); + farfield(ind)=0; +else + maxgain = 0; % force 0 for linear plot end t = thetaRange*pi/180; @@ -63,6 +100,5 @@ fprintf(fid,'POINT_DATA %d\n',numel(t)*numel(a)); fprintf(fid,['SCALARS gain double 1\nLOOKUP_TABLE default\n']); fclose(fid); -dumpField = farfield(:); +dumpField = farfield(:) + maxgain; save('-ascii','-append',filename,'dumpField') - diff --git a/matlab/Tutorials/CRLH_LeakyWaveAnt.m b/matlab/Tutorials/CRLH_LeakyWaveAnt.m index 438ef7b..3ca5b8a 100644 --- a/matlab/Tutorials/CRLH_LeakyWaveAnt.m +++ b/matlab/Tutorials/CRLH_LeakyWaveAnt.m @@ -164,6 +164,6 @@ drawnow disp( 'dumping 3D far field pattern to vtk, use Paraview to visualize...' ); for n=1:numel(f_rad) E_far_normalized_3D = nf2ff.E_norm{n} / max(max(nf2ff.E_norm{n})) * nf2ff.Dmax(n); - DumpFF2VTK( [Sim_Path '/FF_Pattern_' int2str(f_rad(n)/1e6) 'MHz.vtk'],E_far_normalized_3D,theta,phi,1e-3); + DumpFF2VTK( [Sim_Path '/FF_Pattern_' int2str(f_rad(n)/1e6) 'MHz.vtk'],E_far_normalized_3D,theta,phi,'scale',1e-3); end diff --git a/matlab/Tutorials/Conical_Horn_Antenna.m b/matlab/Tutorials/Conical_Horn_Antenna.m index 66311df..5eea145 100644 --- a/matlab/Tutorials/Conical_Horn_Antenna.m +++ b/matlab/Tutorials/Conical_Horn_Antenna.m @@ -194,4 +194,4 @@ ylabel( 'y' ); zlabel( 'z' ); %% -DumpFF2VTK([Sim_Path '/Conical_Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3); +DumpFF2VTK([Sim_Path '/Conical_Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3); diff --git a/matlab/Tutorials/Helical_Antenna.m b/matlab/Tutorials/Helical_Antenna.m index 1474081..71ebe1d 100644 --- a/matlab/Tutorials/Helical_Antenna.m +++ b/matlab/Tutorials/Helical_Antenna.m @@ -197,7 +197,7 @@ plot(thetaRange, 10*log10(directivity_CPLH(:,1)'),'r-.','LineWidth',2); legend('norm','CPRH','CPLH'); %% dump to vtk -DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],directivity,thetaRange,phiRange,1e-3); -DumpFF2VTK([Sim_Path '/3D_Pattern_CPRH.vtk'],directivity_CPRH,thetaRange,phiRange,1e-3); -DumpFF2VTK([Sim_Path '/3D_Pattern_CPLH.vtk'],directivity_CPLH,thetaRange,phiRange,1e-3); +DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],directivity,thetaRange,phiRange,'scale',1e-3); +DumpFF2VTK([Sim_Path '/3D_Pattern_CPRH.vtk'],directivity_CPRH,thetaRange,phiRange,'scale',1e-3); +DumpFF2VTK([Sim_Path '/3D_Pattern_CPLH.vtk'],directivity_CPLH,thetaRange,phiRange,'scale',1e-3); diff --git a/matlab/Tutorials/Horn_Antenna.m b/matlab/Tutorials/Horn_Antenna.m index 378d595..b2988a1 100644 --- a/matlab/Tutorials/Horn_Antenna.m +++ b/matlab/Tutorials/Horn_Antenna.m @@ -213,4 +213,4 @@ ylabel( 'y' ); zlabel( 'z' ); %% -DumpFF2VTK([Sim_Path '/Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3); +DumpFF2VTK([Sim_Path '/Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3); diff --git a/matlab/Tutorials/Simple_Patch_Antenna.m b/matlab/Tutorials/Simple_Patch_Antenna.m index 21a626d..3739fce 100644 --- a/matlab/Tutorials/Simple_Patch_Antenna.m +++ b/matlab/Tutorials/Simple_Patch_Antenna.m @@ -175,4 +175,4 @@ phiRange = (0:2:360) - 180; nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180,'Verbose',1,'Outfile','3D_Pattern.h5'); 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,1e-3); +DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);