Skip to content

Commit 97003c0

Browse files
authored
Merge pull request #92 (Fix #90 & Fix #89)
Fix README code example for channelcoding
2 parents 1d2fe18 + 1fc1334 commit 97003c0

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

commpy/channelcoding/README.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ The [following](https://en.wikipedia.org/wiki/File:Conv_code_177_133.png) convol
7878
Convolutional encoder parameters:
7979

8080
```python
81+
generator_matrix = np.array([[5, 7]]) # generator branches
82+
trellis = cc.Trellis(np.array([M]), generator_matrix) # Trellis structure
83+
8184
rate = 1/2 # code rate
8285
L = 7 # constraint length
8386
m = np.array([L-1]) # number of delay elements
84-
generator_matrix = np.array([[0o171, 0o133]]) # generator branches
85-
trellis = cc.Trellis(M, generator_matrix) # Trellis structure
8687
```
8788

8889
Viterbi decoder parameters:
@@ -106,9 +107,9 @@ noiseVar = 10**(-snrdB/10) # noise variance (power)
106107

107108
N_c = 10 # number of trials
108109

109-
BER_soft = np.empty((N_c,))
110-
BER_hard = np.empty((N_c,))
111-
BER_uncoded = np.empty((N_c,))
110+
BER_soft = np.zeros(N_c)
111+
BER_hard = np.zeros(N_c)
112+
BER_uncoded = np.zeros(N_c)
112113

113114
for cntr in range(N_c):
114115

@@ -136,31 +137,30 @@ for cntr in range(N_c):
136137
decoded_soft = cc.viterbi_decode(demodulated_soft, trellis, tb_depth, decoding_type='unquantized') # decoding (soft decision)
137138
decoded_hard = cc.viterbi_decode(demodulated_hard, trellis, tb_depth, decoding_type='hard') # decoding (hard decision)
138139

140+
NumErr, BER_soft[cntr] = BER_calc(message_bits, decoded_soft[:message_bits.size]) # bit-error ratio (soft decision)
141+
NumErr, BER_hard[cntr] = BER_calc(message_bits, decoded_hard[:message_bits.size]) # bit-error ratio (hard decision)
142+
NumErr, BER_uncoded[cntr] = BER_calc(message_bits, demodulated_uncoded[:message_bits.size]) # bit-error ratio (uncoded case)
139143

140-
NumErr, BER_soft[cntr] = BER_calc(message_bits, decoded_soft[:-(L-1)]) # bit-error ratio (soft decision)
141-
NumErr, BER_hard[cntr] = BER_calc(message_bits, decoded_hard[:-(L-1)]) # bit-error ratio (hard decision)
142-
NumErr, BER_uncoded[cntr] = BER_calc(message_bits, demodulated_uncoded) # bit-error ratio (uncoded case)
143-
144-
mean_BER_soft = np.mean(BER_soft) # averaged bit-error ratio (soft decision)
145-
mean_BER_hard = np.mean(BER_hard) # averaged bit-error ratio (hard decision)
146-
mean_BER_uncoded = np.mean(BER_uncoded) # averaged bit-error ratio (uncoded case)
144+
mean_BER_soft = BER_soft.mean() # averaged bit-error ratio (soft decision)
145+
mean_BER_hard = BER_hard.mean() # averaged bit-error ratio (hard decision)
146+
mean_BER_uncoded = BER_uncoded.mean() # averaged bit-error ratio (uncoded case)
147147

148-
print("Soft decision:\n"+str(mean_BER_soft)+"\n")
149-
print("Hard decision:\n"+str(mean_BER_hard)+"\n")
150-
print("Uncoded message:\n"+str(mean_BER_uncoded)+"\n")
148+
print("Soft decision:\n{}\n".format(mean_BER_soft))
149+
print("Hard decision:\n{}\n".format(mean_BER_hard))
150+
print("Uncoded message:\n{}\n".format(mean_BER_uncoded))
151151
```
152152

153153
Outputs:
154154

155155
```python
156-
>>> Soft decision:
157-
>>> 0.0
158-
>>>
159-
>>> Hard decision:
160-
>>> 3.0000000000000004e-05
161-
>>>
162-
>>> Uncoded message:
163-
>>> 0.008782
156+
Soft decision:
157+
2.8000000000000003e-05
158+
159+
Hard decision:
160+
0.0007809999999999999
161+
162+
Uncoded message:
163+
0.009064
164164
```
165165

166166
### Reference

0 commit comments

Comments
 (0)