#!/usr/bin/env python ################################################## # Gnuradio Python Flow Graph # Title: OFDM TX-RX # Generated: Tue Mar 18 16:46:24 2014 ################################################## from gnuradio import analog from gnuradio import blocks from gnuradio import digital from gnuradio import eng_notation from gnuradio import fft from gnuradio import gr from gnuradio import window from gnuradio.digital.utils import tagged_streams from gnuradio.eng_option import eng_option from gnuradio.gr import firdes from gnuradio.wxgui import fftsink2 from grc_gnuradio import wxgui as grc_wxgui from optparse import OptionParser import numpy import random import wx class OFDM_txrx(grc_wxgui.top_block_gui): def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="OFDM TX-RX") ################################################## # Variables ################################################## self.payload_mod = payload_mod = digital.qam.qam_constellation(constellation_points=16, differential=True, mod_code='none', large_ampls_to_corners=False) self.header_mod = header_mod = digital.constellation_qpsk() self.occupied_carriers = occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) self.bps_payload = bps_payload = payload_mod.bits_per_symbol() self.bps_header = bps_header = header_mod.bits_per_symbol() self.sync_word2 = sync_word2 = (0, 0, 0, 0, 0, 1, 1, -1.0, -1, 1.0, 1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 1, 1.0, 1, -1.0, -1, -1.0, -1, 1.0, -1, 1.0, -1, 1.0, 1, -1.0, 0, 1.0, 1, -1.0, 1, 1.0, -1, -1.0, 1, -1.0, -1, -1.0, 1, 1.0, 1, -1.0, 1, 1.0, -1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 0, 0, 0, 0, 0, 0) self.sync_word1 = sync_word1 = (0, 0, 0, 0, 0, 0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 0, 0, 0, 0, 0) self.samp_rate = samp_rate = 100e3 self.rolloff = rolloff = 0 self.pilot_symbols = pilot_symbols = ((1, 1, -1, -1,),) self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),) self.packet_len = packet_len = 96 self.num_tag_key = num_tag_key = "" self.length_tag_name = length_tag_name = "packet_len" self.length_tag_key = length_tag_key = "frame_len" self.header_formatter = header_formatter = digital.packet_header_ofdm(occupied_carriers, 1, "packet_len", "frame_len", "",bps_header,bps_payload) self.fft_len = fft_len = 64 self.cp_len = cp_len = 16 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=64, fft_rate=15, average=True, avg_alpha=None, title="FFT Plot", peak_hold=False, size=(400,400), ) self.Add(self.wxgui_fftsink2_0.win) self.fft_vxx_0_0_0 = fft.fft_vcc(fft_len, True, (()), True, 1) self.fft_vxx_0_0 = fft.fft_vcc(fft_len, True, (()), True, 1) self.fft_vxx_0 = fft.fft_vcc(fft_len, False, (()), True, 1) self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(header_formatter.formatter()) self.digital_packet_headergenerator_bb_0 = digital.packet_headergenerator_bb(header_formatter.formatter()) self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(fft_len, fft_len/4, False) self.digital_ofdm_serializer_vcc_1 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, length_tag_key, "packet_len", 1, "", True) self.digital_ofdm_serializer_vcc_0 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, length_tag_key, "frame_len", 0, "", True) self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, payload_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 2).base(), fft_len/4, length_tag_key, True, 0) self.digital_ofdm_frame_equalizer_vcvc_0_0 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(),occupied_carriers, pilot_carriers, pilot_symbols).base(), fft_len/4, length_tag_key, True, 1) self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(fft_len, fft_len+fft_len/4, rolloff, length_tag_name) self.digital_ofdm_chanest_vcvc_1 = digital.ofdm_chanest_vcvc((sync_word1), (sync_word2), 1, 0, -1, False) self.digital_ofdm_carrier_allocator_cvc_0 = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, length_tag_name) self.digital_header_payload_demux_0 = digital.header_payload_demux(3, 64, 16, "frame_len", "", True, gr.sizeof_gr_complex) self.digital_crc32_bb_0_0 = digital.crc32_bb(True, "packet_len") self.digital_crc32_bb_0 = digital.crc32_bb(False, length_tag_name) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(header_mod.base()) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(payload_mod.base()) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc((payload_mod.points()), 1) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((header_mod.points()), 1) self.blocks_vector_source_x_0 = blocks.vector_source_b(range(packet_len), True, 1, tagged_streams.make_lengthtags((packet_len,), (0, ), length_tag_name)) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, length_tag_name) self.blocks_tag_debug_1_1 = blocks.tag_debug(gr.sizeof_gr_complex*64, "POST-PAYLOAD-DEMUX") self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char*1, "RX") self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "Rx Packets") self.blocks_repack_bits_bb_1 = blocks.repack_bits_bb(payload_mod.bits_per_symbol(), 8, "packet_len", False) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, payload_mod.bits_per_symbol(), length_tag_name, False) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.05, )) self.blocks_file_sink_17 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/post-payload-crc.dat") self.blocks_file_sink_17.set_unbuffered(False) self.blocks_file_sink_16 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/post-payload-repack.dat") self.blocks_file_sink_16.set_unbuffered(False) self.blocks_file_sink_15 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/post-payload-demod.dat") self.blocks_file_sink_15.set_unbuffered(False) self.blocks_file_sink_14 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/fox/Documents/GNU_radio/test_data/post-payload-serializer.dat") self.blocks_file_sink_14.set_unbuffered(False) self.blocks_file_sink_13 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/post-payload-eq.dat") self.blocks_file_sink_13.set_unbuffered(False) self.blocks_file_sink_12 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/post-payload-fft.dat") self.blocks_file_sink_12.set_unbuffered(False) self.blocks_file_sink_11 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/post-hdr-demod.dat") self.blocks_file_sink_11.set_unbuffered(False) self.blocks_file_sink_10 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/fox/Documents/GNU_radio/test_data/post-hdr-serializer.dat") self.blocks_file_sink_10.set_unbuffered(False) self.blocks_file_sink_09 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/post-hdr-eq.dat") self.blocks_file_sink_09.set_unbuffered(False) self.blocks_file_sink_08 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/post-hdr-chanest.dat") self.blocks_file_sink_08.set_unbuffered(False) self.blocks_file_sink_07 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/channel-estimate.dat") self.blocks_file_sink_07.set_unbuffered(False) self.blocks_file_sink_06 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/sync-detect.dat") self.blocks_file_sink_06.set_unbuffered(False) self.blocks_file_sink_05 = blocks.file_sink(gr.sizeof_float*1, "/home/fox/Documents/GNU_radio/test_data/freq-offset.dat") self.blocks_file_sink_05.set_unbuffered(False) self.blocks_file_sink_04 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/fox/Documents/GNU_radio/test_data/tx-signal.dat") self.blocks_file_sink_04.set_unbuffered(False) self.blocks_file_sink_03 = blocks.file_sink(gr.sizeof_gr_complex*64, "/home/fox/Documents/GNU_radio/test_data/tx-post-allocator.dat") self.blocks_file_sink_03.set_unbuffered(False) self.blocks_file_sink_02 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/tx-hdr.dat") self.blocks_file_sink_02.set_unbuffered(False) self.blocks_file_sink_01 = blocks.file_sink(gr.sizeof_char*1, "/home/fox/Documents/GNU_radio/test_data/vector-source.dat") self.blocks_file_sink_01.set_unbuffered(False) self.blocks_delay_0_1 = blocks.delay(gr.sizeof_gr_complex*1, 0) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 72) self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(-2.0/fft_len) ################################################## # Connections ################################################## self.connect((self.digital_ofdm_frame_equalizer_vcvc_0_0, 0), (self.digital_ofdm_serializer_vcc_0, 0)) self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_ofdm_carrier_allocator_cvc_0, 0)) self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_ofdm_serializer_vcc_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.digital_ofdm_carrier_allocator_cvc_0, 0), (self.blocks_file_sink_03, 0)) self.connect((self.digital_ofdm_carrier_allocator_cvc_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.blocks_file_sink_04, 0)) self.connect((self.digital_header_payload_demux_0, 0), (self.fft_vxx_0_0, 0)) self.connect((self.digital_ofdm_chanest_vcvc_1, 0), (self.digital_ofdm_frame_equalizer_vcvc_0_0, 0)) self.connect((self.fft_vxx_0_0, 0), (self.digital_ofdm_chanest_vcvc_1, 0)) self.connect((self.fft_vxx_0_0, 0), (self.blocks_file_sink_07, 0)) self.connect((self.digital_ofdm_chanest_vcvc_1, 0), (self.blocks_file_sink_08, 0)) self.connect((self.digital_ofdm_frame_equalizer_vcvc_0_0, 0), (self.blocks_file_sink_09, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.blocks_file_sink_11, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_packet_headerparser_b_0, 0)) self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.blocks_file_sink_06, 0)) self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.blocks_file_sink_05, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.digital_header_payload_demux_0, 1), (self.blocks_tag_debug_1_1, 0)) self.connect((self.blocks_delay_0_1, 0), (self.digital_header_payload_demux_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_delay_0_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.analog_frequency_modulator_fc_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.digital_ofdm_sync_sc_cfb_0, 0)) self.connect((self.digital_ofdm_serializer_vcc_0, 0), (self.blocks_file_sink_10, 0)) self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_cyclic_prefixer_0, 0)) self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.digital_header_payload_demux_0, 1)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_file_sink_01, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.digital_crc32_bb_0, 0)) self.connect((self.digital_crc32_bb_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.digital_crc32_bb_0, 0), (self.digital_packet_headergenerator_bb_0, 0)) self.connect((self.digital_packet_headergenerator_bb_0, 0), (self.blocks_file_sink_02, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.blocks_tagged_stream_mux_0, 1)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.digital_packet_headergenerator_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0), (self.digital_ofdm_serializer_vcc_1, 0)) self.connect((self.fft_vxx_0_0_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_1, 0)) self.connect((self.digital_header_payload_demux_0, 1), (self.fft_vxx_0_0_0, 0)) self.connect((self.fft_vxx_0_0_0, 0), (self.blocks_file_sink_12, 0)) self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0), (self.blocks_file_sink_13, 0)) self.connect((self.digital_ofdm_serializer_vcc_1, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_ofdm_serializer_vcc_1, 0), (self.blocks_file_sink_14, 0)) self.connect((self.blocks_repack_bits_bb_1, 0), (self.blocks_file_sink_16, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_file_sink_15, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_repack_bits_bb_1, 0)) self.connect((self.blocks_repack_bits_bb_1, 0), (self.blocks_tag_debug_1, 0)) self.connect((self.digital_crc32_bb_0_0, 0), (self.blocks_file_sink_17, 0)) self.connect((self.digital_crc32_bb_0_0, 0), (self.blocks_tag_debug_0, 0)) self.connect((self.blocks_repack_bits_bb_1, 0), (self.digital_crc32_bb_0_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.digital_packet_headerparser_b_0, "header_data", self.digital_header_payload_demux_0, "header_data") def get_payload_mod(self): return self.payload_mod def set_payload_mod(self, payload_mod): self.payload_mod = payload_mod self.set_bps_payload(self.payload_mod.bits_per_symbol()) def get_header_mod(self): return self.header_mod def set_header_mod(self, header_mod): self.header_mod = header_mod self.set_bps_header(self.header_mod.bits_per_symbol()) def get_occupied_carriers(self): return self.occupied_carriers def set_occupied_carriers(self, occupied_carriers): self.occupied_carriers = occupied_carriers self.set_header_formatter(digital.packet_header_ofdm(self.occupied_carriers, 1, "packet_len", "frame_len", "",self.bps_header,self.bps_payload)) def get_bps_payload(self): return self.bps_payload def set_bps_payload(self, bps_payload): self.bps_payload = bps_payload self.set_header_formatter(digital.packet_header_ofdm(self.occupied_carriers, 1, "packet_len", "frame_len", "",self.bps_header,self.bps_payload)) def get_bps_header(self): return self.bps_header def set_bps_header(self, bps_header): self.bps_header = bps_header self.set_header_formatter(digital.packet_header_ofdm(self.occupied_carriers, 1, "packet_len", "frame_len", "",self.bps_header,self.bps_payload)) def get_sync_word2(self): return self.sync_word2 def set_sync_word2(self, sync_word2): self.sync_word2 = sync_word2 def get_sync_word1(self): return self.sync_word1 def set_sync_word1(self, sync_word1): self.sync_word1 = sync_word1 def get_samp_rate(self): return self.samp_rate def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate self.blocks_throttle_0.set_sample_rate(self.samp_rate) self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate) def get_rolloff(self): return self.rolloff def set_rolloff(self, rolloff): self.rolloff = rolloff def get_pilot_symbols(self): return self.pilot_symbols def set_pilot_symbols(self, pilot_symbols): self.pilot_symbols = pilot_symbols def get_pilot_carriers(self): return self.pilot_carriers def set_pilot_carriers(self, pilot_carriers): self.pilot_carriers = pilot_carriers def get_packet_len(self): return self.packet_len def set_packet_len(self, packet_len): self.packet_len = packet_len def get_num_tag_key(self): return self.num_tag_key def set_num_tag_key(self, num_tag_key): self.num_tag_key = num_tag_key def get_length_tag_name(self): return self.length_tag_name def set_length_tag_name(self, length_tag_name): self.length_tag_name = length_tag_name def get_length_tag_key(self): return self.length_tag_key def set_length_tag_key(self, length_tag_key): self.length_tag_key = length_tag_key def get_header_formatter(self): return self.header_formatter def set_header_formatter(self, header_formatter): self.header_formatter = header_formatter def get_fft_len(self): return self.fft_len def set_fft_len(self, fft_len): self.fft_len = fft_len self.analog_frequency_modulator_fc_0.set_sensitivity(-2.0/self.fft_len) def get_cp_len(self): return self.cp_len def set_cp_len(self, cp_len): self.cp_len = cp_len if __name__ == '__main__': parser = OptionParser(option_class=eng_option, usage="%prog: [options]") (options, args) = parser.parse_args() tb = OFDM_txrx() tb.Run(True)