openEMS/matlab/GetField_TD2FD.m

49 lines
1.2 KiB
Matlab
Raw Permalink Normal View History

function field = GetField_TD2FD(field, freq)
% function field = GetField_TD2FD(field, freq)
%
2010-07-15 09:46:36 +00:00
% Transforms time-domain field data into the frequency domain
2019-05-19 20:09:04 +00:00
% Auto-corrects the half-timestep offset of the H-field
%
% example:
2010-07-15 09:46:36 +00:00
% 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
2010-07-15 09:46:36 +00:00
%
% 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;
2010-07-15 09:46:36 +00:00
% 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;