3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
32 ######################################################################
33 # Decimal to any base conversion.
34 # Convert 'num' to a list of 'l' numbers representing 'num'
35 # to base 'base' (most significant symbol first).
36 ######################################################################
37 def dec2base(num,base,l):
44 print 'Number ', num, ' requires more than ', l, 'digits.'
48 ######################################################################
49 # Conversion from any base to decimal.
50 # Convert a list 's' of symbols to a decimal number
51 # (most significant symbol first)
52 ######################################################################
55 for i in range(len(s)):
63 ######################################################################
64 # Automatically generate the lookup table that maps the FSM outputs
65 # to channel inputs corresponding to a channel 'channel' and a modulation
66 # 'mod'. Optional normalization of channel to unit energy.
67 # This table is used by the 'metrics' block to translate
68 # channel outputs to metrics for use with the Viterbi algorithm.
69 # Limitations: currently supports only one-dimensional modulations.
70 ######################################################################
71 def make_isi_lookup(mod,channel,normalize):
73 constellation = mod[1]
77 for i in range(len(channel)):
79 for i in range(len(channel)):
80 channel[i] = channel[i]/math.sqrt(p)
82 lookup=range(len(constellation)**len(channel))
83 for o in range(len(constellation)**len(channel)):
84 ss=dec2base(o,len(constellation),len(channel))
86 for i in range(len(channel)):
87 ll=ll+constellation[ss[i]]*channel[i]
96 ######################################################################
97 # A list of common modulations.
98 # Format: (dimensionality,constellation)
99 ######################################################################
101 pam4 = (1,[-3, -1, 3, 1]) # includes Gray mapping
102 pam8 = (1,[-7, -5, -3, -1, 1, 3, 5, 7])
107 -1, 0]) # includes Gray mapping
108 psk8=(2,[math.cos(2*math.pi*0/8), math.sin(2*math.pi*0/8), \
109 math.cos(2*math.pi*1/8), math.sin(2*math.pi*1/8), \
110 math.cos(2*math.pi*2/8), math.sin(2*math.pi*2/8), \
111 math.cos(2*math.pi*3/8), math.sin(2*math.pi*3/8), \
112 math.cos(2*math.pi*4/8), math.sin(2*math.pi*4/8), \
113 math.cos(2*math.pi*5/8), math.sin(2*math.pi*5/8), \
114 math.cos(2*math.pi*6/8), math.sin(2*math.pi*6/8), \
115 math.cos(2*math.pi*7/8), math.sin(2*math.pi*7/8)])
119 orth4=(4,[1, 0, 0, 0, \
124 ######################################################################
125 # A list of channels to be tested
126 ######################################################################
128 # C test channel (J. Proakis, Digital Communications, McGraw-Hill Inc., 2001)
129 c_channel = [0.227, 0.460, 0.688, 0.460, 0.227]
140 if __name__ == '__main__':
141 make_fsm_bin_cc_ff (1,2,[[7,5]])
143 make_fsm_bin_cc_ff (2,3,[[1,0,2],[0,1,6]])