Statistics
| Branch: | Tag: | Revision:

gnuradio / gr-digital / python / qpsk.py @ 73ccc57f

History | View | Annotate | Download (6.52 KB)

1
#
2
# Copyright 2005,2006,2011 Free Software Foundation, Inc.
3
# 
4
# This file is part of GNU Radio
5
# 
6
# GNU Radio is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3, or (at your option)
9
# any later version.
10
# 
11
# GNU Radio is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
# 
16
# You should have received a copy of the GNU General Public License
17
# along with GNU Radio; see the file COPYING.  If not, write to
18
# the Free Software Foundation, Inc., 51 Franklin Street,
19
# Boston, MA 02110-1301, USA.
20
# 
21

22
"""
23
QPSK modulation.
24

25
Demodulation is not included since the generic_mod_demod
26
"""
27

28
from gnuradio import gr
29
from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod
30
import digital_swig
31
import modulation_utils
32

33
# Default number of points in constellation.
34
_def_constellation_points = 4
35
# Whether gray coding is used.
36
_def_gray_coded = True
37

38
# /////////////////////////////////////////////////////////////////////////////
39
#                           QPSK constellation
40
# /////////////////////////////////////////////////////////////////////////////
41

42
def qpsk_constellation(m=_def_constellation_points): 
43
    if m != _def_constellation_points:
44
        raise ValueError("QPSK can only have 4 constellation points.")
45
    return digital_swig.constellation_qpsk()
46

47
# /////////////////////////////////////////////////////////////////////////////
48
#                           QPSK modulator
49
# /////////////////////////////////////////////////////////////////////////////
50

51
class qpsk_mod(generic_mod):
52

53
    def __init__(self, constellation_points=_def_constellation_points,
54
                 gray_coded=_def_gray_coded,
55
                 *args, **kwargs):
56

57
        """
58
        Hierarchical block for RRC-filtered QPSK modulation.
59

60
        The input is a byte stream (unsigned char) and the
61
        output is the complex modulated signal at baseband.
62

63
        See generic_mod block for list of parameters.
64
        """
65

66
        constellation_points = _def_constellation_points
67
        constellation = digital_swig.constellation_qpsk()
68
        if constellation_points != 4:
69
            raise ValueError("QPSK can only have 4 constellation points.")
70
        if not gray_coded:
71
            raise ValueError("This QPSK mod/demod works only for gray-coded constellations.")
72
        super(qpsk_mod, self).__init__(constellation=constellation,
73
                                       gray_coded=gray_coded, 
74
                                       *args, **kwargs)
75

76

77
# /////////////////////////////////////////////////////////////////////////////
78
#                           QPSK demodulator
79
#
80
# /////////////////////////////////////////////////////////////////////////////
81

82
class qpsk_demod(generic_demod):
83

84
    def __init__(self, constellation_points=_def_constellation_points,
85
                 *args, **kwargs):
86

87
        """
88
        Hierarchical block for RRC-filtered QPSK modulation.
89

90
        The input is a byte stream (unsigned char) and the
91
        output is the complex modulated signal at baseband.
92

93
        See generic_demod block for list of parameters.
94
        """
95

96
        constellation_points = _def_constellation_points
97
        constellation = digital_swig.constellation_qpsk()
98
        if constellation_points != 4:
99
            raise ValueError('Number of constellation points must be 4 for QPSK.')
100
        super(qpsk_demod, self).__init__(constellation=constellation,
101
                                         *args, **kwargs)
102

103

104

105
# /////////////////////////////////////////////////////////////////////////////
106
#                           DQPSK constellation
107
# /////////////////////////////////////////////////////////////////////////////
108

109
def dqpsk_constellation(m=_def_constellation_points):
110
    if m != _def_constellation_points:
111
        raise ValueError("DQPSK can only have 4 constellation points.")
112
    return digital_swig.constellation_dqpsk()
113

114
# /////////////////////////////////////////////////////////////////////////////
115
#                           DQPSK modulator
116
# /////////////////////////////////////////////////////////////////////////////
117

118
class dqpsk_mod(generic_mod):
119

120
    def __init__(self, constellation_points=_def_constellation_points,
121
                 gray_coded=_def_gray_coded,
122
                 differential=True, *args, **kwargs):
123
        """
124
        Hierarchical block for RRC-filtered DQPSK modulation.
125

126
        The input is a byte stream (unsigned char) and the
127
        output is the complex modulated signal at baseband.
128

129
        See generic_mod block for list of parameters.
130
        """
131

132
        constellation_points = _def_constellation_points
133
        constellation = digital_swig.constellation_dqpsk()
134
        if constellation_points != 4:
135
            raise ValueError('Number of constellation points must be 4 for DQPSK.')
136
        super(dqpsk_mod, self).__init__(constellation=constellation,
137
                                        gray_coded=gray_coded,
138
                                        differential=True,
139
                                        *args, **kwargs)
140

141
# /////////////////////////////////////////////////////////////////////////////
142
#                           DQPSK demodulator
143
#
144
# /////////////////////////////////////////////////////////////////////////////
145

146
class dqpsk_demod(generic_demod):
147

148
    def __init__(self, constellation_points=_def_constellation_points,
149
                 differential=True, *args, **kwargs):
150

151
        """
152
        Hierarchical block for RRC-filtered DQPSK modulation.
153

154
        The input is a byte stream (unsigned char) and the
155
        output is the complex modulated signal at baseband.
156

157
        See generic_demod block for list of parameters.
158
        """
159
        constellation_points = _def_constellation_points
160
        constellation = digital_swig.constellation_dqpsk()
161
        if constellation_points != 4:
162
            raise ValueError('Number of constellation points must be 4 for DQPSK.')
163
        super(dqpsk_demod, self).__init__(constellation=constellation,
164
                                          differential=True,
165
                                          *args, **kwargs)
166

167
#
168
# Add these to the mod/demod registry
169
#
170
modulation_utils.add_type_1_mod('qpsk', qpsk_mod)
171
modulation_utils.add_type_1_demod('qpsk', qpsk_demod)
172
modulation_utils.add_type_1_constellation('qpsk', qpsk_constellation)
173
modulation_utils.add_type_1_mod('dqpsk', dqpsk_mod)
174
modulation_utils.add_type_1_demod('dqpsk', dqpsk_demod)
175
modulation_utils.add_type_1_constellation('dqpsk', dqpsk_constellation)
176