%% Demodulate and Decode Time-Domain Bluetooth BR/EDR Waveform
% Demodulate and decode time-domain Bluetooth BR/EDR waveform using two different ways to get physical layer (PHY) information. The bluetoothIdealReceiver function uses bluetoothPhyConfig object or bluetoothWaveformConfig object to extract PHY information and decode the Bluetooth BR/EDR waveform.
%% Use the bluetoothPhyConfig object to get PHY information
% Create a Bluetooth BR/EDR waveform configuration object with default settings.

txconfig = bluetoothWaveformConfig;

% Create a random input bit vector to generate the payload. Generate the time-domain Bluetooth BR/EDR waveform using the payload.

dataBits = randi([0 1],getPayloadLength(txconfig)*8,1);
waveform = bluetoothWaveformGenerator(dataBits,txconfig);

% Create a configuration object for Bluetooth BR/EDR PHY with default settings. This object sends the PHY information to the ideal receiver.

rxConfig = bluetoothPhyConfig;

% Demodulate and decode the Bluetooth BR/EDR waveform. The generated output displays the decoded bits and a structure containing the decoded information.

[bits,decodedInfo] = bluetoothIdealReceiver(waveform,rxConfig)

%% Use the bluetoothWaveformConfig object to get PHY information
% Create a Bluetooth BR/EDR waveform configuration object with default settings. Set the packet type to 'DM1'and payload length to 10.

cfg = bluetoothWaveformConfig;
cfg.PacketType = 'DM1';
cfg.PayloadLength = 10;

% Create a random input bit vector to generate the payload.

numBits = getPayloadLength(cfg)*8;
dataBits = randi([0 1],numBits,1);

% Generate the time-domain Bluetooth BR/EDR waveform using the payload.

waveform = bluetoothWaveformGenerator(dataBits,cfg);

% Get PHY information from the bluetoothWaveformConfig object function, getPhyConfigProperties.

rxConfig = getPhyConfigProperties(cfg);

% Demodulate and decode the Bluetooth BR/EDR waveform. The generated output displays the decoded bits, a structure containing the decoded information, the packet status, and the decoded CRC.

[bits,decodedInfo,pktStatus,crc] = bluetoothIdealReceiver(waveform,rxConfig)

% Copyright 2019 The MathWorks, Inc.