-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode.m
More file actions
63 lines (47 loc) · 1.48 KB
/
Copy pathencode.m
File metadata and controls
63 lines (47 loc) · 1.48 KB
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
function res = encode(dw)
% function to encode input bit with the generating functions
% number of bits taken for calculating the codeword
k = 7;
% generating functions (last bit assumed to be 0)
g1 = [1 1 0 1 0 1 0];
g2 = [1 1 1 0 1 1 0];
% shift register with input bit initial states
shiftreg = [0 0 0 0 0 0 0];
% iterator for codeword
j=1;
% travelling through the dataword
for i = dw
% taking the input from dataword
shiftreg(2:end) = shiftreg(1:end-1);
shiftreg(1)=i;
% loop for calculating the shiftreg * generating function
for iter = 1:7
w1(iter) = shiftreg(iter)*g1(iter);
w2(iter) = shiftreg(iter)*g2(iter);
end
% calculating XOR of the elements after multiplying shiftreg and generating function
temp1 =mod(sum(w1),2);
temp2 =mod(sum(w2),2);
% storing the codeword generated
res(j)=temp1;
res(j+1)=temp2;
j=j+2;
end
% this loop is for flushing the shift registers
for i = [0 0 0 0 0 0]
% taking input from a empty vector
shiftreg(2:end) = shiftreg(1:end-1);
shiftreg(1)=i;
% loop for calculating the shiftreg * generating function
for iter = 1:7
w1(iter) = shiftreg(iter)*g1(iter);
w2(iter) = shiftreg(iter)*g2(iter);
end
% calculating XOR of the elements after multiplying shiftreg and generating function
temp1 =mod(sum(w1),2);
temp2 =mod(sum(w2),2);
res(j)=temp1;
% storing the codeword generated
res(j+1)=temp2;
j=j+2;
end