forked from JiaoXianjun/LTE-Cell-Scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearcher.h
316 lines (272 loc) · 7.62 KB
/
searcher.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright 2012 Evrytania LLC (http://www.evrytania.com)
//
// Written by James Peroulas <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Improved by Jiao Xianjun ([email protected]):
// 1. TD-LTE support
// 2. fast pre-search frequencies (external mixer/LNB support)
// 3. multiple tries at one frequency
// 4. .bin file recording and replaying
#ifndef HAVE_SEARCHER_H
#define HAVE_SEARCHER_H
#define FILTER_MCHN_SIMPLE_KERNEL
#ifdef USE_OPENCL
#include <CL/cl.h>
#define MAX_NUM_PLATFORM 8
#define MAX_NUM_DEVICE 8
// Class related to OpenCL
class lte_opencl_t {
public:
// Initializer
lte_opencl_t(
const uint & platform_id,
const uint & device_id
);
// de-Initializer
virtual ~lte_opencl_t();
uint platform_id;
uint device_id;
cl_uint num_platform;
cl_platform_id platforms[MAX_NUM_PLATFORM];
cl_uint num_device;
cl_device_id devices[MAX_NUM_DEVICE];
cl_context context;
cl_command_queue cmdQueue;
// setup OpenCL environment
int setup_opencl();
// for filter_my
size_t filter_my_length;
uint filter_my_workitem;
size_t filter_my_capbuf_length;
float *filter_my_in_host;
float *filter_my_out_host;
cl_mem filter_my_orig;
cl_mem filter_my_in;
cl_mem filter_my_mid;
cl_mem filter_my_out;
uint filter_my_buf_in_len;
uint filter_my_buf_mid_len;
uint filter_my_buf_out_len;
cl_kernel filter_my_skip2cols;
cl_kernel filter_my_multi_filter;
cl_kernel filter_my_result_combine;
int setup_filter_my(std::string filter_my_kernels_filename, const size_t & capbuf_length_in, const uint & filter_workitem_in);
int filter_my(itpp::cvec & capbuf);
// for xcorr_pss
size_t filter_mchn_length;
uint filter_mchn_workitem;
size_t filter_mchn_capbuf_length;
size_t filter_mchn_num_chn;
float *filter_mchn_coef_host;
float *filter_mchn_in_host;
float *filter_mchn_out_abs2_host;
cl_mem filter_mchn_coef;
cl_mem filter_mchn_orig;
cl_mem filter_mchn_in;
cl_mem filter_mchn_mid;
cl_mem filter_mchn_out;
cl_mem filter_mchn_out_abs2;
uint filter_mchn_buf_coef_len;
uint filter_mchn_buf_in_len;
uint filter_mchn_buf_mid_len;
uint filter_mchn_buf_out_len;
cl_kernel filter_mchn_skip2cols;
cl_kernel filter_mchn_multi_filter;
cl_kernel filter_mchn_result_combine;
int setup_filter_mchn(std::string filter_mchn_kernels_filename, const size_t & capbuf_length_in, const size_t & num_filter_in, const size_t & filter_length_in, const uint & xcorr_workitem_in);
int filter_mchn(const itpp::cvec & capbuf, const itpp::cmat & pss_fo_set, itpp::mat & corr_store);
private:
};
#else
class lte_opencl_t {
public:
// Initializer
lte_opencl_t(
const uint & platform_id,
const uint & device_id);
uint platform_id;
uint device_id;
};
#endif
void filter_my_fft(
//Inputs
const itpp::vec & coef,
//Inputs&Outputs
itpp::cvec & capbuf
);
// FIR 6RB filter
void filter_my(
//Inputs
const itpp::vec & coef,
//Outputs
itpp::cvec & capbuf
);
void pss_fo_set_gen_non_twist(
// Input
const itpp::vec & fo_search_set,
const double & fs_programmed,
const double & k_factor,
// Output
itpp::cmat & pss_fo_set
);
void pss_fo_set_gen_twist(
// Input
const itpp::vec & fo_search_set,
const double & fc_requested,
const double & fc_programmed,
const double & fs_programmed,
// Output
itpp::cmat & pss_fo_set
);
void pss_fo_set_gen(
// Input
const itpp::vec & fo_search_set,
// Output
itpp::cmat & pss_fo_set
);
void sampling_ppm_f_search_set_by_pss(
// Inputs
lte_opencl_t & lte_ocl,
const uint16 & num_loop,
const itpp::cvec & s,
const itpp::cmat & pss_fo_set,
const bool & sampling_carrier_twist,
const uint16 & max_reserve,
// Inputs&Outputs
itpp::vec & fo_search_set,
// Outpus
itpp::vec & ppm,
std::vector <itpp::mat> & xc,
double & xcorr_pss_time
);
void sampling_ppm_f_search_set_by_pss_old(
// Inputs
const itpp::cvec & capbuf,
const itpp::cmat & pss_fo_set,
const bool & sampling_carrier_twist,
// Inputs&Outputs
itpp::vec & f_search_set,
// Outpus
double & ppm,
vf3d & xc
);
// Correlate the captured data against the PSS.
void xcorr_pss(
// Inputs
const itpp::cvec & capbuf,
const itpp::vec & f_search_set,
const uint8 & ds_comb_arm,
const double & fc_requested,
const double & fc_programmed,
const double & fs_programmed,
const std::vector <itpp::mat> & xc,
// Outputs
itpp::mat & xc_incoherent_collapsed_pow,
itpp::imat & xc_incoherent_collapsed_frq,
// Only used for testing
std::vector <itpp::mat> & xc_incoherent_single,
std::vector <itpp::mat> & xc_incoherent,
itpp::vec & sp_incoherent,
itpp::vec & sp,
uint16 & n_comb_xc,
uint16 & n_comb_sp,
const bool & sampling_carrier_twist,
const double k_facotr
);
// Search the correlations for peaks.
void peak_search(
// Inputs
const itpp::mat & xc_incoherent_collapsed_pow,
const itpp::imat & xc_incoherent_collapsed_frq,
const itpp::vec & Z_th1,
const itpp::vec & f_search_set,
const double & fc_requested,
const double & fc_programmed,
const std::vector <itpp::mat> & xc_incoherent_single,
const uint8 & ds_comb_arm,
const bool & sampling_carrier_twist,
const double k_factor,
// Outputs
std::list <Cell> & cells
);
// For a certain detected PSS, attempt to find the SSS.
Cell sss_detect(
// Inputs
const Cell & cell,
const itpp::cvec & capbuf,
const double & thresh2_n_sigma,
const double & fc_requested,
const double & fc_programmed,
const double & fs_programmed,
// Only used for testing
itpp::vec & sss_h1_np_est,
itpp::vec & sss_h2_np_est,
itpp::cvec & sss_h1_nrm_est,
itpp::cvec & sss_h2_nrm_est,
itpp::cvec & sss_h1_ext_est,
itpp::cvec & sss_h2_ext_est,
itpp::mat & log_lik_nrm,
itpp::mat & log_lik_ext,
const bool & sampling_carrier_twist,
const int & tdd_flag
);
// Perform FOE based only on the PSS and SSS
Cell pss_sss_foe(
Cell & cell_in,
const itpp::cvec & capbuf,
const double & fc_requested,
const double & fc_programmed,
const double & fs_programmed,
const bool & sampling_carrier_twist,
const int & tdd_flag
);
// Extract the time and frequency grid.
void extract_tfg(
// Inputs
const Cell & cell,
const itpp::cvec & capbuf_raw,
const double & fc_requested,
const double & fc_programmed,
const double & fs_programmed,
// Outputs
itpp::cmat & tfg,
itpp::vec & tfg_timestamp,
const bool & sampling_carrier_twist
);
// Perform TOE/FOE/TOC/FOC on the time/ frequency grid.
Cell tfoec(
// Inputs
const Cell & cell,
const itpp::cmat & tfg,
const itpp::vec & tfg_timestamp,
const double & fc_requested,
const double & fc_programmed,
const RS_DL & rs_dl,
// Outputs
itpp::cmat & tfg_comp,
itpp::vec & tfg_comp_timestamp,
const bool & sampling_carrier_twist
);
// Attempt to decode the MIB.
Cell decode_mib(
const Cell & cell,
const itpp::cmat & tfg,
const RS_DL & rs_dl
);
// Small helper function that is used by LTE-Tracker
void del_oob(
itpp::ivec & v
);
#endif