torchbox.antenna package
Submodules
torchbox.antenna.arrays module
- torchbox.antenna.arrays.arraysig(pos, ang, ns=1, ncov=0, scov=1, dim=-1, lambd=1, unit='deg', returns=['sig', 'cov'])
generates array signal
- Parameters:
pos (list, tuple or tensor) – array coordinates (N x 3) or (3 x N)
ns (int, optional) – _description_, by default 1
ncov (int, optional) – _description_, by default 0
scov (int, optional) – _description_, by default 1
dim (int, optional) – the dimensional index of coordinate in
posandang, by default -1.lambd (float, optional) – wave length, by default 1.
unit (str, optional) –
'deg'or'rad', by default'deg'returns (list, optional) – values to be returned,
'sig'(signal),'cov'(sample covariance),'covt'(theoretical covariance), by default['sig', 'cov']
- Returns:
array signal
- Return type:
tensor
Examples
import torch as th import torchbox as tb pos = tb.arraypos(th.arange(0, 64, 0.5), dim=0, axes='y') ang = [[-30, 10, 30], [0, 0, 0]] print(pos.shape) X, R = arraysig(pos, ang, ns=4, ncov=0, scov=1, dim=0, lambd=1, unit='deg', returns=['sig', 'cov']) print(X.shape, R.shape) pos = tb.arraypos(th.arange(0, 64, 0.5), dim=-1, axes='y') ang = [[-30, 0], [0, 0], [10, 0]] print(pos.shape) X, R = arraysig(pos, ang, ns=4, ncov=tb.db2pm(-30, 10), scov=1, dim=-1, lambd=1, unit='deg', returns=['sig', 'cov']) X, R = arraysig(pos, ang, ns=4, ncov=0, scov=tb.db2pm(30, 10), dim=-1, lambd=1, unit='deg', returns=['sig', 'cov']) Y = tb.fft(X, dim=-1, shift=True) print(X.shape, R.shape) plt = tb.plot([X.real, X.abs(), Y.abs()], grids=True, titles=['Real part', 'Amplitude', 'FFT of signal']); plt.show()
- torchbox.antenna.arrays.tr2mimo(tc, rc, dime=0, dimc=-1, tid=None, rid=None, omode='T×R', order='y<:z<', axes='y:z', otype='tensor')
calculate mimo array coordinates from transmiter and receiver array coordinates
- Parameters:
tc (list, tuple, ndarray or tensor) – coordinates of transmit array elements
rc (list, tuple, ndarray or tensor) – coordinates of receive array elements
dime (int) – dimension of the number of elements in
tc,rc,tid,riddimc (int, optional) – coordinate (x, y, z) dimension in
tc,rc, by default -1tid (str, list, tuple, tensor or None, optional) – ids of transmit array elements,
'a'or'auto'means using index as id, and all array share the same txids. If not None, should have the same shape astcwithout dimensiondimc, by default None, no txid return.rid (str, list, tuple, tensor or None, optional) – ids of receive array elements,
'a'or'auto'means using index as id, and all array share the same rxids. If not None, should have the same shape asrcwithout dimensiondimc, by default None, no rxid return.omode (str, optional) – output mode:
'T×R'(default),'R×T','TR','RT'order (str, optional) – mimo array elements’s order, e.g.
'z<:y<', seetorchbox.argsorts(), by default'y<:z<'axes (str, optional) – axis information,
'x:y','y:x:z'…, by default'y:z'otype (str, optional) – output type,
'list','array'or'tensor', by default'tensor'
Examples
import torchbox as tb order = 'z<:y<' tc = [[0, 0], [0, 1], [0, 2]] rc = [[0, 0], [1, 0], [2, 0], [3, 0]] mc, mtid, mrid = tb.tr2mimo(tc, rc, tid='a', rid='a', order=order, axes='y:z') print("MIMO", mc) print("mtid", mtid) print("mrid", mrid) plt = tb.scatterxyz([[tc, rc, mc]], sizes=None, markers=[['^', 's', 'o']], fcolors=[['none', 'none', 'none']], ecolors=[['r', 'b', 'g']], legends=[['Tx', 'Rx', 'Vx']], grids=True); plt.show() tc = [[3, 0], [4, 0.8], [5, 0], [7, 0]] rc = [[0, 0], [0.5, 0], [1, 0], [1.5, 0]] mc, mtid, mrid = tb.tr2mimo(tc, rc, tid='a', rid='a', order=order, axes='y:z') print("MIMO", mc) print("mtid", mtid) print("mrid", mrid) plt = tb.scatterxyz([[tc, rc, mc]], sizes=None, markers=[['^', 's', 'o']], fcolors=[['none', 'none', 'none']], ecolors=[['r', 'b', 'g']], legends=[['Tx', 'Rx', 'Vx']], grids=True); plt.show() tc = [[-19, 4], [-19, 18], [-3, 18], [13, 18]] rc = [[5, 7], [6, 7], [7, 7], [8, 7], [9, 7], [10, 7], [11, 7], [12, 7], [13, 7], [14, 7], [15, 9], [16, 11], [17, 13], [18, 1], [19, 3], [20, 5]] mc, mtid, mrid = tb.tr2mimo(tc, rc, tid='a', rid='a', order=order, axes='y:z') print("MIMO", mc) print("mtid", mtid) print("mrid", mrid) plt = tb.scatterxyz([[tc, rc, mc]], sizes=None, markers=[['^', 's', 'o']], fcolors=[['none', 'none', 'none']], ecolors=[['r', 'b', 'g']], legends=[['Tx', 'Rx', 'Vx']], grids=True); plt.show()
torchbox.antenna.pattern module
- torchbox.antenna.pattern.arrayfactor(pos, ang, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg', keepang=False)
- Parameters:
ang (list, tuple or tensor) – angle values in azimuth and elevation direction
dime (int, optional) – the dimensional index of array element in
pos, by default -2.dimc (int, optional) – the dimensional index of coordinate in
posandang, by default -1.w (list, tuple, tensor or None, optional) – specifies the steering weights of the sensor array (NxL). The default value of w is an all one column vector (Nx1).
lambd (float, optional) – wave length, by default 1.
unit (str, optional) –
'deg'or'rad', by default'deg'keepang (bool, optional) – keep ang’s shape, by default False
- Returns:
steering vector
- Return type:
tensor
Examples
import torch as th import torchbox as tb ang = [[10, 20, 30, -40], [0, 0, 0, 0]] pos = [[0, 0, 0, 0, 0, 0, 0], [0, 0.5, 1, 1.5, 2, 2.5, 3], [0, 0, 0, 0, 0, 0, 0]] ang = th.tensor(ang) pos = th.tensor(pos) ang = ang.T pos = pos.T print("---------------------") af = tb.arrayfactor(pos, ang, dime=-2, dimc=-1, w=None, lambd=1., unit='deg') print(af, af.shape) af = tb.arrayfactor(pos.unsqueeze(0), ang, dime=-2, dimc=-1, w=None, lambd=1., unit='deg') print(af, af.shape) print("-----------URA8x8--------------") az = th.arange(-60, 60, 0.1) el = th.arange(-15, 15, 0.1) ang = th.stack(th.meshgrid((az, el), indexing='ij'), dim=2) order = 'z<:y<' tc = [[0, 0, 0.5], [0, 0, 1.], [0, 0, 1.5], [0, 0, 2.], [0, 0, 2.5], [0, 0, 3.], [0, 0, 3.5], [0, 0, 4.]] rc = [[0, 0, 0], [0, 0.5, 0], [0, 1, 0], [0, 1.5, 0], [0, 2., 0], [0, 2.5, 0], [0, 3.0, 0], [0, 3.5, 0]] mc, mtid, mrid = tb.tr2mimo(tc, rc, order=order, axes='x:y:z') print("MIMO", mc) print("mtid", mtid) print("mrid", mrid) plt = tb.scatterxyz([[tc, rc, mc]], sizes=None, markers=[['^', 's', 'o']], fcolors=[['none', 'none', 'none']], ecolors=[['r', 'b', 'g']], legends=[['Tx', 'Rx', 'Vx']], xlabels='X', ylabels='Y', zlabels='Z', grids=True); plt.show() w = tb.steervec(mc, ang=[[10, 5]], dim=-1) af = tb.arrayfactor(mc, ang, dimc=-1, w=w, keepang=True) afdb = af.abs() plt = tb.mshow([afdb[0].T], Xs=az, Ys=el, cmap=tb.parula, xlabels='Azimuth', ylabels='Elevation'); plt.show() plt = tb.mesh([afdb[0]], Xs=ang[..., 0], Ys=ang[..., 1], cmap=tb.parula, xlabels='Azimuth', ylabels='Elevation'); plt.show() print("-------UCA----------") tc = [[0, 0, 0.5], [0, 0, 1.], [0, 0, 1.5], [0, 0, 2.], [0, 0, 2.5], [0, 0, 3.], [0, 0, 3.5], [0, 0, 4.]] rc = [[0, 0, 0], [0, 0.5, 0], [0, 1, 0], [0, 1.5, 0], [0, 2., 0], [0, 2.5, 0], [0, 3.0, 0], [0, 3.5, 0]] mc, mtid, mrid = tb.tr2mimo(tc, rc, order='z<:y<', axes='x:y:z') mc = tb.pol2car(20, a=th.arange(0, 360, 10), unita='deg') mc = th.stack((mc[0], mc[1]), dim=-1) mc = tb.arraypos(mc, dim=-1, axes='yz') az = th.arange(-60, 60, 0.1) el = th.arange(-45, 45, 0.1) ang = th.stack(th.meshgrid((az, el), indexing='ij'), dim=2) ang = th.stack((ang, ang), dim=0) mc = th.stack((mc, mc, mc, mc), dim=0) w = tb.steervec(mc, ang=[[45, 30]], dim=-1) af = tb.arrayfactor(mc, ang, dimc=-1, w=w, keepang=True) afdb = af.abs() # afdb = tb.mag2db(afdb/afdb.max()) print(afdb.shape) plt = tb.mshow([afdb[0, 0, 0].T], Xs=az, Ys=el, cmap=tb.parula, xlabels='Azimuth', ylabels='Elevation'); plt.show()
- torchbox.antenna.pattern.arraypos(pos, dim=-1, axes='yz')
converts 1d/2d coordinates to 3d
- Parameters:
Examples
pos = [1, 2, 3, 4] pos3d = arraypos(pos, dim=-1, axes='y') print(pos3d, pos3d.shape) pos = [(0, 1), (2, 3), (4, 5), (6, 7)] pos3d = arraypos(pos, dim=-1, axes='yz') print(pos3d, pos3d.shape) pos = [(0, 0, 1), (0, 2, 3), (0, 4, 5), (0, 6, 7)] pos3d = arraypos(pos, dim=-1, axes='xyz') print(pos3d, pos3d.shape)
- torchbox.antenna.pattern.findmlsl(ydb, dim=None, hmin=None)
find mainlobe and sidelobe
- Parameters:
- Returns:
mlidx (int or list) – mainlobe index integer (1 sample) or list (multiple samples)
mlextent (tensor or list) – mainlobe extent tensor (1 sample) or list of tensor (multiple samples)
nulls (tensor or list) – nulls tensor (1 sample) or list of tensor (multiple samples)
slidxs (tensor) – sidelobe indexes tensor (1 sample) or list of tensor (multiple samples)
slflag (bool) – has sidelobe flag bool (1 sample) or list of bool (multiple samples)?
- torchbox.antenna.pattern.ilaf(pos, al, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg')
- torchbox.antenna.pattern.islraf(pos, aml, asl, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg', omode='iml/isl')
- torchbox.antenna.pattern.plaf(pos, al, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg')
- torchbox.antenna.pattern.pslraf(pos, aml, asl, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg', omode='pml/psl')
- torchbox.antenna.pattern.sidelobelevel(ydb, dim=None, sf=0, hmin=None, returns=['psl', 'isl'])
computes sidelobe level
\[PSL = 10*log10(max(y(sl).^2)/max(y(ml).^2)) \]where .. math:: y=10.^{(Y/20)}
- Parameters:
dim (int, list, tuple or None) – dimensions for finding peaks, by default None (all)
sf (int, optional) – a smoothing window size factor, ranging from 0 to 1., by default 0 (no smoothing)
hmin (int, optional) – smaller than
hmindB are disregarded in mainlobe and sidelobe detection, by default None (no limitation)returns (list, optional) – which to return, by default [‘psl’, ‘isl’]
- torchbox.antenna.pattern.sleloss(pos, fov=(-60, 60), res=0.1, acc=0.01, adir='az')
lidelobe energy loss
- Parameters:
fov (list or tuple) – the field of view, e.g. (-60, 60), [(-60, 60), (0, 255)], by default (-60, 60)
res (float, list or tuple) – the resolution, e.g. 0.1, [0.1, 1.0], by default 0.1
acc (float, optional) – the accuracy, by default 0.01
adir (str, optional) – angle direction, only work for 1 dimensional case.
- torchbox.antenna.pattern.sllaf(pos, asl, dime=-2, dimc=-1, w=None, lambd=1.0, unit='deg')
- torchbox.antenna.pattern.steervec(pos, ang, dim=-1, lambd=1.0, unit='deg', keepang=False)
steering vector
- Parameters:
ang (list, tuple or tensor) – angle values in azimuth and elevation direction
dim (int, optional) – the dimensional index of coordinate in
posandang, by default -1.lambd (float, optional) – wave length, by default 1.
unit (str, optional) –
'deg'or'rad', by default'deg'keepang (bool, optional) – keep ang’s shape, by default False
- Returns:
steering vector
- Return type:
tensor
Examples
import torch as th import torchbox as tb ang = [[10, 20, 30, -40], [0, 0, 0, 0]] pos = [[0, 0, 0, 0, 0, 0, 0], [0, 0.5, 1, 1.5, 2, 2.5, 3], [0, 0, 0, 0, 0, 0, 0]] sv = tb.steervec(pos, ang, dim=0) print(sv, sv.shape) ang = th.tensor(ang) pos = th.tensor(pos) sv = tb.steervec(pos, ang, dim=0) print(sv, sv.shape) ang = ang.T pos = pos.T sv = tb.steervec(pos, ang, dim=-1) print(sv, sv.shape) sv = tb.steervec(pos, ang, dim=-1) print(sv, sv.shape) sv = tb.steervec(pos.unsqueeze(0), ang, dim=-1) print(sv, sv.shape)