Skip to content

Commit

Permalink
getting good results from frame2 with constant phase offset
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Feb 3, 2025
1 parent a77e1c9 commit 3ec7a49
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
29 changes: 15 additions & 14 deletions ml_eq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ML experiment in EQs
ML-EQ experiments using toy digital modems.
"""

Expand All @@ -15,8 +15,9 @@
parser.add_argument('--EbNodB', type=float, default=100, help='energy per bit over spectral noise density in dB')
parser.add_argument('--epochs', type=int, default=10, help='number of training epochs')
parser.add_argument('--lr', type=float, default=5E-2, help='learning rate')
parser.add_argument('--loss_phase', action='store_true', help='')
parser.add_argument('--phase_offset', action='store_true', help='insert random phase offset')
parser.add_argument('--loss_phase', action='store_true', help='use phase error as loss function (default symbol MSE)')
parser.add_argument('--phase_offset', action='store_true', help='insert random phase offset [-pi,pi]')
parser.add_argument('--freq_offset', action='store_true', help='insert freq offset uniform [-f,f] cycles/symb')
parser.add_argument('--eq', type=str, default='ml', help='equaliser ml/bypass/dsp (default ml)')
parser.add_argument('--notrain', action='store_false', dest='train', help='bypass training (default train, then inference)')
parser.add_argument('--noplots', action='store_false', dest='plots', help='disable plots (default plots enabled)')
Expand Down Expand Up @@ -201,18 +202,18 @@ def __init__(self, framer, w1, EbNodB):
self.EbNodB = EbNodB

self.dense1 = nn.Linear(2*self.n_total, w1)
self.dense2 = nn.Linear(w1+2*self.n_total, w1)
self.dense3 = nn.Linear(w1+2*self.n_total, w1)
self.dense4 = nn.Linear(w1+2*self.n_total, w1)
self.dense5 = nn.Linear(w1+2*self.n_total, 2*self.n_data)

self.dense2 = nn.Linear(w1, w1)
self.dense3 = nn.Linear(2*w1, w1)
self.dense4 = nn.Linear(3*w1, w1)
self.dense5 = nn.Linear(4*w1, 2*self.n_data)
# note rx_frame complex values passed in as real,imag pairs
def equaliser(self, rx_frame):
x = torch.relu(self.dense1(torch.cat([rx_frame],-1)))
x = torch.relu(self.dense2(torch.cat([x, rx_frame],-1)))
x = torch.relu(self.dense3(torch.cat([x, rx_frame],-1)))
x = torch.relu(self.dense4(torch.cat([x, rx_frame],-1)))
equalised_data = self.dense5(torch.cat([x, rx_frame],-1))
x = torch.relu(self.dense1(rx_frame))
x = torch.cat([x,torch.relu(self.dense2(x))],-1)
x = torch.cat([x,torch.relu(self.dense3(x))],-1)
x = torch.cat([x,torch.relu(self.dense4(x))],-1)
equalised_data = self.dense5(x)
return equalised_data

# tx_data is complex, return real values real,imag pairs to suit loss function
Expand Down Expand Up @@ -316,7 +317,7 @@ def single_point(EbNodB, n_syms):
return BER, rx_data_float, rx_data_eq

if len(args.curve):
EbNodB = np.array([0,1,2,3,4,5,6,7,8], dtype=np.float32)
EbNodB = np.array([-5,-4,-3,-2,-1,0,1,2,3,4,5,7,8], dtype=np.float32)
n_tests = len(EbNodB)
curve = np.zeros((n_tests,2))
for i in np.arange(0,n_tests):
Expand Down
9 changes: 5 additions & 4 deletions mleq_curves.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# ML EQ experiments - generates sets of curves

epochs=100
n_syms=100000
n_syms=1000000
batch_size=128
lr=0.1

function train() {
f=$1
# train with mse and phase loss functions
python3 ml_eq.py --frame ${f} --EbNodB 4 --phase_offset \
--lr 0.05 --n_syms ${n_syms} --epochs ${epochs} --batch_size ${batch_size} --save_model mleq0${f}_mse.model --noplots
--lr ${lr} --n_syms ${n_syms} --epochs ${epochs} --batch_size ${batch_size} --save_model mleq0${f}_mse.model --noplots
python3 ml_eq.py --frame ${f} --loss_phase --EbNodB 4 --phase_offset \
--lr 0.05 --n_syms ${n_syms} --epochs ${epochs} --batch_size ${batch_size} --save_model mleq0${f}_phase.model --noplots
--lr ${lr} --n_syms ${n_syms} --epochs ${epochs} --batch_size ${batch_size} --save_model mleq0${f}_phase.model --noplots
}

function curve() {
Expand All @@ -32,6 +33,6 @@ if [ $# -ne 1 ]; then
exit 1
fi

train $1
#train $1
curve $1

1 change: 1 addition & 0 deletions radae_plots.m
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ function plot_ber_EbNodB(lin_fn,mse_fn="",phase_fn="",png="", epslatex="")
semilogy(lin(:,1),theory,'bk+-;theory;')
hold off;
grid; xlabel('Eb/No (dB)'); ylabel('BER');
axis([lin(1,1) lin(end,1) 1E-3 5E-1]);
if length(png)
print("-dpng",png,"-S800,600");
end
Expand Down

0 comments on commit 3ec7a49

Please sign in to comment.