[Baypiggies] Fwd: array in python

harshal jadhav jadhav.harshal at gmail.com
Thu Oct 8 04:42:40 CEST 2009


Hi JC,

I am trying to implement space time coding on gnu radio.

I have a signal source generating sinusoidal wave.

The output of this signal source is the sampled version of sinusoidal wave.

I want to capture these samples in an array, so that i can group certain
number of samples and mark them as symbol S1 and similarly have symbol S2
gropu of other samples.

I have pyhton code which generates two sinusoidal signals and routes them
over two USRP boards which bears the antenna. one signal is routed through
daughterboard1 and other is routed through daughterboard2.

I want to trap the samples of the source signal before they enter the usrp
board.

*code :*
Transmit 2 signals, one out each daughterboard.

Outputs SSB (USB) signals on side A and side B at frequencies
specified on command line.

Side A is 600 Hz tone.
Side B is 350 + 440 Hz tones.
"""

from gnuradio import gr
from gnuradio.eng_notation import num_to_str, str_to_num
from gnuradio import usrp
from gnuradio import audio
from gnuradio import blks2
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from usrpm import usrp_dbid
import math
import sys


class example_signal_0(gr.hier_block2):
    """
    Sinusoid at 600 Hz.
    """
    def __init__(self, sample_rate):
        gr.hier_block2.__init__(self, "example_signal_0",
                                gr.io_signature(0, 0, 0),
# Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
# Output signature

        src = gr.sig_source_c (sample_rate,    # sample rate
                               gr.GR_SIN_WAVE, # waveform type
                               600,            # frequency
                               1.0,            # amplitude
                               0)              # DC Offset

        self.connect(src, self)


class example_signal_1(gr.hier_block2):
    """
    North American dial tone (350 + 440 Hz).
    """
    def __init__(self, sample_rate):
        gr.hier_block2.__init__(self, "example_signal_1",
                                gr.io_signature(0, 0, 0),
# Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
# Output signature

        src0 = gr.sig_source_c (sample_rate,    # sample rate
                                gr.GR_SIN_WAVE, # waveform type
                                350,            # frequency
                                1.0,            # amplitude
                                0)              # DC Offset

        src1 = gr.sig_source_c (sample_rate,    # sample rate
                                gr.GR_SIN_WAVE, # waveform type
                                440,            # frequency
                                1.0,            # amplitude
                                0)              # DC Offset
        sum = gr.add_cc()
        self.connect(src0, (sum, 0))
        self.connect(src1, (sum, 1))
        self.connect(sum, self)

class my_top_block(gr.top_block):

    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] side-A-tx-freq side-B-tx-freq"
        parser = OptionParser (option_class=eng_option, usage=usage)
        (options, args) = parser.parse_args ()

        if len(args) != 2:
            parser.print_help()
            raise SystemExit
        else:
            freq0 = str_to_num(args[0])
            freq1 = str_to_num(args[1])

        # ----------------------------------------------------------------
        # Set up USRP to transmit on both daughterboards

        self.u = usrp.sink_c(nchan=2)          # say we want two channels

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s

        # we're using both daughterboard slots, thus subdev is a 2-tuple
        self.subdev = (self.u.db[0][0], self.u.db[1][0])
        print "Using TX d'board %s" % (self.subdev[0].side_and_name(),)
        print "Using TX d'board %s" % (self.subdev[1].side_and_name(),)

        # set up the Tx mux so that
        #  channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
        self.u.set_mux(0xba98)

        self.subdev[0].set_gain(self.subdev[0].gain_range()[1])    # set max
Tx gain
        self.subdev[1].set_gain(self.subdev[1].gain_range()[1])    # set max
Tx gain

        self.set_freq(0, freq0)
        self.set_freq(1, freq1)
        self.subdev[0].set_enable(True)             # enable transmitter
        self.subdev[1].set_enable(True)             # enable transmitter

        # ----------------------------------------------------------------
        # build two signal sources, interleave them, amplify and connect
them to usrp

        sig0 = example_signal_0(self.usrp_rate)
        sig1 = example_signal_1(self.usrp_rate)

        intl = gr.interleave(gr.sizeof_gr_complex)
        self.connect(sig0, (intl, 0))
        self.connect(sig1, (intl, 1))

        # apply some gain
        if_gain = 10000
        ifamp = gr.multiply_const_cc(if_gain)

        # and wire them up
        self.connect(intl, ifamp, self.u)


    def set_freq(self, side, target_freq):
        """
        Set the center frequency we're interested in.

        @param side: 0 = side A, 1 = side B
        @param target_freq: frequency in Hz
        @rtype: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital up converter.
        """

        print "Tuning side %s to %sHz" % (("A", "B")[side],
num_to_str(target_freq))
        r = self.u.tune(self.subdev[side]._which, self.subdev[side],
target_freq)
        if r:
            print "  r.baseband_freq =", num_to_str(r.baseband_freq)
            print "  r.dxc_freq      =", num_to_str(r.dxc_freq)
            print "  r.residual_freq =", num_to_str(r.residual_freq)
            print "  r.inverted      =", r.inverted
            print "  OK"
            return True

        else:
            print "  Failed!"

        return False


if __name__ == '__main__':
    try:
        my_top_block().run()
    except KeyboardInterrupt:
        pass

Regards,
Harshal


On Wed, Oct 7, 2009 at 7:32 PM, JC Lawrence <claw at kanga.nu> wrote:

> Why don't we start at the other end and look at what the data actually is
> and what you need to be able to do with it?  The combination of the data's
> natural structure plus your access requirements will drive the choice of
> data-structure (and thus Python Modules etc).  What are you trying to deal
> with here, and what sorts of operations do you need to be able to do
> efficiently with it?
>
> -- JCL
>
>
> On 7 Oct 2009, at 19:23 , harshal jadhav wrote:
>
>  I am having the data in complex form...
>>
>> Regards,
>> Harshal
>>
>> On Wed, Oct 7, 2009 at 7:15 PM, Stephen McInerney <
>> spmcinerney at hotmail.com> wrote:
>>
>> Yes, NumPy is good for large datasets.
>>
>> Harshav - is the problem importing the data format, or what?
>> What formnat do you currently have it in?
>>
>>
>> > Date: Wed, 7 Oct 2009 19:05:25 -0700
>> > From: keith at dartworks.biz
>> > To: baypiggies at python.org
>> > Subject: Re: [Baypiggies] Fwd: array in python
>> >
>> > === On Wed, 10/07, harshal jadhav wrote: ===
>>
>> > > I am using python language for GNU Radio. For this i have a sampled
>> > > signal. The signal is a sine wave. I have to trap each sample of this
>> > > sine wave in an array.Is it possible to capture the samples of the
>> > > sine wave in  an array in python?
>> > ===
>> >
>> > Yes. You might also want to take a look at the numpy extension.
>> >
>> >
>> > -- Keith Dart
>> >
>> > --
>> > -- --------------------
>> > Keith Dart
>> > <keith at dartworks.biz>
>> > =======================
>> > _______________________________________________
>> > Baypiggies mailing list
>> > Baypiggies at python.org
>> > To change your subscription options or unsubscribe:
>> > http://mail.python.org/mailman/listinfo/baypiggies
>>
>> Hotmail: Trusted email with powerful SPAM protection. Sign up now.
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20091007/ad338898/attachment-0001.htm>


More information about the Baypiggies mailing list