2012-12-09 21:06:00 +00:00
|
|
|
function UI = ReadUI(files, path, freq, varargin)
|
|
|
|
% function UI = ReadUI(files, path, freq, varargin)
|
2010-04-24 14:43:22 +00:00
|
|
|
%
|
|
|
|
% read current and voltages from multiple files found in path
|
|
|
|
%
|
|
|
|
% returns voltages/currents in time and frequency-domain
|
2012-12-09 21:06:00 +00:00
|
|
|
%
|
2010-07-14 11:09:18 +00:00
|
|
|
% remarks on the frequency-domain:
|
|
|
|
% - all signals are assumed to start at t=0
|
|
|
|
% - currents that e.g. start at t = +delta_t/2 will be phase shifted by
|
|
|
|
% exp(-j*w*t(1))
|
|
|
|
%
|
2012-12-09 21:06:00 +00:00
|
|
|
% optional parameter:
|
|
|
|
% freq: frequency-domain values will be calculated according to 'freq'
|
|
|
|
% if 'freq' is not given, a (zero padded) FFT will be used
|
|
|
|
%
|
|
|
|
% optional key,value pairs:
|
|
|
|
% 'AR' : auto-regressive model to improve FD accuracy
|
|
|
|
% values: order to use within an AR model or 'auto'
|
2010-04-24 14:43:22 +00:00
|
|
|
%
|
2012-12-09 21:06:00 +00:00
|
|
|
% % examples:
|
2010-07-14 11:09:18 +00:00
|
|
|
% U = ReadUI({'ut1_1','ut1_2'},'tmp' );
|
|
|
|
% I = ReadUI('it1' ,'tmp',[0.5e9 1e9 1.5e9]);
|
2010-04-24 14:43:22 +00:00
|
|
|
%
|
2012-12-09 21:06:00 +00:00
|
|
|
% % using the auto-regressive model
|
|
|
|
% U = ReadUI('port_ut1' , 'tmp', 'AR', 'auto');
|
|
|
|
%
|
2010-04-24 14:43:22 +00:00
|
|
|
% openEMS matlab interface
|
|
|
|
% -----------------------
|
|
|
|
% author: Thorsten Liebig
|
2011-06-08 09:25:35 +00:00
|
|
|
%
|
|
|
|
% See also DFT_time2freq, AR_estimate
|
2010-03-29 20:12:01 +00:00
|
|
|
|
|
|
|
if (nargin<2)
|
|
|
|
path ='';
|
|
|
|
end
|
|
|
|
|
2012-12-09 21:06:00 +00:00
|
|
|
AR_order = 0;
|
2015-12-13 15:27:10 +00:00
|
|
|
SignalType = 'pulse';
|
2012-12-09 21:06:00 +00:00
|
|
|
|
|
|
|
for n=1:2:numel(varargin)
|
|
|
|
if (strcmp(varargin{n},'AR')==1)
|
|
|
|
AR_order = varargin{n+1};
|
2015-12-13 15:27:10 +00:00
|
|
|
elseif strcmpi(varargin{n},'SignalType')
|
|
|
|
SignalType = varargin{n+1};
|
2012-12-09 21:06:00 +00:00
|
|
|
else
|
|
|
|
warning('CSXCAD:ReadUI', ['"' varargin{n} '" is an unknown argument']);
|
|
|
|
end
|
2011-07-07 06:09:34 +00:00
|
|
|
end
|
|
|
|
|
2015-12-13 15:27:10 +00:00
|
|
|
if strcmpi(SignalType,'periodic') && AR_order>0
|
|
|
|
error 'auto-regressive model not compatible with periodic signals'
|
|
|
|
end
|
|
|
|
|
2010-03-29 20:12:01 +00:00
|
|
|
if (ischar(files))
|
|
|
|
filenames{1}=files;
|
|
|
|
else
|
|
|
|
filenames=files;
|
|
|
|
end
|
|
|
|
|
2010-04-17 19:56:16 +00:00
|
|
|
UI.TD = {};
|
|
|
|
UI.FD = {};
|
2010-03-29 20:12:01 +00:00
|
|
|
for n=1:numel(filenames)
|
2010-05-27 09:11:31 +00:00
|
|
|
tmp = load( fullfile(path,filenames{n}) );
|
2010-03-29 20:12:01 +00:00
|
|
|
t = tmp(:,1)';
|
|
|
|
val = tmp(:,2)';
|
2010-09-09 08:02:33 +00:00
|
|
|
|
2010-03-29 20:12:01 +00:00
|
|
|
UI.TD{n}.t = t;
|
|
|
|
UI.TD{n}.val = val;
|
2010-09-09 08:02:33 +00:00
|
|
|
|
|
|
|
if (numel(tmp(1,:))>2)
|
|
|
|
UI.TD{n}.additional = tmp(:,3:end)';
|
|
|
|
end
|
2010-03-29 20:12:01 +00:00
|
|
|
|
2010-12-16 09:33:06 +00:00
|
|
|
if (nargin<3) || isempty(freq)
|
2015-12-13 15:27:10 +00:00
|
|
|
if strcmpi(SignalType,'periodic')
|
|
|
|
warning 'ReadUI: periodic signal type not supported by FFT'
|
|
|
|
end
|
2010-07-14 11:09:18 +00:00
|
|
|
[UI.FD{n}.f,UI.FD{n}.val] = FFT_time2freq( t,val );
|
|
|
|
else
|
|
|
|
UI.FD{n}.f = freq;
|
2012-12-09 21:06:00 +00:00
|
|
|
if strcmpi(AR_order,'auto')
|
|
|
|
AR_order = 2;
|
|
|
|
EC = -1;
|
|
|
|
while 1
|
|
|
|
[val_ar t_ar UI.FD{n}.val EC] = AR_estimate( t, val, freq, AR_order);
|
|
|
|
if (EC==11)
|
|
|
|
AR_order = AR_order*2;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if (EC~=0)
|
|
|
|
warning('CSXCAD:ReadUI','AR estimation failed, skipping...')
|
2015-12-13 15:27:10 +00:00
|
|
|
UI.FD{n}.val = DFT_time2freq( t, val, freq, SignalType );
|
2012-12-09 21:06:00 +00:00
|
|
|
end
|
|
|
|
elseif (AR_order<=0)
|
2015-12-13 15:27:10 +00:00
|
|
|
UI.FD{n}.val = DFT_time2freq( t, val, freq, SignalType );
|
2011-06-08 09:25:35 +00:00
|
|
|
else
|
2012-12-09 21:06:00 +00:00
|
|
|
[val_ar t_ar UI.FD{n}.val EC] = AR_estimate( t, val, freq, AR_order);
|
|
|
|
if (EC~=0)
|
|
|
|
warning('CSXCAD:ReadUI','AR estimation failed, skipping...')
|
2015-12-13 15:27:10 +00:00
|
|
|
UI.FD{n}.val = DFT_time2freq( t, val, freq, SignalType );
|
2012-12-09 21:06:00 +00:00
|
|
|
end
|
2011-06-08 09:25:35 +00:00
|
|
|
end
|
|
|
|
end
|
2010-03-30 11:13:27 +00:00
|
|
|
end
|