Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Converting my python code to matlab

5 vues (au cours des 30 derniers jours)
Jimmy cho
Jimmy cho le 2 Nov 2020
Clôturé : John D'Errico le 3 Nov 2020
Hi guys.
I've implemented in python convolutional encoder K=7 , r =1/2 and I came from world of python / c++ and rarely I use matlab.
Im trying to convert that code that I've done in python to matlab, could anyone please help me? Im newbie in matlab and Im not using it, rarely I use matlab.
I appreciate your help in advance!! , the attached code down is convolutional encoder K=7 , r =1/2 in python:
import os, math
import collections
G1 = 0x79 # 171 octal
G2 = 0x5B # 131 octal
K = 7
UW = 0x1ACFFC1D
buff = collections.deque(maxlen=K)
def binary(num, length=8):
return format(num, '#0{}b'.format(length + 2))
# Fill the buffer with initial values
for i in range(0, K):
buff.append(0)
bitUW = []
binaryUW = binary(UW, 32)[2:]
for i in binaryUW:
bitUW.append(int(i))
bitG1 = []
bitG2 = []
binaryG1 = binary(G1, K)[2:]
binaryG2 = binary(G2, K)[2:]
for i in range(0, K):
bitG1.append(int(binaryG1[i]))
bitG2.append(int(binaryG2[i]))
convolved = []
def buffIsZero():
for i in range(0, K):
if buff[i] == 1:
return False
return True
for i in bitUW:
buff.appendleft(i)
b0 = 0
b1 = 0
for t in range(0, K):
b0 += bitG1[t] & buff[t]
b1 += bitG2[t] & buff[t]
b0 = b0 % 2
b1 = b1 % 2
b1 = 1 if b1 == 0 else 0
convolved.append(b0)
convolved.append(b1)
while True:
buff.appendleft(0)
if buffIsZero():
break
b0 = 0
b1 = 0
for t in range(0, K):
b0 += bitG1[t] & buff[t]
b1 += bitG2[t] & buff[t]
b0 = b0 % 2
b1 = b1 % 2
b1 = 1 if b1 == 0 else 0
convolved.append(b0)
convolved.append(b1)
#convolved = convolved[:len(convolved)-2]
print convolved
f = open("UW.bit", "w")
t = open("UW_normal.bit", "w")
for s in range(0, 64):
for i in bitUW:
if i == 1:
t.write(chr(0xFF))
t.write(chr(0xFF))
t.write(chr(0xFF))
else:
t.write(chr(0x00))
t.write(chr(0x00))
t.write(chr(0x00))
for i in convolved:
if i == 1:
f.write(chr(0xFF))
f.write(chr(0xFF))
f.write(chr(0xFF))
else:
f.write(chr(0x00))
f.write(chr(0x00))
f.write(chr(0x00))
f.close()
t.close()
  1 commentaire
Jimmy cho
Jimmy cho le 3 Nov 2020
Hi guys, any help please?!

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by