-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal_part.py
42 lines (27 loc) · 995 Bytes
/
final_part.py
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
#!/usr/bin/python
import huffman_coding
import convolutional_encoder
import viterbi_decoder
import scipy.io
import noise
def convert_mat_to_dictionary(size, mat):
frequency = {}
for i in range(size):
frequency[chr(i+97)] = mat[i][0]
return frequency
def main():
freq = scipy.io.loadmat('freq.mat')['freq']
frequency = convert_mat_to_dictionary(26, freq)
huffman = huffman_coding.HuffmanCoding(frequency)
output_of_huffman_coding = huffman.encode('setareaskari')
c = convolutional_encoder.ConvolutionalEncoder(output_of_huffman_coding)
output_of_convolutional_encoder = c.encode()
#### noise
out_noise = noise.noise(list(output_of_convolutional_encoder))
vd = viterbi_decoder.ViterbiDecoder()
str1 = ''.join(out_noise)
output_of_viterbi_decoder = vd.decode(str1)
output_of_huffman_decoder = huffman.decode_text(output_of_viterbi_decoder)
print(output_of_huffman_decoder)
if __name__ == "__main__":
main()