# 【OFDM通信】基于matlab深度学习OFDM系统信号检测【含Matlab源码 2023期】

## 一、深度学习OFDM系统信号检测简介

1 OFDM系统模型
OFDM系统是一种常用的多载波调制方式， 因为其具有能够在带宽较窄的情况下传输大量数据、能够对抗频率选择性衰落、传输速率高、实现简单、信道利用率高、抗窄带干扰能力强等优点而受到广泛使用。本节主要介绍了OFDM系统实现的基本原理以及系统模型。

1.1OFDM系统基本原理

1.2OFDM系统模型
OFDM符号是由若干个子载波组成， 且每个子载波都要受到相移键控I+!!(phase-shift keying， PSK) 或者正交幅度调制+2(Quadrature Amplitude Modulation， QAM) 的调制。在发送端， 设N为子载波的数量， T为OFDM符号的宽度， d(i=0， 1…N-1)为分配给每个子载波的数据符号， f：为第0个子载波的载波频率， rect() =1， |sT/2，则从t=1， 开始的OFDM符号表达式为：

Y=XH+Z(2-8)

## 二、部分源代码

%% Clear workspace

clear variables;
close all;

%% Load common parameters and the trained NN

%% Other simulation parameters

NumPilot = length(FixedPilot);
PilotSpacing = NumSC/NumPilot;
NumOFDMsym = NumPilotSym+NumDataSym;
NumClass = length(Label);
NumPath = length(h);

% Load pre-calculated channel autocorrelation matrix for MMSE estimation
% This autocorrelation matrix is calculated in advance using the 3GPP
% channel model, which can be replaced accordingly.

%% SNR range

Es_N0_dB = 0:2:20; % Es/N0 in dB
Es_N0 = 10.^(Es_N0_dB./10); % linear Es/N0
N0 = 1./Es_N0;
NoiseVar = N0./2;

%% Testing data size

NumPacket = 10000; % Number of packets simulated per iteration

%% Simulation

% Same pilot sequences used in training and testing stages
FixedPilotAll = repmat(FixedPilot,1,1,NumPacket);

% Number of Monte-Carlo iterations
NumIter = 1;

% Initialize error rate vectors
SER_DL = zeros(length(NoiseVar),NumIter);
SER_LS = zeros(length(NoiseVar),NumIter);
SER_MMSE = zeros(length(NoiseVar),NumIter);

for i = 1:NumIter

``````for snr = 1:length(NoiseVar)

%% 1. Testing data generation

noiseVar = NoiseVar(snr);

% OFDM pilot symbol (can be interleaved with random data symbols)
PilotSym = 1/sqrt(2)*complex(sign(rand(NumPilotSym,NumSC,NumPacket)-0.5),sign(rand(NumPilotSym,NumSC,NumPacket)-0.5));
PilotSym(1:PilotSpacing:end) = FixedPilotAll;

% OFDM data symbol
DataSym = 1/sqrt(2)*complex(sign(rand(NumDataSym,NumSC,NumPacket)-0.5),sign(rand(NumDataSym,NumSC,NumPacket)-0.5));

% Transmitted OFDM frame
TransmittedPacket = [PilotSym;DataSym];

% Collect the data labels for the selected subcarrier
DataLabel = zeros(size(DataSym(:,idxSC,:)));
for c = 1:NumClass
DataLabel(logical(DataSym(:,idxSC,:) == 1/sqrt(2)*Mod_Constellation(c))) = Label(c);
end
DataLabel = squeeze(DataLabel);

% Testing data collection
XTest = cell(NumPacket,1);
YTest = zeros(NumPacket,1);
for c = 1:NumClass
featureVec = mat2cell(feature,size(feature,1),ones(1,size(feature,2)));
XTest(idx) = featureVec;
YTest(idx) = label;
end
YTest = categorical(YTest);

%% 2. DL detection

YPred = classify(Net,XTest,'MiniBatchSize',MiniBatchSize);
SER_DL(snr,i) = 1-sum(YPred == YTest)/NumPacket;

%% 3. LS & MMSE detection

% Channel estimation
wrapper = @(x,y) performChanEstimation(x,y,RHH,noiseVar,NumPilot,NumSC,NumPath,idxSC);
PilotSeq = mat2cell(FixedPilotAll,1,NumPilot,ones(1,NumPacket));
EstChanLS = cell2mat(squeeze(EstChanLS));
EstChanMMSE = cell2mat(squeeze(EstChanMMSE));

% Symbol detection

end
``````

end
% This function is to model the transmission and reception process in OFDM systems.

% Extract parameters
[NumSym,NumSC,NumPacket] = size(TransmittedFrame);

%% Transmitter

PhaseShift = exp(-1j*rand(1,NumPacket)2pi);

for p = 1:NumPacket

``````% 1. IFFT
x1 = ifft(TransmittedFrame(:,:,p),NumSC,2);

% 2. Inserting CP
x1_CP = [x1(:,NumSC-LengthCP+1:end) x1];

% 3. Parallel to serial transformation
x2 = x1_CP.';
x = x2(:);

% 4. Channel filtering
y_conv = conv(h*PhaseShift(p),x);
y(:,p) = y_conv(1:length(x));
``````

end

SeqLength = size(y,1);

% Calculate random noise in time domain
NoiseF = sqrt(NoiseVar)/sqrt(2).(randn(NumPacket,NumSC)+1jrandn(NumPacket,NumSC)); % Frequency-domain noise
NoiseT = sqrt(SeqLength)*sqrt(SeqLength/NumSC)*ifft(NoiseF,SeqLength,2); % Time-domain noise

y = y+NoiseT.';

for p = 1:NumPacket

``````% 1. Serial to parallem transformation
y1 = reshape(y(:,p),NumSC+LengthCP,NumSym).';

% 2. Removing CP
y2 = y1(:,LengthCP+1:LengthCP+NumSC);

% 3. FFT, # x NymSym x 64
ReceivedPacket(p,:,:) = fft(y2,NumSC,2); % NumSym x 64
``````

end

## 四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 高俊伟.基于深度学习的OFDM信号检测算法研究[D].哈尔滨工程大学

3 备注

THE END