Azzera filtri
Azzera filtri

End to End Bluetooth and WLAN simulation

7 visualizzazioni (ultimi 30 giorni)
Nirmani Hewa Ranchagoda
Nirmani Hewa Ranchagoda il 10 Feb 2021
Risposto: Vamsi Manthini il 22 Mag 2024
I am trying to generate spectrograms of coexisting Bluetooth and WLAN packets. Task required to have multiple transmitters, one receiver, path loss and AWGN noise. MATLAB offers some related examples,
However, they both cannot be directly used for the required purpose due to two reasons.
  1. The first example considers continuous WLAN interference where as I need random WLAN packets (spreaded across the spectrogram)
  2. The second example provides only one bluetooth packet, where as I need multiple packets spreaded across the spectrogram
I tried adopting components from both examples to do what I need, however I face below problems
  1. nextHop funtion in MATLAB gives the channel index for next hop and it is used as an input to the bleWaveformGenerator function. However the output from bleWaveformGenerator does not contain the required carrier (center) frequency. All the packets are centered around 0 Hz.
The main file is copied below. This will need multiple support files from MATLAB-->examples-->bluetooth--->main
% Trying to spread bluetooth packets across the spectrogram and then add
% WLAN packets
commSupportPackageCheck('BLUETOOTH');
pathLossModel = 'Free space'; % Path loss model
rxSensitivity = -70 ; % Receiver sensitivity in dBm
txPower = 0; % Transmit power in dBm
txAntennaGain = 0; % Transmitter antenna gain in dB
rxAntennaGain = 0; % Receiver antenna gain in dB
linkMargin = 15; % Link margin(dB) assumed in the simulation
channelIndex=0;
samplesPerSymbol = 88;
symbolRate = 1e6;
sampleRate = symbolRate*samplesPerSymbol;
% samplesPerSymbol = 8; % Samples per symbol
dataLen = 254; % Data length in bytes
phyMode = 'LE1M'; % PHY transmission mode
% Default access address for periodic advertising channels
accessAdd = [0 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 1]';
slotValue = 1*2;%phyTx.slotsRequired(packetType)
inputClock = 0;
clockTicks = slotValue*2;
numSlots=20;
numMasterTxSlots = floor(numSlots/slotValue);
hopIndex = zeros(1, numMasterTxSlots);
% Index to hop index vector
hopIdx = 1;
fh = bluetoothFrequencyHop;
fh.SequenceType = 'Connection basic';
scope2 = dsp.SpectrumAnalyzer(...
'ViewType','spectrogram', ...
'SpectrumType','Power density', ...
'TimeResolutionSource','Property', ...
'TimeResolution',0.0005, ...
'SampleRate',sampleRate, ...
'TimeSpanSource','Property', ...
'TimeSpan', 0.05, ...
'FrequencyResolutionMethod', 'WindowLength', ...
'WindowLength', 512, ...
'AxesLayout', 'Horizontal',...
'FrequencyOffset',(2402+channelIndex)*1e6);
sprev = rng('default'); % Set random number generator seed
rx=[];
for slotIdx = 0:slotValue:numSlots-slotValue
% % Update clock
inputClock = inputClock + clockTicks
% Frequency hopping
[channelIndex,~] = nextHop(fh,inputClock);
channelIndex=round(channelIndex/2)
txBits = randi([0 1],dataLen*8,1,'int8');
fc = (2*channelIndex+2402)*1e6; % Center frequency in Hz
txWaveform = bleWaveformGenerator(txBits,'Mode',phyMode,...
'SamplesPerSymbol',samplesPerSymbol,...
'ChannelIndex',channelIndex,...
'AccessAddress',accessAdd);
NF = 6; % Noise figure (dB)
T = 290; % Ambient temperature (K)
dBm2dBFactor = 30; % Factor for converting dBm to dB
% Symbol rate based on the PHY transmission mode
symbolRate = 1e6;
if strcmp(phyMode,'LE2M')
symbolRate = 2e6;
end
BW = samplesPerSymbol*symbolRate; % Bandwidth (Hz)
k = 1.3806e-23; % Boltzmann constant (J/K)
noiseFloor = 10*log10(k*T*BW)+NF; % Nosie floor in dB
% Measure signal power at the receiver based on the receiver sensitivity and
% assumed link margin
measuredPowerVector = rxSensitivity - dBm2dBFactor+linkMargin;
snrdB = measuredPowerVector - noiseFloor; % SNR in dB
% Create and configure the System objects for impairments
initImp = helperBLEImpairmentsInit(phyMode,samplesPerSymbol);
% Configure RF impairments
initImp.pfo.FrequencyOffset = 5800; % Frequency offset in Hz
initImp.pfo.PhaseOffset = 5; % Phase offset in degrees
initoff = 0.15*samplesPerSymbol; % Static timing offset
stepsize = 20*1e-6; % Timing drift in ppm, Max range is +/- 50 ppm
initImp.vdelay = (initoff:stepsize:initoff+stepsize*(length(txWaveform)-1))';
initImp.dc = 20; % Percentage related to maximum amplitude value
% Pass generated BLE waveform through RF impairments
txImpairedWfm = helperBLEImpairmentsAddition(txWaveform,initImp);
% Obtain the path loss value in dB
pldB = txPower-dBm2dBFactor+rxAntennaGain+txAntennaGain-measuredPowerVector;
plLinear = 10^(pldB/20); % Convert from dB to linear scale
% Attenuate BLE waveform
attenWaveform = txImpairedWfm./plLinear;
% Add WGN to the attenuated BLE waveform
rxWaveform = awgn(attenWaveform,snrdB,'measured');
% Create and configure the receiver System objects
initRxParams = helperBLEReceiverInit(phyMode,samplesPerSymbol,accessAdd);
% Recover data bits using practical receiver
[rxBits,accessAddress] = helperBLEPracticalReceiver(rxWaveform,initRxParams,channelIndex);
% Obtain BER by comparing the transmitted and recovered bits
ber = [];
if(length(txBits) == length(rxBits))
ber = (sum(xor(txBits,rxBits))/length(txBits));
end
% Estimate the distance between the transmitter and the receiver based on the path loss value and the environment
if any(strcmp(pathLossModel,{'Free space','Log distance','Log normal shadowing'}))
% Center frequency is required only for these path loss models
distance = helperBluetoothEstimateDistance(pathLossModel,pldB,fc);
else
distance = helperBluetoothEstimateDistance(pathLossModel,pldB);
end
hopIndex(hopIdx) = channelIndex;
hopIdx = hopIdx + 1;
scope2(rxWaveform);
pause(0.01);%original 0.01
end

Risposte (1)

Vamsi Manthini
Vamsi Manthini il 22 Mag 2024
Hello,
“The first example considers continuous WLAN interference, whereas I need random WLAN packets spread across the spectrogram. The second example provides only one Bluetooth packet, whereas I need multiple packets spread across the spectrogram.”
“nextHop funtion in MATLAB gives the channel index for next hop and it is used as an input to the bleWaveformGenerator function. However the output from bleWaveformGenerator does not contain the required carrier (center) frequency. All the packets are centered around 0 Hz
  • The output channel index from the nextHop function is used for Bluetooth BR/EDR waveforms, not for Bluetooth LE waveforms. To generate a Bluetooth BR/EDR signal using the generated channel index of nextHop function, use bluetoothWaveformGenerator instead of bleWaveformGenerator. Please try this in your script for the desired results.
Thank you,
Vamsi M

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by