8888 elif i == 9 :
8989 print ("No Bit Errors :)" )
9090
91- # =============================================================================
92- # Complete example using commpy features. Example with code 1
93- # =============================================================================
91+ # ==================================================================================================
92+ # Complete example using Commpy features and compare hard and soft demodulation . Example with code 1
93+ # ==================================================================================================
9494
9595# Modem : QPSK
9696modem = mod .QAMModem (4 )
9797
9898# AWGN channel
99- channels = chan .SISOFlatChannel (None , (1 + 0j , 0j ))
99+ channels = chan .SISOFlatChannel (None , (1 + 0j , 0j ))
100100
101101# SNR range to test
102102SNRs = np .arange (0 , 6 ) + 10 * math .log10 (modem .num_bits_symbol )
@@ -107,31 +107,41 @@ def modulate(bits):
107107 return modem .modulate (cc .conv_encode (bits , trellis1 , 'cont' ))
108108
109109
110- # Demodulation function
111- def demode ( msg ):
112- return modem .demodulate (msg , 'hard' )
110+ # Receiver function (no process required as there are no fading)
111+ def receiver_hard ( y , h , constellation , noise_var ):
112+ return modem .demodulate (y , 'hard' )
113113
114114
115115# Receiver function (no process required as there are no fading)
116- def receiver (y , h , constellation , noise_var ):
117- return modem .demodulate (y , 'hard' )
116+ def receiver_soft (y , h , constellation , noise_var ):
117+ return modem .demodulate (y , 'soft' , noise_var )
118118
119119
120120# Decoder function
121- def decoder (msg ):
121+ def decoder_hard (msg ):
122122 return cc .viterbi_decode (msg , trellis1 )
123123
124124
125+ # Decoder function
126+ def decoder_soft (msg ):
127+ return cc .viterbi_decode (msg , trellis1 , decoding_type = 'soft' )
128+
129+
125130# Build model from parameters
126131code_rate = trellis1 .k / trellis1 .n
127- model = lk .LinkModel (modulate , channels , receiver ,
128- modem .num_bits_symbol , modem .constellation , modem .Es ,
129- decoder , code_rate )
132+ model_hard = lk .LinkModel (modulate , channels , receiver_hard ,
133+ modem .num_bits_symbol , modem .constellation , modem .Es ,
134+ decoder_hard , code_rate )
135+ model_soft = lk .LinkModel (modulate , channels , receiver_soft ,
136+ modem .num_bits_symbol , modem .constellation , modem .Es ,
137+ decoder_soft , code_rate )
130138
131139# Test
132- BERs = lk .link_performance (model , SNRs , 10000 , 600 , 5000 , code_rate )
133- plt .semilogy (SNRs , BERs , 'o-' )
140+ BERs_hard = model_hard .link_performance (SNRs , 10000 , 600 , 5000 , code_rate )
141+ BERs_soft = model_soft .link_performance (SNRs , 10000 , 600 , 5000 , code_rate )
142+ plt .semilogy (SNRs , BERs_hard , 'o-' , SNRs , BERs_soft , 'o-' )
134143plt .grid ()
135144plt .xlabel ('Signal to Noise Ration (dB)' )
136145plt .ylabel ('Bit Error Rate' )
146+ plt .legend (('Hard demodulation' , 'Soft demodulation' ))
137147plt .show ()
0 commit comments