-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathproc_tdoa_kiwi.m
90 lines (78 loc) · 3.16 KB
/
proc_tdoa_kiwi.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
## -*- octave -*-
## exitcode == 0 ... no errors
## exitcode == 1 ... error in 1st try-catch block and no error while saving status.json (status.json valid)
## exitcode == 2 ... no error in 1st try-catch block and error while saving status.json (status.json not valid)
## exitcode == 3 ... error in 1st try-catch block and error while saving status.json (status.json not valid)
function [tdoa,input]=proc_tdoa_kiwi(dir, files, config)
exitcode = 0;
status = struct;
try
status.version = tdoa_get_version();
for i=1:numel(files)
input(i).fn = files{i};
end
config.dir = dir;
config.plot_kiwi = true;
if isfield(config, 'lat_range')
config.plot_kiwi_json = true;
## determine map resolution and create config.lat and config.lon fields
config = tdoa_autoresolution(config);
end
if ~isfield(config, 'use_constraints')
config.use_constraints = false;
end
if ~isfield(config, 'new') ## by default use the original code
config.new = false;
end
if config.new
config.use_constraints = false;
end
[input,status.input] = tdoa_read_data(config, input, dir);
if strcmp(status.input.result.status, 'BAD')
error('ERROR: < 2 good stations found\n');
end
if config.new
[tdoa, status.cross_correlations] = tdoa_compute_lags_new(input);
else
[tdoa, status.cross_correlations] = tdoa_compute_lags(input, struct('dt', 12000, # 1-second cross-correlation intervals
'range', 0.020, # peak search range is +-20 ms
'dk', [-2:2], # use 5 points for peak fitting
'fn', @tdoa_peak_fn_pol2fit,# fit a pol2 to the peak
'remove_outliers', ~config.use_constraints
));
end
if config.use_constraints
[tdoa,status.cross_correlations] = tdoa_cluster_lags(config, tdoa, input, status.cross_correlations);
[tdoa,input,status.constraints] = tdoa_verify_lags (config, tdoa, input);
end
config.plotname = 'TDoA map';
config.title = sprintf('%g kHz %s', input(1).freq, input(1).time);
[tdoa,status.position] = tdoa_plot_map(input, tdoa, config);
if config.new
tdoa = tdoa_plot_dt_new(input, tdoa, config, 1e-2);
else
tdoa = tdoa_plot_dt (input, tdoa, config, 2.5e-3);
end
## save into a .mat file (except the raw IQ samples and times)
for i=1:numel(input)
input(i).t=[];
input(i).z=[];
end
save('-mat', sprintf('%s/tdoa_data.mat', config.dir))
catch err
json_save_cc(stderr, err);
status.octave_error = err;
exitcode = 1;
end_try_catch
try
fid = fopen(fullfile(dir, 'status.json'), 'w');
json_save_cc(fid, status);
fclose(fid);
catch err
json_save_cc(stderr, err);
exitcode += 2;
end_try_catch
if exitcode != 0
exit(exitcode);
end
endfunction