2012年1月18日星期三

gnuradio code for USRP2 TX/RX

#pkt.py(define send_pkt function, send the payload, according to eof to tell whether to send more packets or not)

#packet_utils.py(make packet, build a packet, given access code, payload, and whitener offset)
#packet will have access code at the beginning, followed by length, payload and finally CRC32

self.connect(self._pkt_input, self._modulator, self)

self.connect(self, self._demodulator, self.correlator, self.framer_sink)

-----------------------------------------------------------------------------
dbpsk.py

"differential BPSK modulation and demodulation"

"input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband"

#function bits_per_symbol will return 1, so arity is 2
arity = powe(2, self.bits_per_symbol())

self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity])

--------------------------------------------
psk.py

# identity mapping, range(2) is start from 0(default), the end is 2, so it means [0, 1, 2]
binary_to_ungray = {
2 : range(2),
4 : range(4),
8 : range(8)
}

-----------------------------------------
//how the actual symbol mapping to constellations is done
gr_map_bb.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include
#include

gr_map_bb_sptr
gr_make_map_bb (const std::vector &map)
{
return gnuradio::get_initial_sptr(new gr_map_bb (map));
}

gr_map_bb::gr_map_bb (const std::vector &map)
: gr_sync_block ("map_bb",
gr_make_io_signature (1, 1, sizeof (unsigned char)),
gr_make_io_signature (1, 1, sizeof (unsigned char)))
{
for (int i = 0; i < 0x100; i++)
d_map[i] = i;

unsigned int size = std::min((size_t) 0x100, map.size());
for (unsigned int i = 0; i < size; i++)
d_map[i] = map[i];
}

int
gr_map_bb::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];

for (int i = 0; i < noutput_items; i++)
out[i] = d_map[in[i]];

return noutput_items;
}
-------------------------------------------

dbpsk.py

#symbol clock recovery

self.receiver=gr.mpsk_receiver_cc(arity, 0,
self._costas_alpha, self._costas_beta,
fmin, fmax,
self._mm_mu, self._mm_gain_mu,
self._mm_omega, self._mm_gain_omega,
self._mm_omega_relative_limit)

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

//Basically M-PSK modulations in GNU Radio utilize the function

gr_mpsk_receiver_cc.cc

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

use gr.file_sink() to dump all kinds of data in GNU Radio
The dumped data can be read from Matlab using some conversion codes

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

you need to make and make install when debugging, otherwise you don't add your new modifications to the library and install the library for the python code to access.

eg:
change gr_mpsk_receiver_cc.cc in gnuradio-core/src/lib/general/
change pkt.py in gnuradio-core/src/python/gnuradio/blks2impl

---------------------------------------------------------
benchmark_tx.py
benchmark_rx.py
usrp_transmit_path.py
usrp_receive_path.py
transmit_path.py
receive_path.py
pkt.py
packet_utils.py
dbpsk.py
dqpsk.py
gr_map_bb.cc


-------------------------------
tmr

1 trace dbpsk.py for connection with pkt.py

2 try code below

#!/usr/bin/env python

from gnuradio import gr, eng_notation, gru, window, blks2
from gnuradio import audio
from gnuradio import usrp
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from gnuradio import gr_unittest


class my_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
self.data = (1+2j, 3+4j, 5+6j)
self.src = gr.vector_source_c (self.data)
self.converte = gr.complex_to_float()
self.re_sink = gr.vector_sink_f ()
self.im_sink = gr.vector_sink_f ()
self.connect (self.src, (self.converte,0))
self.connect ((self.converte,0), self.re_sink)
self.connect((self.converte,1), self.im_sink)

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

print "src data: ", tb.data
print "real: ", tb.re_sink.data()
print "imag: ", tb.im_sink.data()

3 use --log of benchmark to see what .dat file can get

4 Q: if I have made one DQPSK transmission for image transfer and now I want to check the transmission and reception of the image at different SNR values. I am unable to find any signal block where i can change the SNR value .

A:
You will want to add a Gaussian noise source and a add block to add
AWGN, or you can use the channel_model block. To set the SNR, you will
first have to calculate the signal power in your simulation and from
their, determine the noise power for your desired SNR. The convert the
noise power to an amplitude, which is what the noise source block
takes. Look in gnuradio-examples/python/digital/benchmark_loopback.py
to see an example of these calculations.

discussion is from here
------------------------------------------------------------------

没有评论: