discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] GRC version 0.60


From: Josh Blum
Subject: Re: [Discuss-gnuradio] GRC version 0.60
Date: Sun, 11 Feb 2007 17:48:41 -0500
User-agent: Thunderbird 1.5.0.9 (X11/20070103)

I caught a mistake in the Trellis.py file. It was my fault for not finishing the notes on adding signal blocks. The only reason I said to declare fcn at the beginning of a definition was so that an attribute error could be raised if the gnuradio block didnt exist. In this case, by adding the names of the gnuradio block to the type = Enum(...), you are doing the same thing in effect. And in the make method, you just call type.parse()[0] ...if 0 was the index of the gnuradio block in the type.parse() tuple.

So, calling fcn[0] at runtime would raise an error, but I dont understand the X windows error.

I fixed the Trellis.py and ran your example. The screen shot and new Trellis.py are attached.

I hope the Trellis works for you now.
-Josh

BTW, I added the trellis file to my repos.

Anastasopoulos Achilleas wrote:

Josh,

I imported some blocks from gr-trellis on GRC.

However there seems to be a problem.
The graph does not run and exits with something like:

...
flow graph save
SRC_DIR: /net/ernesto/home/anastas/grc_mine/src
DATA_DIR: /net/ernesto/home/anastas/grc_mine/data
FILE_PATH: /n/ernesto/home/anastas
'module' object has no attribute 'fractional_interpolator' in Interpolate! -> continuing...
The program 'Run.py' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadPixmap (invalid Pixmap parameter)'.
  (Details: serial 15335 error_code 4 request_code 56 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)




Attached please find the following files:
Trellis.py   (the GRC implementation of some blocks in gr-trellis)
__init.__.py
test_encoder.py
test_encoder.grc.xml
(test files that shows the python code working fine and
the grc equivalent failing)


I would appreciate your input.
Once this is resolve, I can implement the rest
of the blocks in gr-trellis.


Thanks
Achilleas
------------------------------------------------------------------------

"""
GNU Radio Companion is a graphical interface into the GNU Radio project.
Copyright (C) 2007 Josh Blum

GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""
"""
SignalBlockDefs/Misc.py Josh Blum
        These blocks were not categorized. Try to keep the number of misc 
blocks small.
"""

from DataType import *
from gnuradio import gr
from SignalBlockDefs import *


def Encoder(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte-->Byte', (trellis.encoder_bb, Byte(),Byte())),
                     ('Byte-->Short', (trellis.encoder_bs, Byte(),Short())),
                     ('Byte-->Int', (trellis.encoder_bi, Byte(),Int())),
                     ('Short-->Short', (trellis.encoder_ss, Short(),Short())),
                     ('Short-->Int', (trellis.encoder_si, Short(),Int())),
                     ('Int-->Int', (trellis.encoder_ii, Int(),Int())),
                     ],3)
        fcn = type.parse()[0]
        sb.add_input_socket('in', Variable(type, index=1))
        sb.add_output_socket('out', Variable(type, index=2))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Initial State', Int())
        sb.set_docs('''Trellis Encoder. For the time being the underlying FSM 
can only be read from a file...''')
        def make(fg, type, filename, s0):
                fsm=trellis.fsm(filename.parse()) # not sure if this is the 
right way to do this...
                block = fcn[0](fsm, s0.parse())
                return block
        return sb, make




def Metrics(sb):
        from gnuradio import trellis
        type = Enum([('Complex', (trellis.metrics_c, Complex())),
                     ('Float', (trellis.metrics_f, Float())),
                     ('Int', (trellis.metrics_i, Int())),
                     ('Short', (trellis.metrics_s, Short())),],1)
        fcn = type.parse()[0]
        sb.add_input_socket('in', Variable(type, index=1))
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('Output cardinality', Int())
        sb.add_param('Dimensionality', Int())
        sb.add_param('Constellation', FloatVector())
sb.add_param('Metric Type', Enum([('Euclidean', trellis.TRELLIS_EUCLIDEAN),
                    ('Hard Symbol', trellis.TRELLIS_HARD_SYMBOL),
                    ('Hard Bit', trellis.TRELLIS_HARD_BIT)],0))
        sb.set_docs('''Generate the metrics block from gr-trellis.''')
        def make(fg, type, O, D, Con, MetrType):
                block = fcn[0](O.parse(), D.parse(), Con.parse(), 
MetrType.parse())
                return block
        return sb, make


def Viterbi(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte', (trellis.viterbi_b, Byte())),
                     ('Short', (trellis.viterbi_s, Short())),
                     ('Int', (trellis.viterbi_i, Int())),
                     ],1)
        fcn = type.parse()[0]
        sb.add_input_socket('in', Float())
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Length', Int())
        sb.add_param('Initial State', Int())
        sb.add_param('Final State', Int())
        sb.set_docs('''Viterbi Decoder. FSM is specified through its filnemae 
only...''')
        def make(fg, type, filename, K, s0, sK):
                fsm=trellis.fsm(filename.parse())
                block = fcn[0](fsm, K.parse(), s0.parse(), sK.parse())
                return block
        return sb, make


def Viterbi_Combined(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte', (trellis.viterbi_combined_b, Byte())),
                     ('Short', (trellis.viterbi_combined_s, Short())),
                     ('Int', (trellis.viterbi_combined_i, Int())),
                     ],1)
        fcn = type.parse()[0]
        sb.add_input_socket('in', Float())
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Length', Int())
        sb.add_param('Initial State', Int())
        sb.add_param('Final State', Int())
        sb.add_param('Dimensionality', Int())
        sb.add_param('Constellation', FloatVector())
        sb.add_param('Metric Type',
              Enum([('Euclidean', trellis.TRELLIS_EUCLIDEAN),
                    ('Hard Symbol', trellis.TRELLIS_HARD_SYMBOL),
                    ('Hard Bit', trellis.TRELLIS_HARD_BIT)],0))

        sb.set_docs('''Viterbi Decoder combined with metric calculation. FSM is 
specified through its filnemae only...''')
        def make(fg, type, filename, K, s0, sK, D, Con, MetrType):
                fsm=trellis.fsm(filename.parse())
                block = fcn[0](fsm, K.parse(), s0.parse(), sK.parse(), 
D.parse(), Con.parse(), MetrType.parse())
                return block
        return sb, make

------------------------------------------------------------------------

"""
GNU Radio Companion is a graphical interface into the GNU Radio project.
Copyright (C) 2007 Josh Blum

GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""
"""
SignalBlockDefs/__init__.py Josh Blum
        Build a signal block represented by a specific tag.
"""

from Elements import SignalBlock
from DataType import *

all_choices = [
('Complex', Complex()),
('Float', Float()),
('Int', Int()),
('Short', Short()),
('Byte', Byte()),]

all_vector_choices = [('Complex Vector', (ComplexVector(), Complex())),
                                                        ('Float Vector', 
(FloatVector(), Float())),
                                                        ('Int Vector', 
(IntVector(), Int())),
                                                        ('Short Vector', 
(ShortVector(), Short())),
                                                        ('Byte Vector', 
(ByteVector(), Byte()))]

default_samp_rate = '$samp_rate'

audio_rates = [('16KHz', int(16e3)),
                                        ('22.05KHz', int(22.05e3)),
                                        ('24KHz', int(24e3)),
                                        ('32KHz', int(32e3)),
                                        ('44.1KHz', int(44.1e3)),
                                        ('48KHz', int(48e3)),]
default_audio_rate_index = 3

import Sources
import Sinks
import Conversions
import Operators
import Filters
import Modulators
import Misc
import USRP
import Coders
import Trellis

TAGS = (
                        ('Sources', [           
                                ('Signal Source', Sources.SignalSource),
                                ('Noise Source', Sources.NoiseSource),          
                                                
                                ('Vector Source', Sources.VectorSource),
                                ('Random Source', Sources.RandomVector),        
        
                                ('Null Source', Sources.NullSource),    
                                ('File Source', Sources.FileSource),            
                
                                ('Audio Source', Sources.AudioSource),
                                ('USRP Source', USRP.USRPSource),
                        ]),
                        ('Sinks', [                             
                                ('Scope Sink', Sinks.ScopeSink),
                                ('FFT Sink', Sinks.FFTSink),    
                                ('Constellation Sink', Sinks.ConstellationSink),
                                ('Null Sink', Sinks.NullSink),
                                ('File Sink', Sinks.FileSink),                  
        
                                ('Audio Sink', Sinks.AudioSink),
                                ('USRP Sink', USRP.USRPSink),
                        ]),
                        ('Operations', [                        
                                ('Add Constant', Operators.AddConstant),
                                ('Add Constant Vector', 
Operators.AddConstantVector),
                                ('Add', Operators.Add),
                                ('Add Vector', Operators.AddVector),
                                ('Subtract', Operators.Subtract),
                                ('Multiply Constant', 
Operators.MultiplyConstant),              
                                ('Multiply Constant Vector', 
Operators.MultiplyConstantVector),                 
                                ('Multiply', Operators.Multiply),
                                ('Multiply Vector', Operators.MultiplyVector),
                                ('Divide', Operators.Divide),
                                ('nLog10', Operators.nLog10),
                                ('nLog10 Vector', Operators.nLog10Vector),
                        ]),
                        ('Conversions', [                       
                                ('Complex Components', 
Conversions.ComplexComponents),
                                ('Complex Conjugate', 
Conversions.ComplexConjugate),
                                ('Float to Complex', 
Conversions.FloatToComplex),
                                ('Complex to Float', 
Conversions.ComplexToFloat),
                                ('Float to Short', Conversions.FloatToShort),
                                ('Short to Float', Conversions.ShortToFloat),
                                ('Float to Char', Conversions.FloatToChar),
                                ('Char to Float', Conversions.CharToFloat),
                                ('Float to UChar', Conversions.FloatToUChar),
                                ('UChar to Float', Conversions.UCharToFloat),
                                ('Complex to IShort', 
Conversions.ComplexToIShort),
                                ('IShort to Complex', 
Conversions.IShortToComplex),     
                                ('Unpacked to Packed', 
Conversions.UnpackedToPacked),
                                ('Packed to Unpacked', 
Conversions.PackedToUnpacked),
                                ('Unpack k Bits', Conversions.UnpackKBits),
                                ('Binary Slicer', Conversions.BinarySlicer),
                                ('Chunks to Symbols', 
Conversions.ChunksToSymbols),
                                ('Chunks to Symbols1', 
Conversions.ChunksToSymbols1),
                                ('Interleave', Conversions.Interleave),
                                ('Deinterleave', Conversions.Deinterleave),
                                ('Streams to Stream', 
Conversions.StreamsToStream),
                                ('Stream to Streams', 
Conversions.StreamToStreams),
                                ('Streams to Vector', 
Conversions.StreamsToVector),
                                ('Vector to Streams', 
Conversions.VectorToStreams),
                                ('Stream to Vector', 
Conversions.StreamToVector),       
                                ('Vector to Stream', 
Conversions.VectorToStream),                                                    
   
                        ]),
                                ('Coders', [('Constellation Decoder', 
Coders.ConstellationDecoder),                             
                                ('Differential Encoder', 
Coders.DifferentialEncoder),
                                ('Differential Decoder', 
Coders.DifferentialDecoder),   
                                ('Differential Phasor', 
Coders.DifferentialPhasor),     
                                ('Coorelate Access Code', 
Coders.CoorelateAccessCode),                                          
                        ]),
                        ('Filters', [                   
                                ('Low Pass Filter', Filters.LowPassFilter),
                                ('High Pass Filter', Filters.HighPassFilter),
                                ('Band Pass Filter', Filters.BandPassFilter),
                                ('Band Reject Filter', 
Filters.BandRejectFilter),
                                ('Window', Filters.Window),
                                ('Root Raised Cosine', 
Filters.RootRaisedCosine),                                                      
         
                                ('Single Pole IIR Filter', 
Filters.SinglePoleIIRFilter),
                                ('Hilbert', Filters.Hilbert),   
                                ('Power Squelch', Filters.PowerSquelch),
                                ('Decimate', Filters.Decimate),
                                ('Interpolate', Filters.Interpolate),
                                ('Automatic Gain Control', 
Filters.AutomaticGainControl),
                                ('CMA Filter', Filters.CMAFilter),
                                ('Costas Loop', Filters.CostasLoop),
                                ('Clock Recovery', Filters.ClockRecovery),
                                ('FFT', Filters.FFT),
                                ('IFFT', Filters.IFFT),
                        ]),
                        ('Modulators', [                        
                                ('Frequency Modulation', 
Modulators.FrequencyModulation),
                                ('Phase Modulation', 
Modulators.PhaseModulation),
                                ('Quadrature Demodulation', 
Modulators.QuadratureDemodulation),
                                ('WFM Receive', Modulators.WFMReceive),         
        
                                ('WFM Transmit', Modulators.WFMTransmit),       
                                ('NBFM Receive', Modulators.NBFMReceive),       
                
                                ('NBFM Transmit', Modulators.NBFMTransmit),     
                                ('AM Demodulation', Modulators.AMDemod),
                                ('FM Demodulation', Modulators.FMDemod),
                                ('PSK Modulation', Modulators.PSKMod),
                                ('PSK Demodulation', Modulators.PSKDemod),
                                ('GMSK Modulation', Modulators.GMSKMod),
                                ('GMSK Demodulation', Modulators.GMSKDemod),
                        ]),
                        ('Misc', [      
                                ('Throttle', Misc.Throttle),
                                ('Head', Misc.Head),                            
                                ('About', Misc.About),
                                ('Note', Misc.Note),            
                        ]),
                        ('Trellis', [
                                ('Trellis Encoder', Trellis.Encoder),
                                ('Metrics', Trellis.Metrics),
                                ('Viterbi Decoder', Trellis.Viterbi),
                                ('Viterbi Decoder Combined with Metric', 
Trellis.Viterbi_Combined),
                        ])
,)                      

def get_signal_block(parent, coor, rot, lookup_tag, id):
        """ Create a new signal based on a few input parameters. """
        sb = SignalBlock(parent, coor, rot, lookup_tag, id)
        for category, signal_blocks in TAGS:
                for tag, builder in signal_blocks:
                        if lookup_tag == tag: return builder(sb)
        raise TagNotFoundException(lookup_tag)  
        
#       remove the bad tags     #
for category,tags in TAGS:
        tags_to_remove = list()
        for tag in tags:
                try: get_signal_block(None, (0,0), 0, tag[0], '')
except (ImportError, AttributeError), e: print e, " in %s! -> continuing..."%tag[0]
                        tags_to_remove.append(tag)              
        for tag in tags_to_remove: tags.remove(tag)

class TagNotFoundException(Exception):
        def __init__(self, value):      self.value = value
        def __str__(self): return 'Exception! The tag: %s could not be 
found'%repr(self.value)
                
        
------------------------------------------------------------------------

<?xml version='1.0' encoding='UTF-8'?>
<flow_graph>
  <timestamp>1171228213.83</timestamp>
  <hostname>ernesto.eecs.umich.edu</hostname>
  <version>0.60</version>
  <valid>True</valid>
  <window_width>1200</window_width>
  <window_height>800</window_height>
  <vars>
    <var>
      <key>packet_length</key>
      <value>100</value>
      <min/>
      <max/>
    </var>
    <var>
      <key>noise_amp</key>
      <value>0.1</value>
      <min/>
      <max/>
    </var>
  </vars>
  <signal_blocks>
    <signal_block>
      <tag>Add</tag>
      <id>Add0</id>
      <x_coordinate>439</x_coordinate>
      <y_coordinate>274</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>0</param>
        <param>2</param>
      </params>
    </signal_block>
    <signal_block>
      <tag>Trellis Encoder</tag>
      <id>Trellis Encoder0</id>
      <x_coordinate>377</x_coordinate>
      <y_coordinate>47</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>5</param>
        <param>/n/ernesto/home/anastas/awgn1o2_4.fsm</param>
        <param>0</param>
      </params>
    </signal_block>
    <signal_block>
      <tag>Chunks to Symbols</tag>
      <id>Chunks to Symbols0</id>
      <x_coordinate>165</x_coordinate>
      <y_coordinate>197</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>2</param>
        <param>1,1j,-1,-1j</param>
      </params>
    </signal_block>
    <signal_block>
      <tag>Random Source</tag>
      <id>Random Source0</id>
      <x_coordinate>67</x_coordinate>
      <y_coordinate>14</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>1</param>
        <param>$packet_length</param>
        <param>0</param>
        <param>1</param>
        <param>71</param>
        <param>0</param>
      </params>
    </signal_block>
    <signal_block>
      <tag>Noise Source</tag>
      <id>Noise Source0</id>
      <x_coordinate>175</x_coordinate>
      <y_coordinate>358</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>0</param>
        <param>1</param>
        <param>0.1</param>
        <param>67</param>
      </params>
    </signal_block>
    <signal_block>
      <tag>Constellation Sink</tag>
      <id>Constellation Sink0</id>
      <x_coordinate>558</x_coordinate>
      <y_coordinate>314</y_coordinate>
      <rotation>0</rotation>
      <params>
        <param>Constellation</param>
        <param>100</param>
        <param>1000</param>
        <param>1</param>
        <param>0</param>
        <param>2.0</param>
        <param>2.0</param>
      </params>
    </signal_block>
  </signal_blocks>
  <connections>
    <connection>
      <input_signal_block_id>Constellation Sink0</input_signal_block_id>
      <input_socket_index>0</input_socket_index>
      <output_signal_block_id>Add0</output_signal_block_id>
      <output_socket_index>0</output_socket_index>
    </connection>
    <connection>
      <input_signal_block_id>Add0</input_signal_block_id>
      <input_socket_index>0</input_socket_index>
      <output_signal_block_id>Chunks to Symbols0</output_signal_block_id>
      <output_socket_index>0</output_socket_index>
    </connection>
    <connection>
      <input_signal_block_id>Add0</input_signal_block_id>
      <input_socket_index>1</input_socket_index>
      <output_signal_block_id>Noise Source0</output_signal_block_id>
      <output_socket_index>0</output_socket_index>
    </connection>
    <connection>
      <input_signal_block_id>Trellis Encoder0</input_signal_block_id>
      <input_socket_index>0</input_socket_index>
      <output_signal_block_id>Random Source0</output_signal_block_id>
      <output_socket_index>0</output_socket_index>
    </connection>
    <connection>
      <input_signal_block_id>Chunks to Symbols0</input_signal_block_id>
      <input_socket_index>0</input_socket_index>
      <output_signal_block_id>Trellis Encoder0</output_signal_block_id>
      <output_socket_index>0</output_socket_index>
    </connection>
  </connections>
</flow_graph>
------------------------------------------------------------------------

#!/usr/bin/env python

from gnuradio import gr
from gnuradio import trellis
from gnuradio import eng_notation
from gnuradio.wxgui import stdgui, fftsink, waterfallsink, scopesink, form, 
slider

import math
import sys
import random
import wx


class app_flow_graph(stdgui.gui_flow_graph):
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__(self)

        self.frame = frame
        self.panel = panel

        # TX
        Kb=100
        packet = [0]*Kb
        f=trellis.fsm('awgn1o2_4.fsm') # get the FSM specification from a file
        for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
                packet[i] = random.randint(0, 1) # random 0s and 1s
        self.src = gr.vector_source_s(packet,True)
        self.enc = trellis.encoder_ss(f,0) # initial state = 0
        self.mod = gr.chunks_to_symbols_sc((1,1j,-1,-1j),1)
        
        # CHANNEL
        self.add = gr.add_cc()
        self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,math.sqrt(0.1/2),-666)
        
        # RX
        #metrics = 
trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) 
# data preprocessing to generate metrics for Viterbi
        #va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states 
are not set.
        #dst=gr.null_sink(gr.sizeof_gr_complex);
        
        samp_rate=1000
        self.throttle = gr.throttle(gr.sizeof_gr_complex, samp_rate)
        self.dst = scopesink.scope_sink_c(self, panel, sample_rate=samp_rate,
                                    frame_decim=1,
                                    size=100,
                                    v_scale=2,
                                    t_scale=2)
        self.dst.win.info.xy = True
        self.dst.win.set_format_plus()
        vbox.Add(self.dst.win, 10, wx.EXPAND)

        self.connect (self.src,self.enc,self.mod)
        self.connect (self.mod,(self.add,0))
        self.connect (self.noise,(self.add,1))
        self.connect (self.add,self.throttle,self.dst)

        return




def main(args):
    app = stdgui.stdapp(app_flow_graph, "Test Encoder", nstatus=1)
    app.MainLoop()


if __name__ == '__main__':
    main (sys.argv[1:])
------------------------------------------------------------------------

2 4 4

0 2
0 2
1 3
1 3

0 3
3 0
1 2
2 1

AWGN CC from Proakis-Salehi pg 779
GM1o2_4=[1+D^2, 1+D+D^2] = [5, 7] (in decimal);

PNG image

"""
GNU Radio Companion is a graphical interface into the GNU Radio project.
Copyright (C) 2007 Josh Blum

GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""
"""
        Trellis/Misc.py 
        Josh Blum
"""

from DataType import *
from gnuradio import gr
from SignalBlockDefs import *


def Encoder(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte-->Byte', (trellis.encoder_bb, Byte(),Byte())),
                     ('Byte-->Short', (trellis.encoder_bs, Byte(),Short())),
                     ('Byte-->Int', (trellis.encoder_bi, Byte(),Int())),
                     ('Short-->Short', (trellis.encoder_ss, Short(),Short())),
                     ('Short-->Int', (trellis.encoder_si, Short(),Int())),
                     ('Int-->Int', (trellis.encoder_ii, Int(),Int())),
                     ],3)
        sb.add_input_socket('in', Variable(type, index=1))
        sb.add_output_socket('out', Variable(type, index=2))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Initial State', Int())
        sb.set_docs('''Trellis Encoder. For the time being the underlying FSM 
can only be read from a file...''')
        def make(fg, type, filename, s0):
                fsm=trellis.fsm(filename.parse()) # not sure if this is the 
right way to do this...
                block = type.parse()[0](fsm, s0.parse())
                return block
        return sb, make




def Metrics(sb):
        from gnuradio import trellis
        type = Enum([('Complex', (trellis.metrics_c, Complex())),
                     ('Float', (trellis.metrics_f, Float())),
                     ('Int', (trellis.metrics_i, Int())),
                     ('Short', (trellis.metrics_s, Short())),],1)
        sb.add_input_socket('in', Variable(type, index=1))
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('Output cardinality', Int())
        sb.add_param('Dimensionality', Int())
        sb.add_param('Constellation', FloatVector())
        sb.add_param('Metric Type', 
              Enum([('Euclidean', trellis.TRELLIS_EUCLIDEAN),
                    ('Hard Symbol', trellis.TRELLIS_HARD_SYMBOL),
                    ('Hard Bit', trellis.TRELLIS_HARD_BIT)],0))
        sb.set_docs('''Generate the metrics block from gr-trellis.''')
        def make(fg, type, O, D, Con, MetrType):
                block = type.parse()[0](O.parse(), D.parse(), Con.parse(), 
MetrType.parse())
                return block
        return sb, make


def Viterbi(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte', (trellis.viterbi_b, Byte())),
                     ('Short', (trellis.viterbi_s, Short())),
                     ('Int', (trellis.viterbi_i, Int())),
                     ],1)
        sb.add_input_socket('in', Float())
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Length', Int())
        sb.add_param('Initial State', Int())
        sb.add_param('Final State', Int())
        sb.set_docs('''Viterbi Decoder. FSM is specified through its filename 
only...''')
        def make(fg, type, filename, K, s0, sK):
                fsm=trellis.fsm(filename.parse())
                block = fcn[0](fsm, K.parse(), s0.parse(), sK.parse())
                return block
        return sb, make


def Viterbi_Combined(sb):
        import Constants
        from gnuradio import trellis
        type = Enum([('Byte', (trellis.viterbi_combined_b, Byte())),
                     ('Short', (trellis.viterbi_combined_s, Short())),
                     ('Int', (trellis.viterbi_combined_i, Int())),
                     ],1)
        sb.add_input_socket('in', Float())
        sb.add_output_socket('out', Variable(type, index=1))
        sb.add_param('Type', type, False, type=True)
        sb.add_param('File Path', FileOpen(Constants.DEFAULT_FILE_PATH))
        sb.add_param('Length', Int())
        sb.add_param('Initial State', Int())
        sb.add_param('Final State', Int())
        sb.add_param('Dimensionality', Int())
        sb.add_param('Constellation', FloatVector())
        sb.add_param('Metric Type',
              Enum([('Euclidean', trellis.TRELLIS_EUCLIDEAN),
                    ('Hard Symbol', trellis.TRELLIS_HARD_SYMBOL),
                    ('Hard Bit', trellis.TRELLIS_HARD_BIT)],0))

        sb.set_docs('''Viterbi Decoder combined with metric calculation. FSM is 
specified through its filename only...''')
        def make(fg, type, filename, K, s0, sK, D, Con, MetrType):
                fsm=trellis.fsm(filename.parse())
                block = type.parse()[0](fsm, K.parse(), s0.parse(), sK.parse(), 
D.parse(), Con.parse(), MetrType.parse())
                return block
        return sb, make


reply via email to

[Prev in Thread] Current Thread [Next in Thread]