-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathBEACON_SWEEP.py
214 lines (181 loc) · 8.73 KB
/
BEACON_SWEEP.py
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
#!/usr/bin/python3
"""
BEACON_SWEEP.py
Generate beacon and precode signal in order to create a beamsweep.
Beacon can ONLY be generated by base station boards (not clients).
This script deals only with the Transmitter side, that is, only
generates and transmits the beacons. A receiver scripts such as
SISO_RX.py can be used on the receiver (client), concurrently.
Usage example:
python3 BEACON_SWEEP.py --serials="xxxx","yyyy"
where "xxxx" and "yyyy" are the serials of two Iris boards
on the base station
(NOTICE THERE'S NO SPACES BETWEEN SERIAL NUMBERS!)
NOTE ON GAINS:
Gain settings will vary depending on RF frontend board being used
If using CBRS:
rxgain: at 2.5GHz [3:1:105], at 3.6GHz [3:1:102]
txgain: at 2.5GHz [16:1:81], at 3.6GHz [15:1:81]
If using only Dev Board:
rxgain: at both frequency bands [0:1:30]
txgain: at both frequency bands [0:1:42]
---------------------------------------------------------------------
Copyright © 2018-2019. Rice University.
RENEW OPEN SOURCE LICENSE: http://renew-wireless.org/license
---------------------------------------------------------------------
"""
import sys
sys.path.append('../IrisUtils/')
import SoapySDR
from SoapySDR import * #SOAPY_SDR_ constants
from optparse import OptionParser
import numpy as np
import time
import os
import signal
import math
import pdb
import json
import scipy.io as sio
from functools import partial
from scipy.linalg import hadamard
from type_conv import *
from file_rdwr import *
from generate_sequence import *
sdrs = None
hub_dev = None
def beamsweeper(hub, serials, rate, freq, txgain, rxgain, numSamps, numSyms, prefix_length, postfix_length, calibrate, both_channels):
global sdrs, hub_dev
if hub != "": hub_dev = SoapySDR.Device(dict(serial=hub))
print("setting %s as eNB" % (serials))
sdrs = [SoapySDR.Device(dict(serial=serial1)) for serial1 in serials.split(',')]
#some default sample rates
for sdr in sdrs:
info = sdr.getHardwareInfo()
print("%s settings on device" % (info["frontend"]))
for ch in [0, 1]:
sdr.setBandwidth(SOAPY_SDR_RX, ch, 2.5*rate)
sdr.setBandwidth(SOAPY_SDR_TX, ch, 2.5*rate)
sdr.setSampleRate(SOAPY_SDR_TX, ch, rate)
sdr.setSampleRate(SOAPY_SDR_RX, ch, rate)
sdr.setFrequency(SOAPY_SDR_TX, ch, "BB", 0.75*rate)
sdr.setFrequency(SOAPY_SDR_RX, ch, "BB", 0.75*rate)
sdr.setFrequency(SOAPY_SDR_TX, ch, "RF", freq - 0.75*rate)
sdr.setFrequency(SOAPY_SDR_RX, ch, "RF", freq - 0.75*rate)
sdr.setAntenna(SOAPY_SDR_RX, ch, "TRX")
sdr.setDCOffsetMode(SOAPY_SDR_RX, ch, True)
if calibrate:
sdr.writeSetting(SOAPY_SDR_RX, ch, "CALIBRATE", 'SKLK')
sdr.writeSetting(SOAPY_SDR_TX, ch, "CALIBRATE", '')
if "CBRS" in info["frontend"]:
# Set gains to high val (initially)
sdr.setGain(SOAPY_SDR_TX, ch, txgain) # txgain: at 2.5GHz [16:1:93], at 3.6GHz [15:1:102]
sdr.setGain(SOAPY_SDR_RX, ch, rxgain) # rxgain: at 2.5GHz [3:1:105], at 3.6GHz [3:1:102]
else:
# No CBRS board gains, only changing LMS7 gains
sdr.setGain(SOAPY_SDR_TX, ch, "PAD", txgain) # [0:1:42]
sdr.setGain(SOAPY_SDR_TX, ch, "IAMP", 0) # [-12:1:3]
sdr.setGain(SOAPY_SDR_RX, ch, "LNA", rxgain) # [0:1:30]
sdr.setGain(SOAPY_SDR_RX, ch, "TIA", 0) # [0, 3, 9, 12]
sdr.setGain(SOAPY_SDR_RX, ch, "PGA", -10) # [-12:1:19]
if not both_channels:
sdr.writeSetting(SOAPY_SDR_RX, 1, 'ENABLE_CHANNEL', 'false')
sdr.writeSetting(SOAPY_SDR_TX, 1, 'ENABLE_CHANNEL', 'false')
sdr.writeSetting("RESET_DATA_LOGIC", "")
if hub == "":
sdrs[0].writeSetting("SYNC_DELAYS", "")
else:
hub_dev.writeSetting("SYNC_DELAYS", "")
#packet size
symSamp = numSamps + prefix_length + postfix_length
print("numSamps = %d" % symSamp)
# preambles to be sent from BS and correlated against in UE
upsample = 1
preambles_bs = generate_training_seq(preamble_type='gold_ifft', seq_length=128, cp=0, upsample=1)
preambles = preambles_bs[:,::upsample] #the correlators can run at lower rates, so we only need the downsampled signal.
beacon = preambles[0,:]*.25
possible_dim = []
nRadios = len(sdrs)
nChannels = 2 if both_channels else 1
numAnt = nRadios * nChannels
possible_dim.append(2**(np.ceil(np.log2(numAnt))))
h_dim = min(possible_dim)
hadamard_matrix = hadamard(h_dim) #hadamard matrix : http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.hadamard.html
beacon_weights = hadamard_matrix[0:numAnt, 0:numAnt]
print(beacon_weights)
beacon_weights = beacon_weights.astype(np.uint32)
bzeros = np.array([0]*numAnt, np.uint32)
bsched = "BG"#+''.join("G"*(numSyms-1))
print("Schedule %s " % bsched)
bconf = {"tdd_enabled": True,
"frame_mode":
"free_running",
"symbol_size" : symSamp,
"frames": [bsched],
"beacon_start" : prefix_length,
"beacon_stop" : prefix_length+len(beacon)}
for i, sdr in enumerate(sdrs):
sdr.writeSetting("TDD_CONFIG", json.dumps(bconf))
sdr.writeSetting("TX_SW_DELAY", str(30))
sdr.writeSetting("TDD_MODE", "true")
for i, sdr in enumerate(sdrs):
sdr.writeRegisters("BEACON_RAM", 0, cfloat2uint32(beacon, order='QI').tolist())
sdr.writeRegisters("BEACON_RAM_WGT_A", 0, beacon_weights[i*nChannels].tolist())
sdr.writeRegisters("BEACON_RAM_WGT_B", 0, beacon_weights[2*i+1].tolist() if both_channels else bzeros.tolist())
sdr.writeSetting("BEACON_START", str(numAnt))
signal.signal(signal.SIGINT, partial(signal_handler, rate, numSyms))
if hub == "":
sdrs[0].writeSetting("TRIGGER_GEN", "")
else:
hub_dev.writeSetting("TRIGGER_GEN", "")
signal.pause()
def signal_handler(rate, numSyms, signal, frame):
global sdrs, hub_dev
print("printing number of frames")
for sdr in sdrs:
print("NB 0x%X" % SoapySDR.timeNsToTicks(sdr.getHardwareTime(""), rate))
# ADC_rst, stops the tdd time counters
sdr.writeSetting("RESET_DATA_LOGIC", "")
conf = {"tdd_enabled" : False}
sdr.writeSetting("TDD_CONFIG", json.dumps(conf))
sdr.writeSetting("TDD_MODE", "false")
sdrs = None
hub_dev = None
sys.exit(0)
def main():
parser = OptionParser()
parser.add_option("--hub", type="string", dest="hub", help="serial number of the hub device", default="")
parser.add_option("--serials", type="string", dest="serials", help="serial numbers of the devices", default="RF3E000143,RF3E000160,RF3E000025,RF3E000034")
parser.add_option("--rate", type="float", dest="rate", help="Tx sample rate", default=5e6)
parser.add_option("--freq", type="float", dest="freq", help="Tx freq (Hz). POWDER users must set to 3.6e9", default=0)
parser.add_option("--txgain", type="float", dest="txgain", help="Optional Tx gain (dB)", default=80.0)
parser.add_option("--rxgain", type="float", dest="rxgain", help="Optional Rx gain (dB)", default=70.0)
parser.add_option("--numSamps", type="int", dest="numSamps", help="Num samples to receive", default=512)
parser.add_option("--prefix-length", type="int", dest="prefix_length", help="prefix padding length for beacon and pilot", default=82)
parser.add_option("--postfix-length", type="int", dest="postfix_length", help="postfix padding length for beacon and pilot", default=68)
parser.add_option("--numSyms", type="int", dest="numSyms", help="Number of symbols in one frame", default=20)
parser.add_option("--calibrate", action="store_true", dest="calibrate", help="transmit from both channels",default=False)
parser.add_option("--both-channels", action="store_true", dest="both_channels", help="transmit from both channels",default=False)
(options, args) = parser.parse_args()
if options.freq == 0:
print("[ERROR] Please provide RF Freq (Hz). POWDER users must set to 3.6e9. i.e. --freq=3.6e9")
exit(0)
if options.txgain > 81:
print("[ERROR] TX Gain must be between 0 and 81")
exit(0)
beamsweeper(
hub=options.hub,
serials=options.serials,
rate=options.rate,
freq=options.freq,
txgain=options.txgain,
rxgain=options.rxgain,
numSamps=options.numSamps,
numSyms=options.numSyms,
prefix_length=options.prefix_length,
postfix_length=options.postfix_length,
calibrate=options.calibrate,
both_channels=options.both_channels
)
if __name__ == '__main__':
main()