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 set of information bits in a sequence into a message such that , where to form messages. each of the messages, , is mapped to real-valued channel uses, , which results in an effective coding rate of data bits per real channel use. then, two real channel uses are mapped into a complex symbol to create . the normalization layer of the encoder imposes constraints on to further restrict the encoded symbols. to illustrate possibilities, these constraints are implemented using the normalization layer:
energy constraint:
average power constraint:
normalized symbols are mapped onto the ofdm subcarriers and passed through an awgn channel.
the transmitter encodes and outputs encoded symbols, . the channel impairs the encoded symbols to generate . the receiver decodes and outputs estimate, , of the transmitted message .
the input message is a one-hot vector , whose elements are all zeros except the one. the awgn channel adds noise to achieve the specified signal to noise power ratio, .
generate and preprocess data
the input to the transmitter is a random sequence of bits. bits can create distinct messages or input symbols. the input symbol is a categorical feature from the set of . 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, . 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 . size of training labels is .
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, , to 256. the two fully connected layers map bits (in the form of length one-hot arrays) into real numbers, resulting in a rate communications system. after normalization, the ofdm modulator layer maps these real numbers into 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 . therefore, the input to the neural network is a sequence of one-hot values with size . this network uses the sequenceinputlayer
function with number of features and 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, . the following trains an ofdm-based (6,2) autoencoder, which is equivalent to having a coding rate, , of 1/3. set 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) %#okend
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 value was low enough to cause some errors but not too low to avoid convergence. if 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)
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')
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 -1] range that represents 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 vector into a complex valued vector such that the odd and even elements are mapped into the in-phase and the quadrature component of a complex symbol, respectively, where . in other words, treat the 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 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 . for this 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))
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 ( ), the autoencoder can learn to obtain coding gain better than the simple repetition codes.
change , , , , and normalization to train different autoencoders. try different training 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 , , normalization, and 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) | fullyconnectedlayer
(deep learning toolbox) | (deep learning toolbox) | (deep learning toolbox)
related topics
- deep learning in matlab (deep learning toolbox)