main content

ofdm autoencoder for wireless communications -凯发k8网页登录

this example shows how to model an end-to-end orthogonal frequency division modulation (ofdm) communications system with an autoencoder to reliably transmit information bits over a wireless channel.

introduction

this example uses an autoencoder together with ofdm modulator and demodulator layers to design and implement a multi-carrier communications system.

in this example, you will learn how to:

  • use the (deep learning toolbox) function to train the network with multiple snr values.

  • create ofdm modulation and demodulation layers using the and functions.

  • train a fully connected neural network with embedded ofdm modulation and demodulation.

  • separate the neural network into encoder and decoder networks.

  • run bler simulations to compare error rate performance of a conventional ofdm link to an ai-based ofdm link.

for an equivelent single-carrier communications system, see the example.

ofdm-based autoencoder system

this block diagram shows a wireless autoencoder communications system. the encoder (transmitter) first maps each k set of information bits in a sequence into a message s such that s{0,,m-1}, where m=2k to form t messages. each of the t messages, s, is mapped to n real-valued channel uses, x=f(s)rn, which results in an effective coding rate of r=k/n data bits per real channel use. then, two real channel uses are mapped into a complex symbol to create xc=g(s)cn/2. the normalization layer of the encoder imposes constraints on x to further restrict the encoded symbols. to illustrate possibilities, these constraints are implemented using the normalization layer:

  • energy constraint: xi22=1,i

  • average power constraint: e[|xi|2]=1,i

normalized symbols are mapped onto the ofdm subcarriers and passed through an awgn channel.

autoencoder_ofdm.png

the transmitter encodes s and outputs encoded symbols, x. the channel impairs the encoded symbols to generate yrn/2. the receiver decodes y and outputs estimate, sˆ, of the transmitted message s.

the input message is a one-hot vector 1srm, whose elements are all zeros except the sth one. the awgn channel adds noise to achieve the specified signal to noise power ratio, snr.

generate and preprocess data

the input to the transmitter is a random sequence of k bits. k bits can create m=2k distinct messages or input symbols. the input symbol is a categorical feature from the set of {0,1,...,m-1}. as the number of possible input symbols increases, the number of training symbols must increase to give the network a chance to experience a large number of possible input combinations. the same is true for the number of validation symbols. set number of input bits to 2.

k = 2;  % information bits per symbol
m = 2^k;                % size of information symbols set
numtrainsymbols = 2560 * m;
numvalidationsymbols = 128 * m;

the autoencoder neural network best works with one-hot inputs and classifies each input symbol as one of the categorical values, {0,1,...,m-1}. convert random input symbols into a one-hot array using (deep learning toolbox) function and create labels of categorical values. place the one-hot value to the first dimension (rows) and input symbols to the second dimension (columns).

dtrain = randi([0 m-1],1,5)
dtrain = 1×5
     3     3     0     3     2
trainsymbolstemp = onehotencode(dtrain,1,"classnames",0:m-1)
trainsymbolstemp = 4×5
     0     0     1     0     0
     0     0     0     0     0
     0     0     0     0     1
     1     1     0     1     0
trainlabelstemp = categorical(dtrain)
trainlabelstemp = 1x5 categorical
     3      3      0      3      2 

training the neural network at several snr levels ensures that the autoencoder can handle a range of snr values without retraining. set training snr values as an array between -1 db and 9 db. generate multiple batches of training sequences, where each batch (cell) experiences a different snr. set random number generator state for repeatable results for demonstration purposes only.

trainsnrvec = -1:2:9;     % training snr (db)
rng(1234)
trainsymbols = cell(1,length(trainsnrvec));
trainlabels = cell(1,length(trainsnrvec));
validationsymbols = cell(1,length(trainsnrvec));
validationlabels = cell(1,length(trainsnrvec));
for p=1:length(trainsnrvec)
  dtrain = randi([0 m-1],1,numtrainsymbols);
  dvalid = randi([0 m-1],1,numvalidationsymbols);
  trainsymbols{p} = onehotencode(dtrain,1,"classnames",0:m-1);
  trainlabels{p} = categorical(dtrain);
  validationsymbols{p} = onehotencode(dvalid,1,"classnames",0:m-1);
  validationlabels{p} = categorical(dvalid);
end

size of training symbols is m×nsym. size of training labels is 1×nsym.

numbatches = length(trainsymbols)
numbatches = 6
sizetrainsymbols = size(trainsymbols{1})
sizetrainsymbols = 1×2
           4       10240
sizetrainlabels = size(trainlabels{1})
sizetrainlabels = 1×2
           1       10240

define and train neural network model

the second step of designing an ai-based system is to define and train the neural network model.

define neural network

this example uses a modified version of the autoencoder neural network proposed in [2]. set the number of subcarriers, nfftn sub fft, to 256. the two fully connected layers map k bits (in the form of length m one-hot arrays) into n real numbers, resulting in a rate r=k/n communications system. after normalization, the ofdm modulator layer maps these n real numbers into n/2 complex valued symbols and assigns each symbol to a subcarrier. to ensure that ofdm modulator layer outputs full ofdm symbols, set minimum input length, minlength, of the sequence input layer in the third dimension (t) to nfft. therefore, the input to the neural network is a sequence of one-hot values with size m×nfft. this network uses the sequenceinputlayer function with m number of features and nfft sequence length.

the reliability of the communication link can be increased through multiple uses of the channel for the same information symbol, which is also known as coding gain. an autoencoder can learn to leverage this increased number of channel uses, n>k. the following trains an ofdm-based (6,2) autoencoder, which is equivalent to having a coding rate, r, of 1/3. set n to 6.

nfft          = 256;   % number of ofdm subcarriers
n             = 6;      % (n/2) is the number of complex channel uses
cplength      = 4;      % samples
normalization = "energy";   % normalization "energy" | "average power"
ofdmaelayergraph = [
  sequenceinputlayer(m,name="one-hot input",minlength=nfft)
  
  fullyconnectedlayer(m,name="fc_1")
  relulayer(name="relu_1")
  
  fullyconnectedlayer(n,name="fc_2",biasinitializer="narrow-normal")
  
  helperaewofdmnormalizationlayer(method=normalization)
  helperaewofdmmodlayer(nfft,cplength,name="ofdm mod");
  
  helperaewofdmawgnlayer(snr=trainsnrvec,signalpower=1)
  
  helperaewofdmdemodlayer(nfft,cplength,name="ofdm demod");
  
  fullyconnectedlayer(m,name="fc_3")
  relulayer(name="relu_2")
  
  fullyconnectedlayer(m,name="fc_4")
  softmaxlayer(name="softmax")
  
  classificationlayer(name="classoutput")];

the following shows the output sizes for each layer in the autoencoder layer.

to see the full analysis of the network, check the box in the if statement.

if false
  analyzenetwork(ofdmaelayergraph) %#ok
end

train neural network

set the training options for the autoencoder neural network and train the network using the (deep learning toolbox) function. training takes about 15 seconds on an amd epyc 7262 3.2 ghz 8c/16t.

% set training options
options = trainingoptions('adam', ...
  initiallearnrate=0.02, ...
  maxepochs=10, ...
  outputnetwork="best-validation-loss", ...
  shuffle='every-epoch', ...
  validationdata={validationsymbols,validationlabels}, ...
  learnrateschedule="piecewise", ...
  learnratedropperiod=5, ...
  learnratedropfactor=0.1, ...
  executionenvironment="cpu", ...
  plots='none', ...
  sequencelength=nfft);
% train the autoencoder network
[trainednet,traininfo] = trainnetwork(trainsymbols,trainlabels,ofdmaelayergraph,options);
|======================================================================================================================|
|  epoch  |  iteration  |  time elapsed  |  mini-batch  |  validation  |  mini-batch  |  validation  |  base learning  |
|         |             |   (hh:mm:ss)   |   accuracy   |   accuracy   |     loss     |     loss     |      rate       |
|======================================================================================================================|
|       1 |           1 |       00:00:00 |       13.22% |       24.67% |       1.6775 |       1.4967 |          0.0200 |
|       2 |          50 |       00:00:02 |       74.15% |       72.56% |       0.4678 |       0.4751 |          0.0200 |
|       3 |         100 |       00:00:05 |       95.18% |       95.67% |       0.1513 |       0.1256 |          0.0200 |
|       4 |         150 |       00:00:08 |       97.14% |       96.65% |       0.0893 |       0.1177 |          0.0200 |
|       5 |         200 |       00:00:11 |       96.48% |       96.29% |       0.1010 |       0.1127 |          0.0200 |
|       7 |         250 |       00:00:13 |       96.29% |       96.48% |       0.0968 |       0.1106 |          0.0020 |
|       8 |         300 |       00:00:17 |       97.53% |       96.26% |       0.1039 |       0.1224 |          0.0020 |
|       9 |         350 |       00:00:20 |       96.61% |       96.39% |       0.1090 |       0.1210 |          0.0020 |
|      10 |         400 |       00:00:25 |       96.88% |       96.06% |       0.0999 |       0.1272 |          0.0020 |
|======================================================================================================================|
training finished: max epochs completed.
traininfo.n = n;
traininfo.k = k;
traininfo.normalization = normalization;

plot the training progress. the validation accuracy quickly reaches more than 90% while the validation loss keeps slowly decreasing. this behavior shows that the training snr value was low enough to cause some errors but not too low to avoid convergence. if snr is too high that the network does not experience any errors, then the autoencoder does not learn how to correct channel impairments. a rule of thumb is to keep the validation accuracy between 85% and 95%. for definitions of validation accuracy and validation loss, see (deep learning toolbox) section.

figure
helperaewplottrainingperformance(traininfo)

figure contains an axes object. the axes object with xlabel iteration, ylabel validation accuracy contains 2 objects of type line.

separate the network into encoder and decoder parts. encoder starts with the input layer and ends after the ofdm modulator layer. since the ofdm modulator changes the number of time samples (adds cyclic-prefix), use dlnetwork for the encoder network.

for idxofdmlayer = 1:length(trainednet.layers)
  if isa(trainednet.layers(idxofdmlayer), 'helperaewofdmmodlayer')
    break
  end
end
lgraph = layergraph(trainednet.layers(1:idxofdmlayer));
txnet = dlnetwork(lgraph);

decoder starts with the ofdm demodulator layer and ends with the classification layer. add a feature input layer at the beginning. since the ofdm demodulator changes the number of time samples (removes cyclic-prefix), use dlnetwork for the decoder network.

for idxofdmdemod = idxofdmlayer 1:length(trainednet.layers)
  if isa(trainednet.layers(idxofdmdemod), 'helperaewofdmdemodlayer')
    break
  end
end
firstlayername = trainednet.layers(idxofdmdemod).name;
lgraph = addlayers(layergraph(sequenceinputlayer(2,name="rxin",minlength=(nfft cplength)*n/2)), ...
  trainednet.layers(idxofdmdemod:end));
lgraph = connectlayers(lgraph,'rxin',firstlayername);
lgraph = removelayers(lgraph, 'classoutput');
rxnet = dlnetwork(lgraph);

use the plot object function of the trained network objects to show the layer graphs of the full autoencoder, the encoder network, which is the transmitter, and the decoder network, which is the receiver.

figure
tiledlayout(2,2)
nexttile([2 1])
plot(trainednet)
title('autoencoder')
nexttile
plot(txnet)
title('encoder/tx')
nexttile
plot(rxnet)
title('decoder/rx')

figure contains 3 axes objects. axes object 1 with title autoencoder contains an object of type graphplot. axes object 2 with title encoder/tx contains an object of type graphplot. axes object 3 with title decoder/rx contains an object of type graphplot.

compare bler of ofdm-based autoencoder and conventional ofdm over awgn channel

set up simulation parameters. the following parameters ensures the simulation runs in about one minute while providing acceptable bler results. increase the snr range and maximum number of frames to get more reliable results for a wider range.

snrvec = 0:2:8;
symbolsperframe = nfft;
signalpower = 1;

generate random integers in the [0 m-1] range that represents k random information bits. encode these information bits into complex symbols with function. the helperaewofdmencode function runs the encoder part of the autoencoder then maps the real valued x vector into a complex valued xc vector such that the odd and even elements are mapped into the in-phase and the quadrature component of a complex symbol, respectively, where xc=x(1:2:end) jx(2:2:end). in other words, treat the x array as an interleaved complex array.

pass the complex symbols through an awgn channel. decode the channel impaired complex symbols with the function. the following code runs the simulation for each snr point for at least 100 block errors or at most 2000 frames. if is installed and a license is available, uncomment the parfor line to run the simulations on a parallel pool.

minnumerrors = 100;
maxnumframes = 1000;
m = 2^k;
bler = zeros(length(snrvec),2);
t = tic;
%parfor snridx = 1:length(snrvec)
for snridx = 1:length(snrvec)
  snr = snrvec(snridx);
  disp("simulating for snr = "   snr)
  
  numblockerrors = 0;
  numconvsymbolerrors = 0;
  framecnt = 0;
  while (numblockerrors < minnumerrors) ...
      && (framecnt < maxnumframes)
    d = randi([0 m-1],symbolsperframe,1);         % random information symbols
    % run ae tx
    x = helperaewofdmencode(d,txnet);             % encoder
    % run coded ofdm tx
    coded = repelem(d,round(n/k));                % simple repetition code
    xqamcoded = qammod(coded,m,unitaveragepower=true);
    xconvcoded = sqrt(nfft) * ofdmmod(reshape(xqamcoded,round(n/k),[])',nfft,cplength);
    % put both through the same channel
    y = awgn(x,snr,signalpower);
    yconvcoded = awgn(xconvcoded,snr,signalpower);
    % run ae rx
    dhat = helperaewofdmdecode(y,rxnet);          % decoder
    % run coded ofdm rx
    xqamhatcoded = ofdmdemod(yconvcoded,nfft,cplength);
    dconvhatcoded = qamdemod(xqamhatcoded',m,unitaveragepower=true);
    dconvdecoded = mode(dconvhatcoded,1)';
    % compute and contrast error rate
    numblockerrors = numblockerrors   sum(d ~= dhat);
    numconvsymbolerrors = numconvsymbolerrors   sum(d ~= dconvdecoded);
    framecnt = framecnt   1;
  end
  bler(snridx,:) = [numblockerrors  numconvsymbolerrors] ...
    ./ (framecnt*symbolsperframe);
end
simulating for snr = 0
simulating for snr = 2
simulating for snr = 4
simulating for snr = 6
simulating for snr = 8
et = seconds(toc(t));
et.format = 'mm:ss.sss';
disp("total simulation time: "   string(et))
total simulation time: 01:03.374

compare the results with that of an uncoded qpsk system with block length n=6. for this n value, the autoencoder can get more coding gain than a simple repetition code. also, it provides about 5.5 db gain as compared to an uncoded qpsk system with block length 6.

figure
ebnovec = convertsnr([snrvec 10],"snr","ebno",bitspersymbol=k);
semilogy(snrvec,bler,'-o')
hold on
% calculate uncoded block error rate
pskbler = 1-(1-berawgn(ebnovec,'psk',2^k,'nondiff')).^n;
semilogy([snrvec 10],pskbler,'--x')
hold off
ylim([1e-4 1])
grid on
xlabel('e_b/n_o (db)')
ylabel('bler')
legend(sprintf('ae-ofdm (%d,%d)',n,k),sprintf('conv-ofdm (%d,%d)',n,k),sprintf('qpsk (%d,%d)',n,k))

figure contains an axes object. the axes object with xlabel e indexof b baseline / n indexof o baseline blank ( d b ), ylabel bler contains 3 objects of type line. these objects represent ae-ofdm (6,2), conv-ofdm (6,2), qpsk (6,2).

conclusions and further exploration

the bler results show that by inserting the expert knowledge in the form of ofdm modulation and demodulation to the neural network, an ofdm-based autoencoder can be trained. by allowing for multiple channel uses per input symbol ( n>k ), the autoencoder can learn to obtain coding gain better than the simple repetition codes.

change n, k, nfft, cplength, and normalization to train different autoencoders. try different training snr values to optimize the training performance. see the help for the function and the function.

the results are obtained using the following default settings for training and bler simulations:

trainparams.plots = 'none';
trainparams.verbose = true;
trainparams.maxepochs = 10;
trainparams.initiallearnrate = 0.08;
trainparams.learnrateschedule = 'piecewise';
trainparams.learnratedropperiod = 5;
trainparams.learnratedropfactor = 0.1;
trainparams.sequencelength = nfft;
simparams.snrvec = 0:2:12;
simparams.minnumerrors = 100;
simparams.maxnumframes = 3000;
simparams.numsymbolsperframe = nfft;
simparams.signalpower = 1;

vary these parameters to train different autoencoders and test their bler performance. experiment with different n, k, normalization, nfft and snr values.

list of helper functions

references

[1] t. o’shea and j. hoydis, "an introduction to deep learning for the physical layer," in ieee transactions on cognitive communications and networking, vol. 3, no. 4, pp. 563-575, dec. 2017, doi: 10.1109/tccn.2017.2758370.

[2] a. felix, s. cammerer, s. dörner, j. hoydis and s. ten brink, "ofdm-autoencoder for end-to-end learning of communications systems," 2018 ieee 19th international workshop on signal processing advances in wireless communications (spawc), 2018, pp. 1-5, doi: 10.1109/spawc.2018.8445920.

see also

| | (deep learning toolbox) | (deep learning toolbox) | (deep learning toolbox) | (deep learning toolbox) | (deep learning toolbox)

related topics

网站地图