115 lines
4.2 KiB
Matlab
115 lines
4.2 KiB
Matlab
%% RX for labview
|
||
clc;
|
||
close all;
|
||
clear ;
|
||
%% 接收端输入测试数据
|
||
receiveAntennasNum = 1;
|
||
receiveBandwidth = 20e6;
|
||
syncAlgo = 'first';
|
||
chanEstiAlgo = 'first';
|
||
equalizeAlgo = 'first';
|
||
demodMode = 'first';
|
||
interpCodeAlgo = 'first';
|
||
|
||
%% 接收端输入端接口
|
||
rxInput.receiveAntennasNum = receiveAntennasNum; % 1 or 2
|
||
rxInput.receiveBandwidth = receiveBandwidth;% 10~20M
|
||
rxInput.syncAlgo = syncAlgo;% 接口,输入类型为string
|
||
rxInput.chanEstiAlgo = chanEstiAlgo;% 接口,输入类型为string
|
||
rxInput.equalizeAlgo = equalizeAlgo;% 接口,输入类型为string
|
||
rxInput.demodMode = demodMode;% 接口,输入类型为string
|
||
rxInput.interpCodeAlgo = interpCodeAlgo;% 接口,输入类型为string
|
||
|
||
|
||
%% 测试数据,发送端波形参数
|
||
userNum = 1;
|
||
fileType = 'text';
|
||
encryptMode = 'encryptMode';
|
||
antennasNum = 1;
|
||
centerFreq = 2450e6;
|
||
sendBandwidth = 5e6;
|
||
fftNum = 128;
|
||
CPratio = 0.25;
|
||
pilotInterval = 3;
|
||
% MCS_set=[2,2;4,2;4,4;16,2;16,4;64,3;64,4;64,6];% 加密算法需要做一个适配,CHB,3.19
|
||
MCS = [16,4];
|
||
subcarriersNum = 128; % 待适配
|
||
|
||
%% 接收端 计算发送端的一切状态
|
||
txInput.userNum = userNum; % 1 or 2
|
||
txInput.fileType = fileType; % 'text' or 'picture'
|
||
|
||
txInput.encryptMode = encryptMode; % 'encrypt' or 'not encrypt'
|
||
txInput.antennasNum = antennasNum; % 1 or 2
|
||
txInput.centerFreq = centerFreq; % 500MHz~2.4G
|
||
txInput.sendBandwidth = sendBandwidth; % 20~40MHz
|
||
txInput.fftNum = fftNum;% 128 or 256 or 512
|
||
txInput.CPratio = CPratio; % 0.25 or 0.125 or 0.0625
|
||
txInput.pilotInterval = pilotInterval; % 3 5 7
|
||
txInput.MCS = MCS; % a set [2,2;4,2;4,4;16,2;16,4;64,3;64,4;64,6]
|
||
txInput.subcarriersNum = subcarriersNum;% 52 or 106 or 242
|
||
|
||
PacketSize = 200;
|
||
NumerologySel = [txInput.fftNum,txInput.CPratio,txInput.pilotInterval];
|
||
MCS_no = txInput.MCS;
|
||
|
||
[SysParameters,WaveformPara] = WaveformNumerologyCal(PacketSize,NumerologySel,MCS_no);
|
||
|
||
seed_set = [1 2 3];
|
||
rng(seed_set(1),'twister');
|
||
dataPacketBits = randi([0 1],WaveformPara.Payload,1);
|
||
scrData = TX_CRC32_Scramble(dataPacketBits);
|
||
trellis = poly2trellis(7,[171 133]);
|
||
tx_encoded_bit = convenc(scrData,trellis,WaveformPara.puncpat);
|
||
tx_padded_bit = [tx_encoded_bit;zeros(WaveformPara.DataPadding,1)];
|
||
%---------------------------------------------
|
||
dataMod = qammod(tx_padded_bit,WaveformPara.Mod,'InputType','bit');
|
||
WaveformPara.Power_sym = mean(abs(dataMod).^2);
|
||
dataMod = reshape(dataMod,WaveformPara.UsedSubcarrier,[]);
|
||
|
||
%% 获取信道响应 %假设已知前一时刻的信号
|
||
% 生成信道响应
|
||
N_carriers = WaveformPara.N_FFT;
|
||
channel_response=sqrt(1/2)*(randn(1,N_carriers)+1i*randn(1,N_carriers));
|
||
N_windows = 8;
|
||
N_level = 10;
|
||
min_len_CP = 30;
|
||
CPset = Generate_CP(channel_response,N_windows,N_level,min_len_CP);
|
||
[serialOFDMsym,WaveformPara.pilot,myFrameLen] = tx_FFTSymbolGen_PilotBlockPN(dataMod,WaveformPara,CPset);
|
||
WaveformPara.Power_sig = mean(abs(serialOFDMsym).^2);
|
||
[WaveformPara.preamble,WaveformPara.c1,WaveformPara.c2] = ...
|
||
generatePreamble(WaveformPara,WaveformPara.Power_sig);
|
||
%% 输入数据,接收端
|
||
|
||
load('rxdata5normalized.mat')
|
||
|
||
% rxSignal = rxSignal(5382:8680)';
|
||
% rxSignal = downsample(rxSignal, 2)';%data1 part
|
||
|
||
% rxSignal = rxSignal(5128:7889)';%data2 part
|
||
|
||
rxSignal = rxSignal(8500:10500)';
|
||
|
||
[rxSignal_sync,SyncErr] = rxSyncSC(rxSignal,WaveformPara,myFrameLen);
|
||
[rxDataModLs] = rx_PilotBlockChanEstForLabview(rxSignal_sync,WaveformPara,CPset); % 去CP的地方
|
||
dataDemod = qamdemod(rxDataModLs,WaveformPara.Mod,'OutputType','approxllr', ...
|
||
'UnitAveragePower',false,'NoiseVariance',0.0243);%ChanPara.N0
|
||
dataDePadded = dataDemod(1:end - WaveformPara.DataPadding);
|
||
tb = 8;
|
||
decoded = vitdec(dataDePadded,trellis,tb,'trunc','unquant',WaveformPara.puncpat);
|
||
|
||
[rxBits,PER] = RX_CRC32_deScramble(decoded);% 丢包率
|
||
[numErrors,BER] = biterr(dataPacketBits,rxBits);
|
||
|
||
%% 接收端输出接口
|
||
rxOutput.delaySpread = 0; % 接口,输出类型为double
|
||
rxOutput.SNR = 0;% 接口,输出类型为double
|
||
rxOutput.RSSI = 0;% 接口,输出类型为double
|
||
rxOutput.BER = BER;% 输出类型为double
|
||
rxOutput.PER = PER;% 输出类型为double
|
||
rxOutput.EVM = 0;% 接口,输出类型为double
|
||
rxOutput.phaseNoise = 0;% 接口,输出类型为double
|
||
|
||
BER
|
||
PER
|
||
SyncErr |