-
Notifications
You must be signed in to change notification settings - Fork 1
/
Packet_enc_dec_3_GF16.m
99 lines (95 loc) · 3.27 KB
/
Packet_enc_dec_3_GF16.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
95
96
97
98
99
function [Packet_Block,Decoded_Packet,Packet_Error_3_GF16] = Packet_enc_dec_3(K, N, i3)
% Considering size of Native Packet blocks, K=5, L=6.
K = K; %no of packets per Block
C = N; %K + m
L = 6; %no of bytes, each byte with 8 bits.
PER = 0;
% Preallocating space.
Packet_Block = zeros(K,L);
Alpha = zeros(C,K); %Random Variable Matrix.
Packet = ones(L,4);
received_packet = zeros(C-1, L);
Random_Element_rec = zeros(C-1, K);
Received_Packet_N = zeros(C-2, L);
Random_Element_rec_N = zeros(C-2, K);
Coded_Packet = zeros(K,L);
%Decoded_Packet = zeros(K,L);
global Packet_Error_3_GF16;
fprintf('\n')
fprintf('Block_seq_no:- %d',i3)
fprintf('\n')
%--------------------------------
% Generating Data Packet Block
%--------------------------------
for y=1:1:K
for i=1:1:4 % Size of byte, i.e i number of bits.
for j=1:1:L
% Creating a Random Variable.
RN1 = randi([0.0,1.0],1,1);
if RN1<0.9;
Packet(j,i)=0;
else Packet(j,i) = Packet(j,i);
end
end
end
%Packet;
Decimal_Packet = bi2de(Packet);
Packet_Block(y,:) = Decimal_Packet;
% Reseting Packet
Packet = ones(L,4);
Decimal_Packet = bi2de(Packet);
end
Packet_Block = gf(Packet_Block, 4);
%-----------------------------------
% Generating Random Element Matrix.
%-----------------------------------
[Alpha] = Random_Coeff(C, K);
Random_Packet = Alpha;
% Generating Coded Packet by combining Source packet block and Random
% elements Matrix.
Coded_Packet = gf(Coded_Packet, 4);
Coded_Packet = Random_Packet*Packet_Block;
% Coded Packets are Transmitted by Sender.
%---------------------------------------------------------------------
%---------------------ERASURE CHANNEL---------------------------------
%---------------------------------------------------------------------
% Coded_Packets are Received by the Receiver.
%--------------------------------
% Creating ranndom losses.
%--------------------------------
% Considering Packet Erasure Rate(PER) as 0.2
% Introduce Transmission Losses by flipping a random Element Block.
%disp('Introduce Transmission Loss with Random Number RNN');
received_packet = [];
Received_Packet = gf(received_packet,4);
for iii1=1:1:C
PER = randi(10,1,1);
if PER < 2
if iii1 >= C
%-------SKIP------------------------------------
else
Received_Packet(iii1,:) = Coded_Packet(iii1+1,:);
Random_Element_rec(iii1,:) = Random_Packet(iii1+1,:);
C = C-1;
end
else
Received_Packet(iii1,:) = Coded_Packet(iii1,:);
Random_Element_rec(iii1,:) = Random_Packet(iii1,:);
end
PER = 0;
end
%--------------------------------
% Decoding the Packet Block
%--------------------------------
try
%for il = 1:1:C
%Decoded_Packet(il,:) = gflineq(Received_Packet(il,:),Random_Element_rec(i1,:))
Decoded_Packet = Random_Element_rec \ Received_Packet ;
Packet_Error_3_GF16 = isequal(Packet_Block, Decoded_Packet);
Packet_Error_3_GF16 = ~Packet_Error_3_GF16;
%end
catch
Decoded_Packet = 0;
Packet_Error_3_GF16 = isequal(Packet_Block, Decoded_Packet);
Packet_Error_3_GF16 = ~Packet_Error_3_GF16;
end