Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20689 Discussions

Exponential function in vhdl

Altera_Forum
Honored Contributor II
4,502 Views

hiii 

I want to implement exp(x.^2) in VHDL for synthesis. 

Can any one suggest how to do it. Here x is in signed format and i want result in fixed point arithmatic i.e. without rondoff operation. 

Is there any instruction like in MATLAB 'exp' is there . 

Thanks and regards!
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
2,420 Views

For exponential, you will need to create a look up table filled with all the results. 

The address input of the LUT is x and the output is your function.
0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

 

--- Quote Start ---  

For exponential, you will need to create a look up table filled with all the results. 

The address input of the LUT is x and the output is your function. 

--- Quote End ---  

 

Thank you Tricky for your reply. May be I can write this lookup table in a package and call it for places where I need exponential function. If you have any sample program then please share.
0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

I suggest NOT writing a function to do it - vhdl is a hardware description language, NOT a proramming language. You need to understand what hardware will be produced before you write any code.

0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

You can use matlab/python/tcl or whatever language you prefer to write a program that generates a source file for your lookup table.

0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

How can I generate sourse file for my lookup table by using MATLAB. Are you taking about HDL coder. I tried it but it doesnot accept "exp" function.

0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

If not function then should I write any package for exp. Sorry I havent written any lookup table before so I dont know. And actually I want to design a Gaussian filter with variable window size & sigma value. For that I am using two 1D gaussian.  

So the part I want to impliment is 

Gauss= exp^(-(x^2)/2*(sigma)^2); 

here sigma will vary from 0.1 to 5. 

and x is a vector =[-2 -1 0 1 2] for length equal to 5. I want to vary length also. How to do it.please help me with this. If you know any book for these type of operation then please suggest.
0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

I highly suggest you learn about digital design. What you are going to create is a ROM - a read only memory. This can be done in VHDL using a constant which can be initialised from a function, a specified constant or a .mif file. you can have matlab generate the values to go into the constant. 

There are plenty of examples out on the web.
0 Kudos
Altera_Forum
Honored Contributor II
2,420 Views

 

--- Quote Start ---  

If not function then should I write any package for exp. Sorry I havent written any lookup table before so I dont know. And actually I want to design a Gaussian filter with variable window size & sigma value. For that I am using two 1D gaussian.  

So the part I want to impliment is 

Gauss= exp^(-(x^2)/2*(sigma)^2); 

here sigma will vary from 0.1 to 5. 

and x is a vector =[-2 -1 0 1 2] for length equal to 5. I want to vary length also. How to do it.please help me with this. If you know any book for these type of operation then please suggest. 

--- Quote End ---  

 

 

Any equation can be implemented in fpga as LUT either fully or partially. In the partial case you do in fpga what is doable and then use LUT. 

In your case I suggest: 

get x^2 in fpga (x * x), one multiplier 

get 2* sigma^2 in fpga, one multiplier and add one zero lsb 

truncate above results to suitable bitwidth 

divide -x2/(2*sigma^2) in fpga if you can afford a divider, else include this section within LUT 

finally get LUT for your exp in software e.g. matlab and put it in a rom 

 

To get LUT of exp: 

you need to know range of your result. then just calculate exp of that range in suitable steps and rounded to your rom bitwidth 

Then in fpga address LUT with actual fpga result.
0 Kudos
Reply