# Gain and Sample Rate Setting

**URL:** <https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185>\
**Category:** GNU Radio\
**Created:** [August 30, 2015, 11:05pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185 "2015-08-30T23:05:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [August 30, 2015, 11:05pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/1 "2015-08-30T23:05:00Z")

</div>

Hello all,  
I have XCVR2450 USRP’s. I have been trying to send the data between two  
USRP’s. I have made some changes to the python code in uhd\_interface.py  
where I have changed the gain to 25 and set the frequency for  
transmitter and receiver to 2.435G. I have run uhd\_fft program only to  
find that my sample rate of 50k is not being supported. I am unable to  
know how to set the sample rate and sps for my device. Because of that,  
I have been receiving some errors like

ok = False pktno = 88 n\_rcvd = 1 n\_right = 0  
ok = False pktno = 105 n\_rcvd = 2 n\_right = 0  
ok = False pktno = 49227 n\_rcvd = 3 n\_right = 0  
ok = False pktno = 117 n\_rcvd = 4 n\_right = 0  
ok = False pktno = 121 n\_rcvd = 5 n\_right = 0  
ok = False pktno = 122 n\_rcvd = 6 n\_right = 0  
ok = False pktno = 126 n\_rcvd = 7 n\_right = 0

I also have attached a graph of uhd\_fft program. I think I have got a  
wave which represents a transmission gain of 25 and received gain of 15  
because I have specified it in the uhd\_interface.py program. Please  
advice as to where I can change these settings so that I might be able  
to receive packet in a right order. Thank you

Regards,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 12:06am UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/2 "2015-08-31T00:06:07Z")

</div>

Hi,  
what Jeon writes is correct so far, but two comments:

> You can check XCVR2450’s dsp rate

XCVR2450 is your daughterboard, not your USRP. The mainboard has a  
master clock rate. 100M is a good example, because it’s the MCR of the  
USRP N2x0.

> But in case of LFTX, LFRX, it is 200k.

As explained above, it’s not a feature of the daughterboard, but of your  
USRP. My assumption would be the minimum rate for you is 100M/512 =  
192.something kHz

And as Jeon pointed out, you should see a warning on the console, saying  
which sampling rate was actually used.  
Now, I’m not quite sure what tools you’re using that use the  
uhd\_interface.uhd\_transmitter and uhd\_interface.uhd\_receiver, but if  
it’s one of the benchmark\_\* scripts, you will need to adjust symbol rate  
or samples\_per\_symbol, or likely both, to yield a valid sampling rate.

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 30, 2015, 11:43pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/3 "2015-08-30T23:43:55Z")

</div>

Note before the text: my answer might have some incorrect terminologies.

I am unable to know how to set the sample rate and sps for my device.

> 

1. DSP rate should be an integer multiple of sampling rate

You can check XCVR2450’s dsp rate by `uhd_usrp_probe` command. Let’s say  
it  
is 100M (not a true value!)  
If you set sampling rate to 30k, 100M/30k = 3.333k, not an integer

1. There is some lower limit of sampling rate

Since I’ve never used XCVR2450, I don’t know the exact value of it.  
But in case of LFTX, LFRX, it is 200k.  
If 50k that you’ve set is below such lower limit, you can see warning  
message on the console.

Regards,  
Jeon.

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 12:15am UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/4 "2015-08-31T00:15:21Z")

</div>

Hi,  
Thanks for the advice. I am sorry that I didn’t understand what you have  
said. So what you suggest is that I need to make some changes to the  
benchmark scripts. But I have changed gain and frequency already in the  
uhd\_interface program. Do i need to use the gnuradio-companion for  
uhd\_interface program? Because, I am giving all the commands in the  
terminal itself. Please suggest me further. Excuse me if I am asking  
some noob doubts because I am new to gnuradio.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 1:15am UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/5 "2015-08-31T01:15:04Z")

</div>

Besides the problem I had above, there seems to be a new one. Till that  
day, I used to get some output, but today, when I tried to run the  
./benchmark\_tx.py -f 2.435G command, I am getting the following error

Traceback (most recent call last):  
File “./benchmark\_tx.py”, line 147, in   
main()  
File “./benchmark\_tx.py”, line 111, in main  
tb = my\_top\_block(mods[options.modulation], options)  
File “./benchmark\_tx.py”, line 49, in **init**  
options.antenna, options.verbose)  
File  
“/usr/local/share/gnuradio/examples/digital/narrowband/uhd\_interface.py”,  
line 135, in **init**  
freq, gain, antenna)  
File  
“/usr/local/share/gnuradio/examples/digital/narrowband/uhd\_interface.py”,  
line 62, in **init**  
self.\_rate, self.\_sps = self.set\_sample\_rate(bitrate, sps)  
File  
“/usr/local/share/gnuradio/examples/digital/narrowband/uhd\_interface.py”,  
line 70, in set\_sample\_rate  
asked\_samp\_rate = bitrate \* req\_sps  
TypeError: unsupported operand type(s) for \*: ‘float’ and ‘NoneType’

But the receiver is working just fine. I don’t know what mistake is  
present in my benchmark transmission file. Please help me with this. I  
am attaching the same benchmark scripts.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 11:16pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/6 "2015-08-31T23:16:44Z")

</div>

Please Help with this problem.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 11:35pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/7 "2015-08-31T23:35:44Z")

</div>

On 30.08.2015 16:15, Ben Gustin wrote:

> File  
> “/usr/local/share/gnuradio/examples/digital/narrowband/uhd\_interface.py”,  
> line 70, in set\_sample\_rate  
> asked\_samp\_rate = bitrate \* req\_sps  
> TypeError: unsupported operand type(s) for \*: ‘float’ and ‘NoneType’

This is what you want to track down. See what req\_sps is in the file  
mentioned above, and where it’s set.  
If your receiver is working, this seems like some simple Python bug.

> But the receiver is working just fine. I don’t know what mistake is  
> present in my benchmark transmission file. Please help me with this. I  
> am attaching the same benchmark scripts.

If you want to attach files, I suggest you subscribe to the mailing list  
instead of using ‘ruby forum’. Most people handle the mailing list in  
this way.

Cheers,  
Martin

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [August 31, 2015, 11:59pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/8 "2015-08-31T23:59:18Z")

</div>

Thank you for the reply Martin. I have checked the benchmark\_tx.py and  
uhd\_interface.py script and the text in the file is

```
def set_sample_rate(self, bitrate, req_sps):
    start_sps = req_sps
    while(True):
        asked_samp_rate = bitrate * req_sps
        self.u.set_samp_rate(asked_samp_rate)
        actual_samp_rate = self.u.get_samp_rate()

        sps = actual_samp_rate/bitrate
        if(sps < 2):
            req_sps +=1
        else:
            actual_sps = sps
            break

```

So when I remove ‘req’, it’s showing the error

UnboundLocalError: local variable ‘sps’ referenced before assignment.

How to deal with this? Please help

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:17am UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/9 "2015-09-01T10:17:10Z")

</div>

Hi Ben,

you will have to inspect the error, and it will tell you that the  
“options” object has no attribute “lo\_offset”. This means that the  
script tries to access member of the options variable that isn’t there.  
Also, this allowed me to find out which benchmark\_tx (there’s two in GNU  
Radio) you’re working with.

This is a bit strange, because the option “–lo-offset” is definitely  
there, added by uhd\_transmitter.add\_options. Having had a look at the  
file you uploaded to ruby-forum (please PLEASE don’t use ruby-forum), it  
is really missing these lines that add the “–lo-offset” option. These  
were added in 2013. Is it possible that you use a modern  
narrowband/benchmark\_tx.py with a narrowband/uhd\_interface.py from  
before 2013?

All in all, only you have worked with your code; I think it will really  
really pay if you work yourself through these errors to figure out  
what’s wrong – if you didn’t mix up versions like I suspected above, I  
have no idea what goes wrong, and you can’t keep coming back to the  
mailing list with every single Python error. Doing this “the hard way”  
yourself will have a lot of benefits for you: You will be faster overall  
(because I’m pretty sure this is not the last python problem you’ll  
encounter), because you won’t have to rely and wait on other people  
reading your error messages, and simultaneously you’ll develop the  
skills necessary to write your own python code.

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:15pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/10 "2015-09-01T22:15:49Z")

</div>

You should just use matching versions of these files… kind of  
obviously.  
I wonder how this mix up happened; generally, you should just use the  
versions of things as they come with exactly your GNU Radio  
installation; probably, these files are under  
/usr/share/gnuradio/examples/digital or so.

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 9:51pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/11 "2015-09-01T21:51:29Z")

</div>

Thanks for the reply Marcus. It seems that you were right about my  
mixing up different versions of the script files. So I guess that I need  
to add any program lines in my script to remove that error is there any  
other way? Please help with this one issue. And I will work towards the  
python codes as you suggested.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:29pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/12 "2015-09-01T22:29:18Z")

</div>

So I need to uninstall and install gnuradio for making this work again  
or I can download the files from the internet. Thanks for the help

Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:41pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/13 "2015-09-01T22:41:43Z")

</div>

I am sorry to have misunderstood you. I am sorry to bother you like  
this. I got the point now. So do I need to install the GNU radio again  
for this mix-up not to happen?

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:35pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/14 "2015-09-01T22:35:07Z")

</div>

You misunderstood me.  
The files should be _part of your GNU Radio installation_, and you  
should use these (and no others).

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![hailandkill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@hailandkill](https://www.ruby-forum.com/u/hailandkill)\
**Post date:** [September 1, 2015, 10:53pm UTC](https://www.ruby-forum.com/t/gain-and-sample-rate-setting/243185/15 "2015-09-01T22:53:14Z")

</div>

> So do I need to install the GNU radio again  
> No, as I said. These files /come with GNU Radio/, and I’m assuming you  
> did not go ahead and use root privileges to overwrite the originals. You  
> just need to take the originals (probably in  
> /usr/share/gnuradio/examples/digital), and copy them to wherever you  
> want to work with them.

I can’t, however, tell whether you’ve intentionally modified the files  
under /usr/share… ; that’s something you know, not I 🙂

Also, as I have already asked you: please stop using Ruby-forum, and  
sign up under

> **[Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)**

Ruby forum just guesses to which email you’re replying, so everyone else  
gets your emails in strange thread hierarchies, and it’s nearly  
impossible to follow discussions on the mailing list with you.

Best regards,  
Marcus
