forked from bb16177/OTFS-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataGen.m
94 lines (82 loc) · 4.39 KB
/
dataGen.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [dataIn, dataBits_in, codedData_in, packetSize, numPackets, numCB] = dataGen(k,numDC,ofdmSym,totalBits,codeRate, ldpcEncoder)
%--------------------------------------------------------------------------
%
% Generates and encodes random binary data
%
%--------------------------------------------------------------------------
% Input arguments:
%
% k Bits/Symbol
% numDC Number of data subcarriers
% ofdmSym Totol ofdm symbols per subframe
% totalBits The approximate total bits to be simulated by the system
% codeRate LDPC code rate
% ldpcEncoder LDPC encode system object
%
%--------------------------------------------------------------------------
% Function returns:
%
% dataIn The input encoded data to the modulator
% dataBits_in The binary generated initial data before coding
% codedData_in The binary codewords
% packetSize No. of subframes / "packet"
% numPackets Number of packets required to satisfy totalBits
% numCB No. of code blocks / "subframe"
%
%--------------------------------------------------------------------------
%
% Author: Bradley Bates
% University of Bristol, UK
% email address: [email protected]
% May 2020
%
% Copyright (c) 2020, Bradley Bates
%
%--------------------------------------------------------------------------
% Calculate subframe size
% Initialise information about frames to be transmitted
packetSize = 1; % No. of subframes / "packet"
numCB = 1; % No. of code blocks / "subframe"
noCodedbits = 64800; % Codeword length
% Calculate exact no. of frames and bits required for simulation
subframeSize = [k*numDC*ofdmSym 1]; % Calculate size of a subframe
maxSubframes = ceil(totalBits./subframeSize(1)); % Total no. of subframes to be transmitted
% Determine number of code block and number of subframes/packet
if subframeSize(1) == noCodedbits % If same size do nothing
numCB = 1;
packetSize = 1;
elseif subframeSize(1) > noCodedbits % Match for when subframe > codeword
[numCB, packetSize] = rat(subframeSize(1)./ noCodedbits,1e-1);
elseif subframeSize(1) < noCodedbits % Match for when subframe < codeword
[packetSize, numCB] = rat(noCodedbits./ subframeSize(1),1e-1);
end
% Ensure theres always enough data bit capacity
while numCB*noCodedbits >= subframeSize(1)*packetSize
packetSize = packetSize + 1;
% Divide both by 2 if possible
if (rem(numCB,2) == 0) && (rem(packetSize,2) == 0) && numCB*noCodedbits <= subframeSize(1)*packetSize
packetSize = packetSize./2;
numCB = numCB./2;
end
end
% Calculate the pad bits required to round up to the nearest whole subframe
padBits = zeros((subframeSize(1)*packetSize - numCB*noCodedbits),1);% Calculate the number of pad bits
numPackets = round(maxSubframes./packetSize); % Total no. of "packets" to be transmitted
numPackets(~numPackets)=1; % If 0 packets set to 1
% Generate Random Input Data
range shuffle; % Shuffle random no. generator
codedData_in = []; % Initialse arrays
dataBits_in = [];
for q = 1:numCB
dataBits = randi([0,1],[noCodedbits*codeRate,1]); % Generate binary datafor each frame of the burst
dataBits_in = [dataBits_in;dataBits]; % Concatenate binary data
codedData_in = [codedData_in; ldpcEncoder(dataBits)]; % Generate LDPC codeblocks
end
paddedData_in = [codedData_in; padBits]; % Append pad bits to coded bits
dataIn = randintrlv(paddedData_in,4831); % Interleave paddedData randdeintrlv
% Print info about data output
% fprintf(['\n',num2str(numCB),' code block(s)\n', num2str(packetSize), ' subframes/packet \n'])
% fprintf([ num2str(numel(padBits)),' pad bits out of ', num2str((subframeSize(1)*packetSize)),' data bits = ', num2str(100*(numel(padBits)/(subframeSize(1)*packetSize))),' percent pad bits!\n'])
% fprintf(['Total packets: ', num2str(numPackets),'\n'])
% fprintf(['Total bits: ', num2str(numPackets*packetSize*(subframeSize(1))),'\n'])
end