function sdrTransmitter = rfFingerprintingUnknownClassDataCollectionTx
%rfFingerprintingUnknownClassDataCollectionTx RF fingerprinting unknown class transmitter
%   TX = rfFingerprintingUnknownClassDataCollectionTx configures a PlutoSDR
%   to continuously transmit a Non-HT WLAN format preamble and returns the
%   transmitting radio object, TX. Use this function to generate the data
%   corresponding to the Unknown class in the "Test a Deep Neural Network
%   with Captured Data to Detect WLAN Router Impersonation" example.
%
%   First, run this function to start the transmitter. Then, run
%   rfFingerprintingUnknownClassDataCollectionRx preferably on a laptop so
%   that you can move the receiver to different locations to create
%   independent channels. Once you are done collecting the data, call
%   release(TX).
%
%   See also rfFingerprintingUnknownClassDataCollectionrx,
%   rfFingerprintingRouterDataCollection and
%   DesignRFFingerprintingDeepLearningNetworkExample

%   Copyright 2019 The MathWorks, Inc.

% Create Beacon frame-body configuration object
frameBodyConfig = wlanMACManagementConfig;
 
% Create Beacon frame configuration object
beaconFrameConfig = wlanMACFrameConfig('FrameType', 'Beacon');
beaconFrameConfig.ManagementConfig = frameBodyConfig;

% Set random MAC address
beaconFrameConfig.Address2 = "DEE71EA52156";

% Generate Beacon frame bits
[beacon, mpduLength] = wlanMACFrame(beaconFrameConfig, 'OutputFormat', 'bits');

nonHTcfg = wlanNonHTConfig(...
    'ChannelBandwidth', 'CBW20',...
    "MCS", 1,...
    "PSDULength", mpduLength);

fs = wlanSampleRate(nonHTcfg);

% Add zeros to account for channel and filter delays
txSig = [wlanWaveformGenerator(beacon, nonHTcfg); zeros(160,1)];

% Transmit WLAN preamble using PlutoSDR
if helperIsPlutoSDRInstalled
    radios = findPlutoRadio();
    if ~isempty(radios)
        % Set ADALM-PLUTO as a transmitter
        deviceNameSDR = 'Pluto'; % Set SDR Device
        osf=2;
        sdrTransmitter = sdrtx(deviceNameSDR);
        sdrTransmitter.RadioID = 'usb:0';
        sdrTransmitter.BasebandSampleRate = fs*osf; 
        sdrTransmitter.CenterFrequency = helperWLANChannelFrequency(153, 5);
        sdrTransmitter.ShowAdvancedProperties = true;
        sdrTransmitter.Gain = 0;

        % Resample transmitted Waveform
        txSig  = resample(txSig,osf,1);

        % Set PlutoSDR to transmit
        transmitRepeat(sdrTransmitter, txSig);
        disp(message('comm_demos:rfFingerprinting:DataCollectionInstructions1').getString)
        disp(message('comm_demos:rfFingerprinting:DataCollectionInstructions2').getString)
    else
        error(message("comm_demos:common:RadioNeeded", 1, "ADALM-PLUTO"));
    end
else
    error(message("comm_demos:common:CSTSupportPKGNotFound", ...
      "Analog Devices ADALM-PLUTO Radio"));
end
end
