i think that this is nearly the beginning of task 1

This commit is contained in:
ti_mo
2026-06-03 19:46:31 +02:00
parent 4395bbe0b1
commit 78b271247c
7 changed files with 200 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
function numPacketErrors = simulateTransmission(cfgEHT, channel, snr, packets, maxNumErrors, simParameters, chanBW, substreamIndex)
numPacketErrors = 0;
ofdmInfo = wlanEHTOFDMInfo('EHT-Data', cfgEHT);
ind = wlanFieldIndices(cfgEHT);
if nargin < 8
substreamIndex = 1;
end
stream = RandStream('combRecursive', Seed=simParameters.Seed);
stream.Substream = substreamIndex;
RandStream.setGlobalStream(stream);
snrVal = convertSNR(snr, "snrsc", "snr", FFTLength=ofdmInfo.FFTLength, NumActiveSubcarriers=ofdmInfo.NumTones);
for packetIdx = 1:packets
if numPacketErrors >= maxNumErrors
break;
end
txPSDU = randi([0 1], psduLength(cfgEHT) * 8, 1);
tx = wlanWaveformGenerator(txPSDU, cfgEHT);
txPad = [tx; zeros(50, cfgEHT.NumTransmitAntennas)];
reset(channel);
rx = awgn(channel(txPad), snrVal);
coarsePacketOffset = wlanPacketDetect(rx, chanBW);
if isempty(coarsePacketOffset)
numPacketErrors = numPacketErrors + 1;
continue;
end
lstf = rx(coarsePacketOffset + (ind.LSTF(1) : ind.LSTF(2)), :);
coarseFrequencyOffset = wlanCoarseCFOEstimate(lstf, chanBW);
rx = frequencyOffset(rx, simParameters.SampleRate, -coarseFrequencyOffset);
nonhtfields = rx(coarsePacketOffset + (ind.LSTF(1) : ind.LSTF(2)), :);
finePacketOffset = wlanSymbolTimingEstimate(nonhtfields, chanBW);
packetOffset = coarsePacketOffset + finePacketOffset;
if packetOffset > 50
numPacketErrors = numPacketErrors + 1;
continue;
end
rxLLTF = rx(packetOffset + (ind.LLTF(1) : ind.LLTF(2)), :);
fineFrequencyOffset = wlanFineCFOEstimate(rxLLTF, chanBW);
rx = frequencyOffset(rx, simParameters.SampleRate, -fineFrequencyOffset);
rxHELTF = rx(packetOffset + (ind.EHTLTF(1) : ind.EHTLTF(2)), :);
heltfDemod = wlanEHTDemodulate(rxHELTF, "EHT-LTF", cfgEHT);
[chanEstimate, pilotEstimate] = wlanEHTLTFChannelEstimate(heltfDemod, cfgEHT);
rxData = rx(packetOffset + (ind.EHTData(1) : ind.EHTData(2)), :);
demodSym = wlanEHTDemodulate(rxData, "EHT-Data", cfgEHT);
nVarEst = wlanEHTDataNoiseEstimate(demodSym(ofdmInfo.PilotIndices, :, :),pilotEstimate, cfgEHT);
demodDataSym = demodSym(ofdmInfo.DataIndices, :, :);
chanEstimateData = chanEstimate(ofdmInfo.DataIndices, :, :);
[eqSym, csi] = wlanEHTEqualize(demodDataSym, chanEstimateData, nVarEst, cfgEHT, 'EHT-Data');
rxPSDU = wlanEHTDataBitRecover(eqSym, nVarEst, csi, cfgEHT);
numPacketErrors = numPacketErrors + any(biterr(txPSDU, rxPSDU));
end
end