def __init__(self, constellation, differential, rotation): if constellation.arity() > 256: # If this becomes limiting some of the blocks should be generalised so # that they can work with shorts and ints as well as chars. raise ValueError("Constellation cannot contain more than 256 points.") gr.hier_block2.__init__(self, "mod_demod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature arity = constellation.arity() # TX self.constellation = constellation self.differential = differential import weakref self.blocks = [weakref.proxy(self)] # We expect a stream of unpacked bits. # First step is to pack them. self.blocks.append( gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)) # Second step we unpack them such that we have k bits in each byte where # each constellation symbol hold k bits. self.blocks.append( gr.packed_to_unpacked_bb(self.constellation.bits_per_symbol(), gr.GR_MSB_FIRST)) # Apply any pre-differential coding # Gray-coding is done here if we're also using differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(gr.map_bb(self.constellation.pre_diff_code())) # Differential encoding. if self.differential: self.blocks.append(gr.diff_encoder_bb(arity)) # Convert to constellation symbols. self.blocks.append(gr.chunks_to_symbols_bc(self.constellation.points(), self.constellation.dimensionality())) # CHANNEL # Channel just consists of a rotation to check differential coding. if rotation is not None: self.blocks.append(gr.multiply_const_cc(rotation)) # RX # Convert the constellation symbols back to binary values. self.blocks.append(digital_swig.constellation_decoder_cb(self.constellation.base())) # Differential decoding. if self.differential: self.blocks.append(gr.diff_decoder_bb(arity)) # Decode any pre-differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(gr.map_bb( mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits self.blocks.append(gr.unpack_k_bits_bb( self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) self.blocks = self.blocks[:check_index] self.blocks.append(weakref.proxy(self)) self.connect(*self.blocks)
def __init__(self, sps, # Samples per symbol excess_bw, # RRC filter excess bandwidth (typically 0.35-0.5) amplitude, # DAC output level, 0-32767, typically 2000-8000 vector_source, # Indicate if it's the infinite sequence of 1, or by use the code to change the amplitude ): gr.hier_block2.__init__(self, "bpsk_modulator", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # Create BERT data bit stream self.vector_source = vector_source self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit scrambler # Map to constellation self._constellation = [-1+0j, 1+0j] self._mapper = gr.chunks_to_symbols_bc(self._constellation) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(sps, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps self._rrc = gr.interp_fir_filter_ccf(sps, # Interpolation rate taps) # FIR taps self.amp = gr.multiply_const_cc(amplitude) # Wire block inputs and outputs self.connect(self.vector_source, self._scrambler, self._mapper, self._rrc, self.amp, self)
def __init__(self, sps, # Samples per symbol excess_bw, # RRC filter excess bandwidth (typically 0.35-0.5) amplitude # DAC output level, 0-32767, typically 2000-8000 ): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # Create BERT data bit stream self._bits = gr.vector_source_b([1,], True) # Infinite stream of ones self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit scrambler # Map to constellation self._constellation = [-1+0j, 1+0j] self._mapper = gr.chunks_to_symbols_bc(self._constellation) # Create RRC with specified excess bandwidth taps = gr.firdes.root_raised_cosine(sps*amplitude, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps self._rrc = gr.interp_fir_filter_ccf(sps, # Interpolation rate taps) # FIR taps # Wire block inputs and outputs self.connect(self._bits, self._scrambler, self._mapper, self._rrc, self)
def key_factory(index): print "FACTORY CALLED index = %d"%(index); r = es.es_pyhandler(); excess_bw = 0.5; sps = 4; amplitude = sig_amp; taps = gr.firdes.root_raised_cosine(sps*amplitude, # Gain sps, # Sampling rate 1.0, # Symbol rate excess_bw, # Roll-off factor 11*sps) # Number of taps blocks = {}; blocks["src"] = es.vector_source([1]) blocks["scrambler"] = gr.scrambler_bb(0x8A, 0x7F, 7); blocks["mapper"] = gr.chunks_to_symbols_bc( [-1+0j, 0+1j, 1+0j, 0-1j] ); blocks["rrc"] = gr.interp_fir_filter_ccf(sps, taps); r.sink = es.vector_sink([gr.sizeof_gr_complex]); r.set_pyb2(blocks); tb = gr.top_block(); tb.connect( blocks["src"], blocks["scrambler"], blocks["mapper"], blocks["rrc"], r.sink ); r.tb = tb.to_top_block(); return r;
def __init__(self, sample_rate, symbol_rate): gr.hier_block2.__init__( self, "dvb_s_modulator_bc", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature samples_per_symbol = sample_rate / symbol_rate if samples_per_symbol < 2: raise TypeError, "Samples per symbol must be >= 2" # Form symbols with 2 bits per symbol self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self.reunpack = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST) self.mapper = gr.chunks_to_symbols_bc(mod_constellation) # Design FIR filter taps for square root raised cosine filter ntaps = 11 * int(samples_per_symbol * nfilts) rrc_taps = gr.firdes.root_raised_cosine(nfilts, nfilts, 1.0, dvb_swig.RRC_ROLLOFF_FACTOR, ntaps) # Baseband pulse shaping filter self.rrc_filter = gr.pfb_arb_resampler_ccf(samples_per_symbol, rrc_taps) self.connect(self, self.pack, self.reunpack, self.mapper, self.rrc_filter, self)
def __init__(self, constellation, differential, rotation): if constellation.arity() > 256: # If this becomes limiting some of the blocks should be generalised so # that they can work with shorts and ints as well as chars. raise ValueError("Constellation cannot contain more than 256 points.") gr.hier_block2.__init__(self, "mod_demod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature arity = constellation.arity() # TX self.constellation = constellation self.differential = differential self.blocks = [self] # We expect a stream of unpacked bits. # First step is to pack them. self.blocks.append( gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)) # Second step we unpack them such that we have k bits in each byte where # each constellation symbol hold k bits. self.blocks.append( gr.packed_to_unpacked_bb(self.constellation.bits_per_symbol(), gr.GR_MSB_FIRST)) # Apply any pre-differential coding # Gray-coding is done here if we're also using differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(gr.map_bb(self.constellation.pre_diff_code())) # Differential encoding. if self.differential: self.blocks.append(gr.diff_encoder_bb(arity)) # Convert to constellation symbols. self.blocks.append(gr.chunks_to_symbols_bc(self.constellation.points(), self.constellation.dimensionality())) # CHANNEL # Channel just consists of a rotation to check differential coding. if rotation is not None: self.blocks.append(gr.multiply_const_cc(rotation)) # RX # Convert the constellation symbols back to binary values. self.blocks.append(digital_swig.constellation_decoder_cb(self.constellation.base())) # Differential decoding. if self.differential: self.blocks.append(gr.diff_decoder_bb(arity)) # Decode any pre-differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(gr.map_bb( mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits self.blocks.append(gr.unpack_k_bits_bb( self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) self.blocks = self.blocks[:check_index] self.blocks.append(self) self.connect(*self.blocks)
def mod_bits_qpsk(strbits, syms=[0, 1, 3, 2], pts=[-1, 1j, 1, -1j]): src = gr.vector_source_b(es.string_to_vector(strbits)) unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) pack = gr.pack_k_bits_bb(2) bts = gr.map_bb((syms)) mapper = gr.chunks_to_symbols_bc(pts, 1) rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91) interp = gr.interp_fir_filter_ccc(2, (rrc_taps)) sink = gr.vector_sink_c() tb = gr.top_block() tb.connect(src, unpack, pack, bts, mapper, interp, sink) tb.run() return sink.data()
def mod_bits_qpsk(strbits, syms=[0,1,3,2], pts=[-1,1j,1,-1j]): src = gr.vector_source_b(es.string_to_vector(strbits)); unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST); pack = gr.pack_k_bits_bb(2); bts = gr.map_bb((syms)); mapper = gr.chunks_to_symbols_bc(pts, 1); rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91); interp = gr.interp_fir_filter_ccc(2, (rrc_taps)) sink = gr.vector_sink_c(); tb=gr.top_block(); tb.connect(src,unpack,pack,bts,mapper,interp,sink); tb.run(); return sink.data();
def __init__(self, EbN0): gr.top_block.__init__(self) self.const = digital.qpsk_constellation() # Source is N_BITS bits, non-repeated data = map(int, numpy.random.randint(0, self.const.arity(), N_BITS/self.const.bits_per_symbol())) src = gr.vector_source_b(data, False) mod = gr.chunks_to_symbols_bc((self.const.points()), 1) add = gr.add_vcc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, self.EbN0_to_noise_voltage(EbN0), RAND_SEED) demod = digital.constellation_decoder_cb(self.const.base()) ber = BitErrors(self.const.bits_per_symbol()) self.sink = gr.vector_sink_f() self.connect(src, mod, add, demod, ber, self.sink) self.connect(noise, (add, 1)) self.connect(src, (ber, 1))
def __init__(self, EbN0): gr.top_block.__init__(self) self.const = digital.qpsk_constellation() # Source is N_BITS bits, non-repeated data = map( int, numpy.random.randint(0, self.const.arity(), N_BITS / self.const.bits_per_symbol())) src = gr.vector_source_b(data, False) mod = gr.chunks_to_symbols_bc((self.const.points()), 1) add = gr.add_vcc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, self.EbN0_to_noise_voltage(EbN0), RAND_SEED) demod = digital.constellation_decoder_cb(self.const.base()) ber = BitErrors(self.const.bits_per_symbol()) self.sink = gr.vector_sink_f() self.connect(src, mod, add, demod, ber, self.sink) self.connect(noise, (add, 1)) self.connect(src, (ber, 1))
def __init__(self, sample_rate, symbol_rate): gr.hier_block2.__init__(self, "dvb_s_modulator_bc", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature samples_per_symbol = sample_rate / symbol_rate if samples_per_symbol < 2: raise TypeError, "Samples per symbol must be >= 2" # Form symbols with 2 bits per symbol self.pack = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self.reunpack = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST) self.mapper = gr.chunks_to_symbols_bc(mod_constellation) # Design FIR filter taps for square root raised cosine filter ntaps = 11 * int(samples_per_symbol * nfilts) rrc_taps = gr.firdes.root_raised_cosine(nfilts, nfilts, 1.0, dvb_swig.RRC_ROLLOFF_FACTOR, ntaps) # Baseband pulse shaping filter self.rrc_filter = gr.pfb_arb_resampler_ccf(samples_per_symbol, rrc_taps) self.connect(self, self.pack, self.reunpack, self.mapper, self.rrc_filter, self)
def __init__(self, fg, spb, alpha, gain, use_barker=0): if not isinstance(spb, int) or spb < 2: raise TypeError, "sbp must be an integer >= 2" self.spb = spb self.bits_per_chunk = 1 ntaps = 2 * spb - 1 alpha = 0.5 self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk, gr.GR_MSB_FIRST) constellation = ( (), ( -1-0j,1+0j ), ( 0.707+0.707j,-0.707-0.707j ), ( 0.707+0j,-0.707-0.707j ), ( -1+0j,-1j, 1j, 1+0j ), ( 1+0j,0+1j,-1+0j,0-1j ), ( 0+0j,1+0j ) ) self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2]) self.scrambler = bbn.scrambler_bb(True) self.diff_encode = gr.diff_encoder_bb(2); self.barker_taps = bbn.firdes_barker(spb) self.rrc_taps = gr.firdes.root_raised_cosine(4 * gain, spb, 1.0, alpha, ntaps) if use_barker: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps) else: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps) fg.connect(self.scrambler, self.bytes2chunks) fg.connect(self.bytes2chunks, self.diff_encode) fg.connect(self.diff_encode, self.chunks2symbols) fg.connect(self.chunks2symbols,self.tx_filter) gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter) bbn.crc16_init()
def __init__(self, sps, excess_bw, amplitude, vector_source): try: self.sps = 2 except KeyError: pass gr.hier_block2.__init__(self, "OQPSK Modulator", gr.io_signature(0, 0, 0), # Input gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output if not isinstance(self.sps, int) or self.sps < 2: raise TypeError, "sample per symbol sps ou spb must be an integer >= 2" self.vector_source = vector_source self.symbolsToChips = ucla.symbols_to_chips_bi() self.chipsToSymbols = gr.packed_to_unpacked_ii(2, gr.GR_MSB_FIRST) #self.symbolsToConstellation = gr.chunks_to_symbols_ic((-1-1j, -1+1j, 1-1j, 1+1j)) self.symbolsToConstellation = gr.chunks_to_symbols_bc((-1-1j, -1+1j, 1-1j, 1+1j)) #self._scrambler = gr.scrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit scrambler self.pskmod = ucla.qpsk_modulator_cc() self.delay = ucla.delay_cc(self.sps) self.amp = gr.multiply_const_cc(amplitude) #self.connect(self.vector_source , self.symbolsToChips, self.chipsToSymbols, self.symbolsToConstellation, self.pskmod, self.delay, self.amp, self) #self.connect(self.vector_source , self._scrambler, self.symbolsToConstellation, self.pskmod, self.delay, self.amp, self) self.connect(self.vector_source, self.symbolsToConstellation, self.pskmod, self.delay, self.amp, self) #self.connect(self, self.symbolsToChips, self.chipsToSymbols, self.symbolsToConstellation, self.pskmod, self)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered differential BPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per baud >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param log: Log modulation data to files? @type log: bool """ gr.hier_block2.__init__(self, "dbpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if self._samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter nfilts = 32 ntaps = nfilts * 11 * int(self._samples_per_symbol) # make nfilts filters of ntaps each self.rrc_taps = gr.firdes.root_raised_cosine( nfilts, # gain nfilts, # sampling rate based on 32 filters in resampler 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol, self.rrc_taps) # Connect self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self) if verbose: self._print_verbage() if log: self._setup_logging()
def __init__(self, constellation, samples_per_symbol=_def_samples_per_symbol, differential=_def_differential, excess_bw=_def_excess_bw, gray_coded=True, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered differential generic modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param constellation: determines the modulation type @type constellation: gnuradio.digital.gr_constellation @param samples_per_symbol: samples per baud >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_coded: turn gray coding on/off @type gray_coded: bool @param verbose: Print information about modulator? @type verbose: bool @param log: Log modulation data to files? @type log: bool """ gr.hier_block2.__init__(self, "generic_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._constellation = constellation.base() self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._differential = differential if self._samples_per_symbol < 2: raise TypeError, ("sbp must be >= 2, is %f" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if gray_coded == True: self.symbol_mapper = gr.map_bb(self._constellation.pre_diff_code()) if differential: self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(self._constellation.points()) # pulse shaping filter nfilts = 32 ntaps = nfilts * 11 * int(self._samples_per_symbol) # make nfilts filters of ntaps each self.rrc_taps = gr.firdes.root_raised_cosine( nfilts, # gain nfilts, # sampling rate based on 32 filters in resampler 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol, self.rrc_taps) # Connect blocks = [self, self.bytes2chunks] if gray_coded == True: blocks.append(self.symbol_mapper) if differential: blocks.append(self.diffenc) blocks += [self.chunks2symbols, self.rrc_filter, self] self.connect(*blocks) if verbose: self._print_verbage() if log: self._setup_logging()
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "qam8_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) rot = 1.0 print "constellation with %d arity" % arity rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self. _samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__(self, "qam8_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(qam.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(qam.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) rot = 1.0 print "constellation with %d arity" % arity rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__(self, constellation, samples_per_symbol=_def_samples_per_symbol, differential=_def_differential, excess_bw=_def_excess_bw, gray_coded=True, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered differential generic modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param constellation: determines the modulation type @type constellation: gnuradio.digital.gr_constellation @param samples_per_symbol: samples per baud >= 2 @type samples_per_symbol: float @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_coded: turn gray coding on/off @type gray_coded: bool @param verbose: Print information about modulator? @type verbose: bool @param log: Log modulation data to files? @type log: bool """ gr.hier_block2.__init__( self, "generic_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._constellation = constellation.base() self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._differential = differential if self._samples_per_symbol < 2: raise TypeError, ("sbp must be >= 2, is %f" % self._samples_per_symbol) arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if gray_coded == True: self.symbol_mapper = gr.map_bb(self._constellation.pre_diff_code()) if differential: self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc( self._constellation.points()) # pulse shaping filter nfilts = 32 ntaps = nfilts * 11 * int( self._samples_per_symbol) # make nfilts filters of ntaps each self.rrc_taps = gr.firdes.root_raised_cosine( nfilts, # gain nfilts, # sampling rate based on 32 filters in resampler 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol, self.rrc_taps) # Connect blocks = [self, self.bytes2chunks] if gray_coded == True: blocks.append(self.symbol_mapper) if differential: blocks.append(self.diffenc) blocks += [self.chunks2symbols, self.rrc_filter, self] self.connect(*blocks) if verbose: self._print_verbage() if log: self._setup_logging()
def __init__(self, gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol * self.amplitude, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) # self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( # gui.GetWin(), # title="Constellation Plot", # sample_rate=self._samples_per_symbol, # frame_rate=5, # const_size=2048, # M=2, # theta=0, # alpha=0.005, # fmax=0.06, # mu=0.5, # gain_mu=0.005, # symbol_rate=self._samples_per_symbol/2, # omega_limit=0.005, # ) # gui.Add(self.wxgui_constellationsink2_0.win) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self._scrambler, self.chunks2symbols_b, self.rrc_filter, self) #self.connect(self.rrc_filter, self.wxgui_constellationsink2_0) if self.verbose: self._print_verbage()
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__(self, "cqpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = 8 # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) # 0 +45 1 [+1] # 1 +135 3 [+3] # 2 -45 7 [-1] # 3 -135 5 [-3] self.pi4map = [1, 3, 7, 5] self.symbol_mapper = gr.map_bb(self.pi4map) self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter self.rrc_taps = firdes.root_raised_cosine( self._samples_per_symbol, # gain (sps since we're interpolating by sps) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = filter.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__(self, fg, spb, alpha, gain, use_barker=0): """ Hierarchical block for RRC-filtered PSK modulation modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param spb: samples per baud >= 2 @type spb: integer @param alpha: Root-raised cosine filter excess bandwidth @type alpha: float """ if not isinstance(spb, int) or spb < 2: raise TypeError, "sbp must be an integer >= 2" self.spb = spb self.bits_per_chunk = 1 ntaps = 2 * spb - 1 alpha = 0.5 # turn bytes into symbols self.bytes2chunks = gr.packed_to_unpacked_bb(self.bits_per_chunk, gr.GR_MSB_FIRST) constellation = ( (), ( -1-0j,1+0j ), ( 0.707+0.707j,-0.707-0.707j ), ( 0.707+0j,-0.707-0.707j ), ( -1+0j,-1j, 1j, 1+0j), ( 1+0j,0+1j,-1+0j,0-1j ), ( 0+0j,1+0j ), ) self.chunks2symbols = gr.chunks_to_symbols_bc(constellation[2]) self.scrambler = bbn.scrambler_bb(True) self.diff_encode = gr.diff_encoder_bb(2); self.barker_taps = bbn.firdes_barker(spb) # Form Raised Cosine filter self.rrc_taps = gr.firdes.root_raised_cosine( 4 * gain, # gain FIXME may need to be spb spb, # sampling freq 1.0, # symbol_rate alpha, ntaps) if use_barker: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.barker_taps) else: self.tx_filter = gr.interp_fir_filter_ccf(spb, self.rrc_taps) # Connect fg.connect(self.scrambler, self.bytes2chunks) fg.connect(self.bytes2chunks, self.diff_encode) fg.connect(self.diff_encode, self.chunks2symbols) fg.connect(self.chunks2symbols,self.tx_filter) # Initialize base class gr.hier_block.__init__(self, fg, self.scrambler, self.tx_filter) bbn.crc16_init()
def __init__(self, principal_gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) #arity = pow (2, 2) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: map_param = psk.binary_to_gray[arity] self.symbol_mapper = gr.map_bb(map_param) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #For IEEE 802.15.4 915 868 MHz standard self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #case when we use a stream of bits #self.connect(self, self.chunks2symbols_b, self.rrc_filter, self) if self.verbose: self._print_verbage()
def __init__(self, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered QPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param samples_per_symbol: samples per symbol >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modualtion data to files? @type debug: bool """ gr.hier_block2.__init__( self, "dqpsk2_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if samples_per_symbol < 2: raise TypeError, ("sbp must be >= 2, is %f" % samples_per_symbol) ntaps = 11 * samples_per_symbol arity = pow(2, self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) rot = .707 + .707j rotated_const = map(lambda pt: pt * rot, psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_bc(rotated_const) # pulse shaping filter nfilts = 32 ntaps = 11 * int( nfilts * self._samples_per_symbol) # make nfilts filters of ntaps each self.rrc_taps = gr.firdes.root_raised_cosine( nfilts, # gain nfilts, # sampling rate based on 32 filters in resampler 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol, self.rrc_taps) if verbose: self._print_verbage() if log: self._setup_logging() # Connect & Initialize base class self.connect(self, self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter, self)
def __init__(self, fg, samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, gray_code=_def_gray_code, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered differential BPSK modulation. The input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param samples_per_symbol: samples per baud >= 2 @type samples_per_symbol: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param gray_code: Tell modulator to Gray code the bits @type gray_code: bool @param verbose: Print information about modulator? @type verbose: bool @param log: Log modulation data to files? @type log: bool """ self._fg = fg self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._gray_code = gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sbp must be an integer >= 2, is %d" % self._samples_per_symbol) ntaps = 11 * self._samples_per_symbol arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.bytes2chunks = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diffenc = gr.diff_encoder_bb(arity) self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect fg.connect(self.bytes2chunks, self.symbol_mapper, self.diffenc, self.chunks2symbols, self.rrc_filter) if verbose: self._print_verbage() if log: self._setup_logging() # Initialize base class gr.hier_block.__init__(self, self._fg, self.bytes2chunks, self.rrc_filter)