S
sanborne
I have another question related to fixed point.
I wrote a function in MATLAB that will take an arbitrary yet well
behaved function and generate an if-then-elseif tree that can
approximate that function over a given interval. For example, the
following is the output of my function to approximate the natural
logarithm over an interval of 1e-4 to 1 (I apologize if you are
unfamiliar with MATLAB, as this is a VHDL forum, but the functionality
of this code should be relatively clear):
% begin code
% y=ln( x );
% at each interval, y is computed using a linear approximation y=a*x +
b.
if x<0.0263665
if x<0.00428133
if x<0.00206914
if x<0.00143845
y = fi(825.681,T1,F)*x + fi(-7.72178,T1,F);% here 1
else
y = fi(574.007,T1,F)*x + fi(-7.35822,T1,F);
end
elseif x>0.00297635
y = fi(277.414,T1,F)*x + fi(-6.63109,T1,F);% here 4
else
y = fi(399.046,T1,F)*x + fi(-6.99465,T1,F);
end
elseif x>0.00615848
if x<0.0127427
if x<0.00885867
y = fi(134.072,T1,F)*x + fi(-5.90395,T1,F);% here 6
else
y = fi(93.206,T1,F)*x + fi(-5.54039,T1,F);
end
elseif x>0.0183298
y = fi(45.0458,T1,F)*x + fi(-4.81325,T1,F);% here 9
else
y = fi(64.7961,T1,F)*x + fi(-5.17682,T1,F);
end
else
y = fi(192.856,T1,F)*x + fi(-6.26752,T1,F);
end
elseif x>0.0379269
if x<0.162378
if x<0.078476
if x<0.0545559
y = fi(21.7703,T1,F)*x + fi(-4.08612,T1,F);% here 11
else
y = fi(15.1346,T1,F)*x + fi(-3.72256,T1,F);
end
elseif x>0.112884
y = fi(7.31443,T1,F)*x + fi(-2.99542,T1,F);% here 14
else
y = fi(10.5214,T1,F)*x + fi(-3.35899,T1,F);
end
elseif x>0.233572
if x<0.483293
if x<0.335982
y = fi(3.53501,T1,F)*x + fi(-2.26829,T1,F);% here 16
else
y = fi(2.45752,T1,F)*x + fi(-1.90473,T1,F);
end
elseif x>0.695193
y = fi(1.1877,T1,F)*x + fi(-1.17759,T1,F);% here 19
else
y = fi(1.70845,T1,F)*x + fi(-1.54116,T1,F);
end
else
y = fi(5.08494,T1,F)*x + fi(-2.63186,T1,F);
end
else
y = fi(31.3155,T1,F)*x + fi(-4.44969,T1,F);
end
% end code
I think converting this code to VHDL should be relatively straight
forward, although I do not know very well how to deal with fixed
point. How, for example would I convert the constant coefficients
above into fixed point hardware?
But my real question is whether this is the right approach. I am
afraid the hardware implementation of the equivalent VHDL would use a
TON of multipliers, and might have other problems too. How would
someone implement a non-linear, yet common function in hardware? Note
that taylor series is definitely not the answer. After a fairly in-
depth study the above solution is the best I could come up with. Are
there any other suggestions? Is there something better than my binary
if-tree approach?
Thanks a ton for any responses.
I wrote a function in MATLAB that will take an arbitrary yet well
behaved function and generate an if-then-elseif tree that can
approximate that function over a given interval. For example, the
following is the output of my function to approximate the natural
logarithm over an interval of 1e-4 to 1 (I apologize if you are
unfamiliar with MATLAB, as this is a VHDL forum, but the functionality
of this code should be relatively clear):
% begin code
% y=ln( x );
% at each interval, y is computed using a linear approximation y=a*x +
b.
if x<0.0263665
if x<0.00428133
if x<0.00206914
if x<0.00143845
y = fi(825.681,T1,F)*x + fi(-7.72178,T1,F);% here 1
else
y = fi(574.007,T1,F)*x + fi(-7.35822,T1,F);
end
elseif x>0.00297635
y = fi(277.414,T1,F)*x + fi(-6.63109,T1,F);% here 4
else
y = fi(399.046,T1,F)*x + fi(-6.99465,T1,F);
end
elseif x>0.00615848
if x<0.0127427
if x<0.00885867
y = fi(134.072,T1,F)*x + fi(-5.90395,T1,F);% here 6
else
y = fi(93.206,T1,F)*x + fi(-5.54039,T1,F);
end
elseif x>0.0183298
y = fi(45.0458,T1,F)*x + fi(-4.81325,T1,F);% here 9
else
y = fi(64.7961,T1,F)*x + fi(-5.17682,T1,F);
end
else
y = fi(192.856,T1,F)*x + fi(-6.26752,T1,F);
end
elseif x>0.0379269
if x<0.162378
if x<0.078476
if x<0.0545559
y = fi(21.7703,T1,F)*x + fi(-4.08612,T1,F);% here 11
else
y = fi(15.1346,T1,F)*x + fi(-3.72256,T1,F);
end
elseif x>0.112884
y = fi(7.31443,T1,F)*x + fi(-2.99542,T1,F);% here 14
else
y = fi(10.5214,T1,F)*x + fi(-3.35899,T1,F);
end
elseif x>0.233572
if x<0.483293
if x<0.335982
y = fi(3.53501,T1,F)*x + fi(-2.26829,T1,F);% here 16
else
y = fi(2.45752,T1,F)*x + fi(-1.90473,T1,F);
end
elseif x>0.695193
y = fi(1.1877,T1,F)*x + fi(-1.17759,T1,F);% here 19
else
y = fi(1.70845,T1,F)*x + fi(-1.54116,T1,F);
end
else
y = fi(5.08494,T1,F)*x + fi(-2.63186,T1,F);
end
else
y = fi(31.3155,T1,F)*x + fi(-4.44969,T1,F);
end
% end code
I think converting this code to VHDL should be relatively straight
forward, although I do not know very well how to deal with fixed
point. How, for example would I convert the constant coefficients
above into fixed point hardware?
But my real question is whether this is the right approach. I am
afraid the hardware implementation of the equivalent VHDL would use a
TON of multipliers, and might have other problems too. How would
someone implement a non-linear, yet common function in hardware? Note
that taylor series is definitely not the answer. After a fairly in-
depth study the above solution is the best I could come up with. Are
there any other suggestions? Is there something better than my binary
if-tree approach?
Thanks a ton for any responses.