summaryrefslogtreecommitdiff
path: root/openEMS/matlab/GetField_TD2FD.m
blob: 014c6d60741795055df49515fac5a83ccc2f1cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;