FPGA调制分类与神经网络数字预失真设计
立即解锁
发布时间: 2025-09-06 00:17:13 阅读量: 3 订阅数: 54 AIGC 

# FPGA调制分类与神经网络数字预失真设计
## 1. FPGA调制分类
### 1.1 前提条件
要进行调制分类,需要以下工具和硬件:
- Deep Learning Toolbox™
- Deep Learning HDL Toolbox™
- Deep Learning HDL Toolbox™ Support Package for Xilinx FPGA and SoC
- Communications Toolbox™
- Xilinx™ Zynq® UltraScale+™ MPSoC ZCU102 Evaluation Kit
### 1.2 预测调制类型
训练好的卷积神经网络(CNN)可以识别以下八种数字和三种模拟调制类型:
- Binary phase shift keying (BPSK)
- Quadrature phase shift keying (QPSK)
- 8-ary phase shift keying (8-PSK)
- 16-ary quadrature amplitude modulation (16-QAM)
- 64-ary quadrature amplitude modulation (64-QAM)
- 4-ary pulse amplitude modulation (PAM4)
- Gaussian frequency shift keying (GFSK)
- Continuous phase frequency shift keying (CPFSK)
- Broadcast FM (B-FM)
- Double sideband amplitude modulation (DSB-AM)
- Single sideband amplitude modulation (SSB-AM)
以下是相关代码:
```matlab
modulationTypes = categorical(["BPSK", "QPSK", "8PSK", ...
"16QAM", "64QAM", "PAM4", "GFSK", "CPFSK", ...
"B-FM", "DSB-AM", "SSB-AM"]);
load trainedModulationClassificationNetwork
trainedNet
```
### 1.3 生成测试信号
生成具有Rician多径衰落、中心频率和采样时间漂移以及加性高斯白噪声(AWGN)的PAM4帧,具体步骤如下:
1. 使用`randi`生成随机比特。
2. 使用`pammod`进行PAM4调制。
3. 使用`rcosdesign`设计平方根升余弦脉冲成形滤波器。
4. 使用`filter`进行脉冲成形。
5. 使用`comm.RicianChannel`应用Rician多径信道。
6. 使用`comm.PhaseFrequencyOffset`应用相位和频率偏移。
7. 使用`interp1`应用采样时间漂移。
8. 使用`awgn`添加AWGN。
以下是代码实现:
```matlab
rng(123456)
d = randi([0 3], 1024, 1);
syms = pammod(d,4);
filterCoeffs = rcosdesign(0.35,4,8);
tx = filter(filterCoeffs,1,upsample(syms,8));
SNR = 30;
maxOffset = 5;
fc = 902e6;
fs = 200e3;
multipathChannel = comm.RicianChannel(...
'SampleRate', fs, ...
'PathDelays', [0 1.8 3.4] / 200e3, ...
'AveragePathGains', [0 -2 -10], ...
'KFactor', 4, ...
'MaximumDopplerShift', 4);
frequencyShifter = comm.PhaseFrequencyOffset(...
'SampleRate', fs);
reset(multipathChannel)
outMultipathChan = multipathChannel(tx);
clockOffset = (rand() * 2*maxOffset) - maxOffset;
C = 1 + clockOffset / 1e6;
frequencyShifter.FrequencyOffset = -(C-1)*fc;
outFreqShifter = frequencyShifter(outMultipathChan);
t = (0:length(tx)-1)' / fs;
newFs = fs * C;
tp = (0:length(tx)-1)' / newFs;
outTimeDrift = interp1(t, outFreqShifter, tp);
rx = awgn(outTimeDrift,SNR,0);
unknownFrames = helperModClassGetNNFrames(rx);
[prediction1,score1] = classify(trainedNet,unknownFrames);
helperModClassPlotScores(score1,modulationTypes)
```
### 1.4 波形生成用于训练
为每种调制类型生成10,000帧,其中80%用于训练,10%用于验证,10%用于测试。每帧长度为1024个样本,采样率为200 kHz。
```matlab
numFramesPerModType = 10000;
percentTrainingSamples = 80;
percentValidationSamples = 10;
percentTestSamples = 10;
sps = 8;
spf = 1024;
symbolsPerFrame = spf / sps;
fs = 200e3;
fc = [902e6 100e6];
```
### 1.5 创建信道损伤
每个帧需要经过以下信道损伤:
- AWGN
- Rician多径衰落
- 时钟偏移,导致中心频率偏移和采样时间漂移
```matlab
channel = helperModClassTestChannel(...
'SampleRate', fs, ...
'SNR', SNR, ...
'PathDelays', [0 1.8 3.4] / fs, ...
'AveragePathGains', [0 -2 -10], ...
'KFactor', 4, ...
'MaximumDopplerShift', 4, ...
'MaximumClockOffset', 5, ...
'CenterFrequency', 902e6)
chInfo = info(channel)
```
### 1.6 波形生成与存储
创建循环为每种调制类型生成信道受损帧,并将帧及其相应标签存储在MAT文件中。
```matlab
rng(1235)
tic
numModulationTypes = length(modulationTypes);
channelInfo = info(channel);
transDelay = 50;
dataDirectory = fullfile(tempdir,"ModClassDataFiles");
disp("Data file directory is " + dataDirectory);
fileNameRoot = "frame";
dataFilesExist = false;
if exist(dataDirectory,'dir')
files = dir(fullfile(dataDirectory,sprintf("%s*",fileNameRoot)));
if length(files) == numModulationTypes*numFramesPerModType
dataFilesExist = true;
end
end
if ~dataFilesExist
disp("Generating data and saving in data files...")
[success,msg,msgID] = mkdir(dataDirectory);
if ~success
error(msgID,msg)
end
for modType = 1:numModulationTypes
elapsedTime = seconds(toc);
elapsedTime.Format = 'hh:mm:ss';
fprintf('%s - Generating %s frames\n', ...
elapsedTime, modulationTypes(modType))
label = modulationTypes(modType);
numSymbols = (numFramesPerModType / sps);
dataSrc = helperModClassGetSource(modulationTypes(modType), sps, 2*spf, fs);
modulator = helperModClassGetModulator(modulationTypes(modType), sps, fs);
if contains(char(modulationTypes(modType)), {'B-FM','DSB-AM','SSB-AM'})
channel.CenterFrequency = 100e6;
else
channel.CenterFrequency = 902e6;
end
for p=1:numFramesPerModType
x = dataSrc();
y = modulator(x);
rxSamples = channel(y);
frame = helperModClassFrameGenerator(rxSamples, spf, spf, transDelay, sps);
fileName = fullfile(dataDirectory,...
sprintf("%s%s%03d",fileNameRoot,modulationTypes(modType),p));
save(fileName,"frame","label")
end
end
else
disp("Data files exist. Skip data generation.")
end
helperModClassPlotTimeDomain(dataDirectory,modulationTypes,fs)
helperModClassPlotSpectrogram(dataDirectory,modulationTypes,fs,sps)
```
### 1.7 创建数据存储
使用`signalDatastore`对象管理生成的复波形文件。
```matlab
frameDS = signalDatastore(dataDirectory,'SignalVariableNames',["frame","label"]);
```
### 1.8 转换复信号为实数组
将复信号转换为实值4-D数组。
```matlab
frameDSTrans = transform(frameDS,@helperModClassIQAsPages);
```
### 1.9 划分训练、验证和测试数据
将帧划分为训练、验证和测试数据。
```matlab
splitPercentages = [percentTrainingSamples,percentValidationSamples,percentTestSamples];
[trainDSTrans,validDSTrans,testDSTrans] = helperModClassSplitData(frameDSTrans,splitPercentages);
```
### 1.10 导入数据到内存
将文件中的数据导入内存以加快训练速度。
```matlab
pctExists = parallelComputingLicenseExists();
trainFrames = transform(trainDSTrans, @helperModClassReadFrame);
rxTrainFrames = readall(trainFrames,"UseParallel",pctExists);
rxTrainFrames = cat(4, rxTrainFrames{:});
validFrames = transform(validDSTrans, @helperModClassReadFrame);
rxValidFrames = readall(validFrames,"UseParallel",pctExists);
rxValidFrames = cat(4, rxValidFrames{:});
trainLabels = transform(trainDSTrans, @helperModClassReadLabel);
rxTrainLabels = readall(trainLabels,"UseParallel",pctExists);
validLabels = transform(validDSTrans, @helperModClassReadLabel);
rxValidLabels = readall(validLabels,"UseParallel",pctExists);
testFrames = transform(testDSTrans
```
0
0
复制全文
相关推荐









