# Re: sign\_extend.v!

**URL:** <https://www.ruby-forum.com/t/re-sign-extend-v/204482>\
**Category:** GNU Radio\
**Created:** [March 14, 2011, 4:17am UTC](https://www.ruby-forum.com/t/re-sign-extend-v/204482 "2011-03-14T04:17:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 14, 2011, 4:17am UTC](https://www.ruby-forum.com/t/re-sign-extend-v/204482/1 "2011-03-14T04:17:00Z")

</div>

> -----Original Message-----  
> From: Josh B. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
> Sent: Sunday, March 13, 2011 10:52 PM  
> To: removed\_email\_address@domain.invalid  
> Subject: Re: [Discuss-gnuradio] sign\_extend.v !!!
> 
> [Sign extension - Wikipedia](http://en.wikipedia.org/wiki/Sign_extension)

\<website that explains what it means to sign extend - this is what this  
module does - more detailed explanation as to how it does it appears  
below\>

> On 03/13/2011 07:47 PM, Alaa Salaheldin wrote:
> 
> > Can anyone please help me to understand what’s going on in sign\_extend.v ,  
> > this macro is initiated in the cic\_decim.v
> > 
> > sign\_extend #(bw,bw+maxbitgain)  
> > ext\_input (.in(signal\_in),.out(signal\_in\_ext));

instantiates the sign\_extend module. Positional parameter settings  
“#(bw, bw + maxbitgain)” will be assigned to bits\_in and bits\_out,  
respectively.

> > when i opened the macro i couldn’t understand it’s function
> > 
> > // Sign extension “macro”  
> > // bits\_out should be greater than bits\_in
> > 
> > module sign\_extend (in,out);

module with 2 ports: in & out

> > parameter bits\_in=0; // FIXME Quartus insists on a default  
> > parameter bits\_out=0;  
> > input [bits\_in-1:0] in;

size of input port “in” is determined by “bits\_in”

> > output [bits\_out-1:0] out;

size of output port “out” is determined by “bits\_out”

> > assign out = {{(bits\_out-bits\_in){in[bits\_in-1]}},in};

this expression assigns a value to out using both concatenation &  
replication

{(bits\_out-bits\_in){in[bits\_in-1]}} replicates in’s MSB (bits\_out -  
bits\_in) times. This value is then prepended (via concatenation) to in.

Voila! Sign extension implemented in verilog and explained in the  
webpage Josh pointed to above.

> > endmodule
> > 
> > Thanks in advance.

Hope this helps,

–Bob

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 14, 2011, 10:52pm UTC](https://www.ruby-forum.com/t/re-sign-extend-v/204482/2 "2011-03-14T22:52:48Z")

</div>

I am trying to run this script available at

[http://swigerco.com/gnuradio/ate/](http://swigerco.com/gnuradio/ate/)

to sweep through several frequencies and to log the data. However  
running the script gives me an error regarding the “import usrp\_siggen”  
(I am attaching some of code below, the error is “no module named  
usrp\_siggen.py”).

What might be done to fix this?

Best regards,  
-Vijay

* * *

initial portion of the code

import wx  
import usrp\_siggen  
from gnuradio import gr  
from gnuradio import usrp  
from gnuradio.eng\_option import eng\_option  
from optparse import OptionParser  
from gnuradio import eng\_notation  
import math

ID\_ABOUT = wx.NewId()  
ID\_EXIT = wx.NewId()  
ID\_STARTFREQ = wx.NewId()  
ID\_STEPFREQ = wx.NewId

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 15, 2011, 12:24am UTC](https://www.ruby-forum.com/t/re-sign-extend-v/204482/3 "2011-03-15T00:24:49Z")

</div>

On 03/14/2011 02:52 PM, Vijay P. wrote:

> I am trying to run this script available at
> 
> [Automatic Testing - Sweep Generator](http://swigerco.com/gnuradio/ate/)
> 
> to sweep through several frequencies and to log the data. However running the  
> script gives me an error regarding the “import usrp\_siggen” (I am attaching some  
> of code below, the error is “no module named usrp\_siggen.py”).
> 
> What might be done to fix this?

I think you need to copy usrp\_siggen.py from the gnuradio tree into your  
PYTHONPATH or into the working directory of your application.

-JOsh
