function [txgrid, bitsIn] = generateOFDMGrid(genb, info, QAMModulation, TotSubframes)
%% Empty OFDM symbol
txgrid   = zeros(genb.NDLRB*12, info.SlotsPerSubframe*info.SymbolsPerSlot*TotSubframes,genb.CellRefP);
nSymbols = numel(txgrid);

%% Validate the Grid
validateGrid(txgrid, genb, info);

switch QAMModulation
    case 'QPSK'
        bitsPerSubCarrier = 2;
    case '16QAM'
        bitsPerSubCarrier = 4;
    case '64QAM'
        bitsPerSubCarrier = 6;
    case '256QAM'
        bitsPerSubCarrier = 8;
end
% Generate random bits
nBits   = bitsPerSubCarrier*nSymbols; % The multiple is 4 for 16QAM, 6, for 64 QAM ...
bitsIn  = randi([0,1],1,nBits);
symbols = lteSymbolModulate(bitsIn, QAMModulation);

txgrid = reshape(symbols, size(txgrid));
end

function validateGrid(txgrid, genb, info)
Nfft            = info.Nfft;
NDLRB           = genb.NDLRB;
SymbolsPerSlot  = info.SymbolsPerSlot;
SlotsPerSubframe= info.SlotsPerSubframe;
nSC             = NDLRB * 12;
if (~any(size(txgrid,1)==[0 nSC Nfft]))
    error('The input resource grid must contain a whole number of resource blocks i.e. number of rows must be an integer multiple of 12.');
end

% Validate number of OFDM symbols in the input
if (mod(size(txgrid,2),SymbolsPerSlot*SlotsPerSubframe)~=0)
    error('The input resource grid must contain a whole number of subframes i.e. number of columns must be an integer multiple of %d symbols per subframe (dependent on CP and subcarrier spacing).',SymbolsPerSlot*2);
end

end
