[USRP-users] USRP1 and UHD rx_samples_to_file

Steven Clark steven.p.clark at gmail.com
Fri Nov 12 12:12:18 EST 2010


> What would the downside be of using STREAM_MODE_START_CONTINUOUS in this RX
>> app?
>>
>>
> That would work. I think the idea was to demonstrate requesting a specific
> number of samples. But you could just as easily read until n samples and
> then turn off streaming. With the first method (when applicable) you know
> that your queues are empty when all the samples have arrived. In the latter
> you will want to drain the rx queue before starting streaming again.
>
>
I took a stab at editing rx_samples_to_file to be USRP1 friendly. Flush recv
bufs before/after main loop, and use START_CONTINUOUS / STOP_CONTINUOUS.
Relevant code below:

     *std::cout << "Entry flush...";
    //flush the buffers in the recv path
    while(dev->recv(
        &buff.front(), buff.size(), md,
        uhd::io_type_t::COMPLEX_INT16,
        uhd::device::RECV_MODE_ONE_PACKET
    )){
        /* NOP */
    };
    std::cout << "done." << std::endl;*

    //setup streaming
    //uhd::stream_cmd_t
stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
    *uhd::stream_cmd_t
stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);*
    stream_cmd.num_samps = total_num_samps;
    stream_cmd.stream_now = true;
    sdev->issue_stream_cmd(stream_cmd);

    //loop until total number of samples reached
    size_t num_acc_samps = 0; //number of accumulated samples

    std::ofstream outfile(file.c_str(), std::ofstream::binary);

    *size_t num_samps_remaining = total_num_samps;*

    while(num_acc_samps < total_num_samps){

        size_t num_rx_samps = dev->recv(
            &buff.front(), *std::min(buff.size(), num_samps_remaining)*, md,
            uhd::io_type_t::COMPLEX_INT16,
            uhd::device::RECV_MODE_ONE_PACKET
        );

        std::cout << "Got " << num_rx_samps << " samps" << std::endl;

        [...]

        //write complex short integer samples to the binary file
        outfile.write((const char*)&buff[0], num_rx_samps *
sizeof(std::complex<short>));

        num_acc_samps += num_rx_samps;
       * num_samps_remaining -= num_rx_samps;*

        //std::cout << num_acc_samps << std::endl;
    } done_loop:

   * sdev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
*

   * std::cout << "Exit flush...";
    //flush the buffers in the recv path
    while(dev->recv(
        &buff.front(), buff.size(), md,
        uhd::io_type_t::COMPLEX_INT16,
        uhd::device::RECV_MODE_ONE_PACKET
    )){
        /* NOP */
    };
    std::cout << "done." << std::endl;
*

I compile with*:
*g++ rx_to_file_alt.cpp -L/opt/uhd/lib -luhd -lboost_program_options-mt
-lboost_thread-mt -o rx_to_file_alt -I../uhd/host/include

Run with:
./rx_to_file_alt --nsamp=100000 --rate=0.5e6 --freq=433e6 --gain=0
--file=test.bin

Output:
linux; GNU C++ version 4.4.4 20100630 (Red Hat 4.4.4-10); Boost_104100;
UHD_20101109.230702.c0dfc2c


Creating the usrp device with: ...
Using Device: Single USRP:
  Device: usrp1 device
  Mboard: usrp1 mboard - 4c7560d7
  RX DSP: usrp1 ddc 2X + hb
  RX Channel: 0
    RX Dboard: usrp1 dboard (rx unit) - A
    RX Subdev: WBX (0x0053)
  TX DSP: usrp1 duc 2X
  TX Channel: 0
    TX Dboard: usrp1 dboard (tx unit) - A
    TX Subdev: WBX (0x0052)

Setting RX Rate: 0.500000 Msps...
Actual RX Rate: 0.500000 Msps...

Setting RX Freq: 433.000000 Mhz...
Actual RX Freq: 433.000000 Mhz...

Setting RX Gain: 0.000000 dB...
Actual RX Gain: 0.000000 dB...

LO Locked = 1
Entry flush...done.
Got 4096 samps
Got 4096 samps
Got 4096 samps
Got 4096 samps
[...]
Got 4096 samps
Got 4096 samps
Got 4096 samps
Got 1696 samps
Exit flush...done.

Done!


The amount of data written to the file is correct. HOWEVER, the output
written to test.bin looks wrong. It is mostly in range [-4,4], with some
large amplitude junk at the beginning of the capture. I don't see anything
resembling a sine wave. When I capture with the same input using GNURadio, I
see a nice fat sine wave as expected. Any ideas?

-Steven
**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20101112/c2fa8b70/attachment-0002.html>


More information about the USRP-users mailing list