sigmoid函数导数的硬件实现(verilog)

https://blog.csdn.net/XJTU_NOC_Wei/article/details/53613599

 

仿真思路

其实是使用了很普通的硬件的函数的仿真方法,但是有趣的是我为了提升精度将划分划分的更加细致了; 
看一下matlab源代码还有图像大家就知道了:

function Mysolution()
x1=0:0.01:0.125;
f1=0.2498 ;
x2=0.125:0.01:0.25;
f2=0.2478;
x3=0.25:0.01:0.375;
f3= 0.2440 ;
x4=0.375:0.01:0.5;
f4=0.2384;
x5=0.5:0.01:0.625;
f5=0.2312;
x6=0.625:0.01:0.75;
f6=0.2226;
x7=0.75:0.01:0.875;
f7=0.2129;
x8=0.875:0.01:1;
f8=0.2022;
x9=1:0.01:1.125;
f9=0.1909;
x10=1.125:0.01:1.25;
f10=0.1791;
x11=1.25:0.01:1.375;
f11=0.1671;
x12=1.375:0.01:1.5;
f12=0.1551;
x13=1.5:0.01:1.625;
f13=0.1443;
x14=1.625:0.01:1.75;
f14=0.1317;
x15=1.75:0.01:1.875;
f15=0.1206;
x16=1.875:0.01:2;
f16=0.1101;
x17=2:0.01:2.125;
f17=0.1001;
x18=2.125:0.01:2.25;
f18=0.0907;
x19=2.25:0.01:2.375;
f19=0.0820;
x20=2.375:0.01:2.5;
f20=0.0739;
x21=2.5:0.01:2.625;
f21=0.0665;
x22=2.625:0.01:2.75;
f22=0.0597;
x23=2.75:0.01:2.875;
f23=0.0534;
x24=2.875:0.01:3;
f24=0.0478;
x25=3:0.01:3.125;
f25=0.0427;
x26=3.125:0.01:3.25;
f26=0.0381;
x27=3.25:0.01:3.375;
f27=0.0339;
x28=3.375:0.01:3.5;
f28=0.0302;
x29=3.5:0.01:3.625;
f29=0.0268;
x30=3.625:0.01:3.75;
f30=0.0238;
x31=3.75:0.01:3.875;
f31=0.0211;
x32=3.875:0.01:4;
f32=0.0188;
x33=4:0.01:4.125;
f33=0.0166;
x34=4.125:0.01:4.25;
f34=0.0147;
x35=4.25:0.01:4.375;
f35=0.0130;
x36=4.375:0.01:4.5;
f36=0.0116;
x37=4.5:0.01:4.625;
f37=0.0102;
x38=4.625:0.01:4.75;
f38=0.009;
x39=4.75:0.01:4.875;
f39=0.008;
x40=4.875:0.01:5;
f40=0.0071;
x41=5:0.01:5.125;
f41=0.0063;
x42=5.125:0.01:5.25;
f42=0.0055;
x43=5.25:0.01:5.375;
f43=0.0049;
x44=5.375:0.01:5.5;
f44=0.0043;
x45=5.5:0.01:5.625;
f45=0.0038;
x46=5.625:0.01:5.75;
f46=0.0034;
x47=5.75:0.01:5.875;
f47=0.0030;
x48=5.875:0.01:6;
f48=0.0026;
x49=6:0.01:6.125;
f49=0.0023;
x50=6.125:0.01:6.25;
f50=0.0020;
x51=6.25:0.01:6.375;
f51=0.0018;
x52=6.375:0.01:6.5;
f52=0.0016;
x53=6.5:0.01:6.625;
f53=0.0014;
x54=6.625:0.01:6.75;
f54=0.0012;
x55=6.75:0.01:6.875;
f55=0.0011;
x56=6.875:0.01:7;
f56=0.0010;
x57=7:0.01:7.125;
f57=0.0009;
x58=7.125:0.01:7.25;
f58=0.0008;
x59=7.25:0.01:7.375;
f59=0.0007;
x60=7.375:0.01:7.5;
f60=0.0006;
x61=7.5:0.01:7.625;
f61=0.0005;
x62=7.625:0.01:7.75;
f62=0.0005;
x63=7.75:0.01:7.875;
f63=0.0004;
x64=7.875:0.01:8;
f64=0.0004;
x=0.0625:0.125:7.9375;
fx=exp(-x)./(1+exp(-x)).^2;
plot(x,fx,'b');
hold on;
plot(x1,f1,'r');hold on;
plot(x2,f2,'r');hold on;
plot(x3,f3,'r');hold on;
plot(x4,f4,'r');hold on;
plot(x5,f5,'r');hold on;
plot(x6,f6,'r');hold on;
plot(x7,f7,'r');hold on;
plot(x8,f8,'r');hold on;
plot(x9,f9,'r');hold on;
plot(x10,f10,'r');hold on;
plot(x11,f11,'r');hold on;
plot(x12,f12,'r');hold on;
plot(x13,f13,'r');hold on;
plot(x14,f14,'r');hold on;
plot(x15,f15,'r');hold on;
plot(x16,f16,'r');hold on;
plot(x17,f17,'r');hold on;
plot(x18,f18,'r');hold on;
plot(x19,f19,'r');hold on;
plot(x20,f20,'r');hold on;
plot(x21,f21,'r');hold on;
plot(x22,f22,'r');hold on;
plot(x23,f23,'r');hold on;
plot(x24,f24,'r');hold on;
plot(x25,f25,'r');hold on;
plot(x26,f26,'r');hold on;
plot(x27,f27,'r');hold on;
plot(x28,f28,'r');hold on;
plot(x29,f29,'r');hold on;
plot(x30,f30,'r');hold on;
plot(x31,f31,'r');hold on;
plot(x32,f32,'r');hold on;
plot(x33,f33,'r');hold on;
plot(x34,f34,'r');hold on;
plot(x35,f35,'r');hold on;
plot(x36,f36,'r');hold on;
plot(x37,f37,'r');hold on;
plot(x38,f38,'r');hold on;
plot(x39,f39,'r');hold on;
plot(x40,f40,'r');hold on;
plot(x41,f41,'r');hold on;
plot(x42,f42,'r');hold on;
plot(x43,f43,'r');hold on;
plot(x44,f44,'r');hold on;
plot(x45,f45,'r');hold on;
plot(x46,f46,'r');hold on;
plot(x47,f47,'r');hold on;
plot(x48,f48,'r');hold on;
plot(x49,f49,'r');hold on;
plot(x50,f50,'r');hold on;
plot(x51,f51,'r');hold on;
plot(x52,f52,'r');hold on;
plot(x53,f53,'r');hold on;
plot(x54,f54,'r');hold on;
plot(x55,f55,'r');hold on;
plot(x56,f56,'r');hold on;
plot(x57,f57,'r');hold on;
plot(x58,f58,'r');hold on;
plot(x59,f59,'r');hold on;
plot(x60,f60,'r');hold on;
plot(x61,f61,'r');hold on;
plot(x62,f62,'r');hold on;
plot(x63,f63,'r');hold on;
plot(x64,f64,'r');hold on;
xx=0.0625:0.125:8-0.0625;
ff=exp(-xx)./(1+exp(-xx)).^2
plot(xx,ff,'black');
end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201

这里写图片描述
确实比较简单,但是硬件实现遇见了很大的麻烦,为什么呢,因为我们用到的数据是16位的浮点型,大概画一下结构好了; 
这里写图片描述
也就是说,我现在知道了每个范围的x所对应的y的值,在输入一个十六位二进制的浮点型数据之后,根据这个数据得知rom里面对应的y的地址值,反正就是很麻烦我也没啥时间写,直接上代码吧。 
先做一个y值得rom

memory_initialization_radix=2;
memory_initialization_vector=
0011000011111111
0011000011111101
0011000011111001
0011000011110100
0011000011101100
0011000011100011
0011000011011001
0011000011001111
0011000011000011
0011000010110111
0011000010101011
0011000010011110
0011000010010010
0011000010000110
0010110001111011
0010110001110000
0010110001100110
0010110001011100
0010110001010011
0010110001001011
0010110001000100
0010100000111101
0010100000110110
0010100000110000
0010100000101011
0010100000100110
0010100000100010
0010010000011110
0010010000011011
0010010000011000
0010010000010101
0010010000010011
0010010000010001
0010000000001111
0010000000001101
0010000000001011
0010000000001010
0010000000001001
0010000000001000
0001110000000111
0001110000000110
0001110000000101
0001110000000100
0001110000000100
0001100000000011
0001100000000011
0001100000000011
0001100000000010
0001100000000010
0001100000000010
0001010000000001
0001010000000001
0001010000000001
0001010000000001
0001010000000001
0001000000000000
0001000000000000
0001000000000000
0001000000000000
0001000000000000
0001000000000000
0000110000000000
0000110000000000
0000110000000000;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67

然后用x对应到地址,我设计的很巧妙的呦:

//由x得到adress
module Mysolution(clk,read_x,addra);
input clk;
input [15:0] read_x;
output [5:0] addra;
reg [15:0] Data1;
reg [15:0] Data2;
reg [5:0] addra;
always @(posedge clk)
begin
Data1={6'b000001,read_x[9:0]};
Data2={6'b000000,read_x[9:0]};
if(read_x[14:10]>=5'b01111)
addra=Data1[12:7];
else
addra=Data2[12:7];
end
endmodule
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
module addrtodata(clk,ena,read_x,douta);
input clk,ena;
input[15:0] read_x;
output [15:0] douta;
wire [15:0] douta;
wire [5:0] addra;
Mysolution  mysolution_init_0(.clk(clk),.read_x(read_x),.addra(addra));
blk_mem_gen_0 addrtodata(.clka(clk),.addra(addra),.douta(douta),.ena(ena));
endmodule
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

好了,testbench自己写,加油;

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XJTU_NOC_Wei/article/details/53613599

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值