summaryrefslogtreecommitdiff
path: root/openEMS/matlab/GetField_TD2FD.m
diff options
context:
space:
mode:
Diffstat (limited to 'openEMS/matlab/GetField_TD2FD.m')
-rw-r--r--openEMS/matlab/GetField_TD2FD.m48
1 files changed, 48 insertions, 0 deletions
diff --git a/openEMS/matlab/GetField_TD2FD.m b/openEMS/matlab/GetField_TD2FD.m
new file mode 100644
index 0000000..014c6d6
--- /dev/null
+++ b/openEMS/matlab/GetField_TD2FD.m
@@ -0,0 +1,48 @@
+function field = GetField_TD2FD(field, freq)
+% function field = GetField_TD2FD(field, freq)
+%
+% Transforms time-domain field data into the frequency domain
+% Autocorrects the half-timestep offset of the H-field
+%
+% example:
+% freq = linspace(0,1e9,100); %target frequency vector (Hz)
+% field = ReadHDF5FieldData('tmp/Ht.h5');
+% field_FD = GetField_TD2FD(field, freq);
+%
+% openEMS matlab interface
+% -----------------------
+% author: Thorsten Liebig
+%
+% See also ReadHDF5FieldData
+
+if (~isfield(field,'TD'))
+ warning('openEMS:GetField_TD2FD','field has no time domain data... skipping FD transformation...');
+ return
+end
+
+t = field.TD.time;
+dt = t(2)-t(1);
+
+clear field.FD
+
+field.FD.frequency = freq;
+
+for nf = 1:numel(freq)
+ field.FD.values{nf} = 0;
+end
+
+numTS = numel(field.TD.values);
+
+for n=1:numTS
+ for nf = 1:numel(freq)
+ f = freq(nf);
+ field.FD.values{nf} = field.FD.values{nf} + field.TD.values{n}.*exp(-1i*2*pi*f*t(n)) * 2 * dt;
+ % t(n) is absolute time and therefore the half-timestep offset of
+ % the H-field is automatically compensated
+ % openEMS output: E-fields start at t=0
+ % openEMS output: H-fields start at t=delta_t/2
+ end
+end
+
+field.FD.DataType=1;
+