For the tanh verilog code, first we need to understand the basic about it and where we are applying it.

for understanding and plotting we will take from matlab platform.

lets say, X is vary from -5 to 5 so its tanh values and its plot as

x = -5:1:5;
tanh_val=tanh(x);
plot(tanh_val), grid on

from this figure it is shown that the range of tanh is from -1 to 1, logically every trigonometry function has range -1 to 1.

for better representation of the same we take one more range for plot

x = -15:1:15;
tanh_val=tanh(x);
plot(tanh_val), grid on

One more conclution we can draw from this plot for any value of x which is > -+6 would result in -1 and +1, as

tanh(-6) ~ -1 and   tanh(+6) ~ +1, so the important range of x is between -6 to +6.

If your input to tanh is in this range then its ok, else you have to map your input in to this range. Let it be we will see what we can do about it in later time.

so, for the verilog code. we can use ROM for storing these tanh function values. For that we need to convert it in to hex either into floating or fixed point, following code shows the conversion for Q16.16 format for hex values.

%%
x = -5:10/1024:5-(10/1024); % 1024 is the depth of ROM , 
act_val=tanh(x);
plot(act_val), grid on

struct.mode = ‘fixed’;
struct.roundmode = ‘ceil’;
struct.overflowmode = ‘saturate’;
struct.format = [32 16];
q = quantizer(struct);
t = [];
formatSpec = ‘%+2.4f\n’;
%——————————–
for pnty=1:size(x,2)
t1 = dec2hex(bin2dec(num2bin(q,act_val(pnty))),8)
t = [t ; t1 ‘ //’ num2str(act_val(pnty),formatSpec)];
end

%——————————————–

t variable contains the all ROM entries , you can use these values for memory file for ROM. z_act_fun_file.hex


module z_act_fun
(
input [9:0] addr,
output signed [31:0] data
);

reg [31:0] mem [0:1023]; // 1024 locations of 32-bit data

initial begin
$readmemh(“z_act_fun_file.hex”, mem); // Read memory initialization data from file
end

assign data = mem[addr];

endmodule


As we said we need to take care of rang, if there is need of rang mapping, please ref the link http://learnwebgl.brown37.net/08_projections/projections_mapping.html

Given a value p in the range A to B, calculate a point q in the range C to D that is in the same relative place.

  • Solution 1:
    • Since scaling is always relative to the origin, and we need to scale the range from A to B to make it the same size as the range C to D, let’s shift the range A to B to the origin. We can do this by subtracting A from p. p-A
    • Scale p by the ratio of the range sizes, (D-C)/(B-A). (p-A)*(D-C)/(B-A)
    • Now shift this value to the start of the C to D range by adding C. Therefore, our equation is q = (p-A)*(D-C)/(B-A) + C
  • Solution 2:
    • Because the relationship between the points p and q must maintain relative distances, the ratio of their distances must be equal to the ratio of the range sizes. Therefore, (p-A)/(q-C) = (B-A)/(D-C)
    • If you solve this equation for q, you get q = (p-A)*(D-C)/(B-A) + C

If you rearrange the terms in this equation, you end up with a scale factor and an offset. Specially,

scale = (D-C)/(B-A)
offset = -A*(D-C)/(B-A) + C
q = p*scale + offset

Let’s work a specific example. We want to take the values between 12 and 22 and map them into a range from 6 to 7. The ratio between these two ranges is (7-6)/(22-12) = 1/10. The offset is -12*(1/10) + 6 = 4.8. Our linear mapping formula become `q = p*(1/10) + 4.8. If you apply the formula to all the whole numbers in the range 12 to 22, you get equally spaced values in the range 6 to 7, as shown below.

Linear Mapping
12 13 14 15 16 17 18 19 20 21 22
6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7
Hope you clear about it, Please do comment, will reply with in 24hrs.

 

 

 

 

 

By admin

124 thoughts on “verilog tanh code”
  1. Howⅾy very cool site!! Man .. Excellent .. Superb
    .. I will bookmark your blog and take the feedѕ additionally?

    I am happy to search oᥙt numerous helpful info here
    іn the рut up, we neеd develop extra techniques on this regard, thanks for sharing.
    . . . . .

    Here is my sitе … Dewa99

  2. Hello, Neat post. There is a problem together with your site in internet explorer, may
    check this? IE nonetheless is the market leader and a large part of other folks will
    leave out your fantastic writing due to this problem.

  3. I’m impressed, I must say. Rarely do I encounter a blog that’s both equally educative and entertaining, and let me
    tell you, you’ve hit the nail on the head. The problem is an issue that not
    enough men and women are speaking intelligently about.
    I’m very happy I came across this during my hunt for
    something concerning this.

    Here is my site … berufbekleidung pflege

  4. Appreciating the persistence you put into your site and detailed information you present. It’s great to come across a blog every once in a while that isn’t the same outdated rehashed information. Wonderful read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.

  5. Good post. I learn something totally new and challenging on sites I
    stumbleupon on a daily basis. It’s always interesting to read
    content from other writers and use something
    from their web sites.

  6. Hey! Would you mind if I share your blog with my twitter group?
    There’s a lot of folks that I think would really appreciate your content.
    Please let me know. Many thanks

  7. Its like you read my mind! You seem to know
    a lot about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive the message home a little bit, but other than that, this is fantastic
    blog. A great read. I will definitely be back.

  8. I like this post, enjoyed this one thanks for posting. “Good communication is as stimulating as black coffee and just as hard to sleep after.” by Anne Morrow Lindbergh.

  9. An intriguing discussion is definitely worth comment.
    There’s no doubt that that you should write
    more about this topic, it might not be a taboo matter but usually folks don’t discuss
    such topics. To the next! Cheers!!

  10. Simply wish to say your article is as astonishing.
    The clarity in your post is just excellent and i could assume you’re an expert on this subject.

    Well with your permission allow me to grab your
    feed to keep up to date with forthcoming post. Thanks a million and
    please carry on the rewarding work.

  11. Great goods from you, man. I’ve bear in mind your stuff
    previous to and you’re simply too great. I really like what you have got here, certainly like what you’re stating and the way wherein you assert it.

    You make it entertaining and you still take care of to keep it smart.
    I can not wait to learn far more from you. That is actually a wonderful website.

  12. Excellent website you have here but I was wanting to know if you
    knew of any forums that cover the same topics talked about in this article?
    I’d really love to be a part of group where I can get feedback from
    other experienced people that share the same interest.
    If you have any suggestions, please let me know. Thanks!

  13. I must thank you for the efforts you have put in writing this blog.
    I really hope to see the same high-grade blog posts by you in the future as well.
    In truth, your creative writing abilities has inspired me to get
    my very own site now 😉

  14. Definitely believe that which you said. Your favorite justification appeared to be at the internet the
    simplest thing to take note of. I say to you, I certainly get
    irked even as people consider worries that they just don’t realize
    about. You managed to hit the nail upon the top and also
    outlined out the whole thing without having side effect
    , folks could take a signal. Will likely be again to get more.

    Thank you

  15. Helpful info. Lucky me I found your web site unintentionally, and I am surprised why this accident didn’t happened in advance!
    I bookmarked it.

  16. Today, I went to the beach with my children. I
    found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear. She never wants to go back!
    LoL I know this is completely off topic but I had to tell someone!

  17. I’ve learn a few good stuff here. Definitely worth bookmarking for revisiting. I surprise how much attempt you set to create this kind of magnificent informative web site.

  18. Hello! This is kind of off topic but I need some guidance from an established blog.
    Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about creating my own but I’m not
    sure where to start. Do you have any tips or suggestions?
    Cheers

  19. When someone writes an paragraph he/she maintains the idea
    of a user in his/her mind that how a user can know it.
    So that’s why this article is amazing. Thanks!

  20. Every weekend i used to go to see this site, for the reason that
    i wish for enjoyment, for the reason that this this site conations
    truly good funny information too.

  21. Howdy! I’m at work surfing around your blog from my new iphone 3gs!
    Just wanted to say I love reading through your blog and look forward to all your posts!
    Keep up the excellent work!

  22. We’re a bunch of volunteers and opening a brand new scheme in our community.
    Your website provided us with useful information to work on. You
    have performed a formidable process and our entire group will be grateful to
    you.

  23. Hello There. I discovered your weblog the use of msn. This is an extremely neatly written article.
    I’ll make sure to bookmark it and come back to learn more of your helpful information. Thank you
    for the post. I will certainly return.

  24. At this time it appears like Drupal is the best blogging platform out there right now.
    (from what I’ve read) Is that what you’re using on your blog?

  25. This design is spectacular! You obviously know how to keep
    a reader entertained. Between your wit and your videos,
    I was almost moved to start my own blog (well, almost…HaHa!) Wonderful job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  26. Useful information. Lucky me I discovered your site by
    accident, and I’m surprised why this twist of fate did not took place in advance!

    I bookmarked it.

  27. After going over a few of the articles on your web page,
    I seriously like your way of blogging. I saved as a favorite
    it to my bookmark site list and will be checking back
    soon. Take a look at my web site as well and tell me how
    you feel.

  28. What’s up, this weekend is pleasant in favor of me, because this occasion i am reading this wonderful educational piece of writing
    here at my house.

  29. For most recent news you have to go to see world-wide-web and on internet I found this web
    page as a finest site for most recent updates.

  30. Your mode of telling all in this piece of writing
    is actually nice, every one be capable of effortlessly be aware of it, Thanks a lot.

  31. Thanks for the marvelous posting! I seriously enjoyed reading it, you
    might be a great author.I will make certain to
    bookmark your blog and will eventually come back someday.

    I want to encourage that you continue your great job, have a nice evening!

  32. Have you ever thought about writing an ebook or guest authoring on other sites?
    I have a blog based on the same subjects you discuss and would really like to have you
    share some stories/information. I know my readers would enjoy your work.
    If you’re even remotely interested, feel free
    to shoot me an email.

  33. Wow, amazing blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your website
    is wonderful, let alone the content!

  34. Greate pieces. Keep writing such kind of info on your page.

    Im really impressed by your site.
    Hey there, You have done an incredible job. I’ll certainly digg
    it and individually suggest to my friends.
    I am sure they will be benefited from this web site.

  35. Hey there outstanding website! Does running a blog like this take a
    large amount of work? I’ve no understanding of
    coding but I had been hoping to start my own blog
    in the near future. Anyway, should you have any ideas or techniques for new blog owners please share.
    I know this is off subject but I just wanted to ask. Cheers!

  36. I got this web site from my buddy who informed me regarding this website and at the moment this time I
    am browsing this website and reading very informative posts at
    this time.

  37. Whats up very cool blog!! Guy .. Excellent .. Superb ..
    I’ll bookmark your blog and take the feeds also? I am satisfied to seek out a lot of useful information right here in the submit,
    we need work out extra strategies on this regard, thank
    you for sharing. . . . . .

  38. Hi, i think that i saw you visited my website thus i came to “return the favor”.I am trying to find things
    to enhance my web site!I suppose its ok to
    use some of your ideas!!

  39. I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my problem.
    You’re incredible! Thanks!

  40. I’m not sure why but this site is loading extremely slow for me.
    Is anyone else having this issue or is it a problem on my end?
    I’ll check back later on and see if the problem still exists.

  41. Dear Medical Professionals,
    We are excited to invite you to explore our online bookstore, specifically tailored for the curious minds
    in the medical field. Our collection features a wide range
    of medical bestsellers, from pioneering research texts to insightful health guides.

    books.toxylact.com
    Understanding the importance of accessible knowledge in healthcare, we are thrilled to offer you the opportunity to download various medical bestsellers for
    free. Whether you are a practicing professional, a student, or
    simply someone with a keen interest in medical science,
    our bookstore is a treasure trove of information.
    Immerse yourself in the latest medical insights and discoveries.

    Enhance your professional knowledge, or simply satisfy your curiosity about the ever-evolving world of medicine.
    Our user-friendly platform ensures a seamless browsing and
    downloading experience.
    Visit us today and start your journey into the depths of medical wisdom.

    Warm regards,
    Lactology Foundation
    http://www.toxylact.com

  42. Thank you for the good writeup. It in fact was a amusement account it.
    Look advanced to more added agreeable from you! By the way, how can we communicate?

  43. Good day! Do you know if they make any plugins to assist with SEO?
    I’m trying to get my blog to rank for some targeted keywords
    but I’m not seeing very good gains. If you know of any
    please share. Thanks!

  44. I am really impressed with your writing
    skills as well as with the layout on your weblog.

    Is this a paid theme or did you modify it yourself?
    Anyway keep up the excellent quality writing, it’s
    rare to see a nice blog like this one these days.

  45. Very nice post. I just stumbled upon your blog and wished to say
    that I’ve truly enjoyed surfing around your blog posts.
    After all I’ll be subscribing to your feed and I hope you write again soon!

  46. Thanks for a marvelous posting! I truly enjoyed reading it,
    you are a great author.I will remember to bookmark your blog and may come back very soon. I want
    to encourage you to definitely continue your great work, have a
    nice holiday weekend!

  47. Hey there, I think your blog might be having browser compatibility issues.
    When I look at your website in Firefox, it looks fine but when opening in Internet Explorer, it has some
    overlapping. I just wanted to give you a quick heads up!
    Other then that, great blog!

  48. What¦s Taking place i’m new to this, I stumbled upon this I have found It positively helpful and it has aided me out loads. I’m hoping to contribute & assist other customers like its aided me. Good job.

  49. Situs dan Aplikasi slot gacor gampang menang dengan RTP gacor yang mampu mewujudkan maxwin jackpot dengan winrate tinggi. Dengan minimal deposit 25rb via Dana Ovo Gopay dan Rekening Bank serta dukungan server canggih mengadopsi html5, sehingga setiap putaran spin yang menyala akan menghasilkan scatter yang sangat menarik. link alternatif yang selalu di kawal admin 24 jam, menjadikan login para member semakin mudah untuk di akses. Daftar Astina333 untuk menjemput hoki kalian bersama slot88 menyala sekarang juga!

  50. I have recently started a blog, the information you provide on this website has helped me greatly. Thanks for all of your time & work. “If you would know strength and patience, welcome the company of trees.” by Hal Borland.

  51. Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Ie. I’m not sure if this is a format issue or something to do with internet browser compatibility but I figured I’d post to let you know. The layout look great though! Hope you get the issue solved soon. Kudos

  52. Do you mind if I quote a few of your posts as long as I provide credit and
    sources back to your website? My blog site is in the very same area of interest as yours
    and my users would truly benefit from a lot of the information you present here.

    Please let me know if this alright with you. Thanks a lot!

  53. I don’t know if it’s just me or if everybody else encountering
    problems with your website. It looks like some of the text
    within your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them too?
    This might be a issue with my web browser because I’ve had this happen before.
    Kudos

  54. Wonderful beat ! I would like to apprentice while you amend your
    site, how could i subscribe for a blog web site?
    The account helped me a acceptable deal. I had been a
    little bit acquainted of this your broadcast provided bright clear idea

  55. Hello, i think that i saw you visited my web site so i came to “return the favor”.I am attempting to find things to improve my website!I suppose its ok to use
    some of your ideas!!

  56. I’ve been exploring for a little for any high-quality
    articles or weblog posts in this sort of space .
    Exploring in Yahoo I at last stumbled upon this
    site. Studying this information So i am happy to convey that I’ve an incredibly just right uncanny feeling I came upon just what
    I needed. I most certainly will make certain to do not forget this site and give it a look on a
    continuing basis.

  57. Hi, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam comments?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me insane so
    any support is very much appreciated.

  58. Thank you, I’ve just been searching for information about this subject for a while and yours is the best I’ve came upon till
    now. However, what concerning the bottom line? Are you positive
    concerning the supply?

Leave a Reply

Your email address will not be published. Required fields are marked *