-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFETDataRead.m
99 lines (82 loc) · 3.01 KB
/
FETDataRead.m
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function [data, filePath] = FETDataRead(filePath)
% FETDataRead reads data from a text file with FET characteristics
%
% The function reads the delimited data stored in the file and saves it
% in an output matrix. It also performs several checks to confirm that
% the file contains transfer characteristics in the linear and saturation
% regime.
%
% INPUT:
% path2File - full path to file with data, user is prompted to
% select a file if not given
%
% OUTPUT:
% data.type - string specifying type of data (transfer or output)
% data.x - vector containing x-axis data (gate or drain voltage)
% data.Is - matrix containing source current data
% data.Id - matrix containing drain current data
% data.Ig - matrix containing gate current data
% data.Vstep - vector containing the drain or gate voltage steps
% data.DataMatrix - matrix containing the raw data from file
% data.path - file path
% data.title - title (file name without extension)
%
% Sam Schott, 06.10.2017
%
global path
V_DRAIN_IDENTIFIERS = {'Vd', 'Drain voltage'};
V_GATE_IDENTIFIERS = {'Vg', 'Gate voltage'};
I_SOURCE_IDENTIFIERS = {'Is', 'source', 'Source current'};
I_DRAIN_IDENTIFIERS = {'Id', 'Isd', 'Drain current'};
I_GATE_IDENTIFIERS = {'Ig', 'Gate current'};
if nargin==0
[fileName, dirName] = uigetfile([path, '*.txt'], 'Select file');
filePath = fullfile(dirName, fileName);
% output empty matrix if no file is selected
if fileName == 0
data = [];
return;
end
path = dirName;
end
S = importdata(filePath);
% save raw data to output structure
data.DataMatrix = S.data;
% check if data is from output or transfer curve
if isinstring(S.colheaders{1}, V_DRAIN_IDENTIFIERS)
data.type = 'output';
elseif isinstring(S.colheaders{1}, V_GATE_IDENTIFIERS)
data.type = 'transfer';
else
error('Data has a unknown format. Please check if you have selected the right file.');
end
% save x-axis data to output structure
data.x = data.DataMatrix(:, 1);
% find colummns with source, drain and gate currents
check_source = isinstring(S.colheaders, I_SOURCE_IDENTIFIERS);
check_drain = isinstring(S.colheaders, I_DRAIN_IDENTIFIERS);
check_gate = isinstring(S.colheaders, I_GATE_IDENTIFIERS);
if sum(check_drain) == 0 || sum(check_gate) == 0
error('The data file is imcomplete. Please check the format of your data');
end
% extract data to ouput structure
data.Is = data.DataMatrix(:, check_source);
data.Id = data.DataMatrix(:, check_drain);
data.Ig = data.DataMatrix(:, check_gate);
% calculate source values if not provided
if isempty(data.Is)
data.Is = data.Id + data.Ig;
end
% determine stepped voltage values and save as vector
step_names = S.colheaders(check_drain);
data.Vstep = [];
nsteps = sum(check_drain);
for i = 1:nsteps
find = regexp(step_names{i}, '(\d+(\.\d+)*)', 'match');
data.Vstep(i) = str2double(find);
end
[~, name, ~] = fileparts(filePath);
data.path = filePath;
data.title = name;
end