HDL Coder: Replace the exp Function with a Lookup Table

15 次查看(过去 30 天)
Hello,
I want to use an exponential function with complex input values on an FPGA.
I followed the following guide to convert a not supported fixed point function into a lookup table: https://de.mathworks.com/help/hdlcoder/ug/replace-the-exp-function-with-a-lookup-table.html
If I run the example with complex input values then the replacing of the exp function with a lookup table fails. Using the same example with non complex input values succeeds. When looking at the fixpt function it can be seen that it still uses exp:
...
function y = custom_fcn(x)
fm = get_fimath();
y = fi(exp(x), 1, 14, 12, fm);
end
...
Which results in the error: ??? Function 'exp' is not defined for values of class 'embedded.fi'.
Which leaves me at the question how can an exponential function with complex inputs be implemented on an FPGA using the HDL coder?
I attached my files here. Testbench:
close all
nbrIterations = 10000;
LUT_result = zeros(nbrIterations,1);
diff = zeros(nbrIterations,1);
%Random values betwen -1.5705 and 1.5705
random_in = (3.141.*rand(nbrIterations,1) -1.5705)*1j;
for i=1:nbrIterations
LUT_result(i) = call_custom_fcn( random_in(i));
diff(i) = abs( LUT_result(i) - exp(random_in(i)) );
end
figure(1); plot(diff);
custom_fcn.m:
function y = custom_fcn(x)
y = exp(x);
end
call_custom_fcn.m:
function y = call_custom_fcn(x)
y = custom_fcn(x);
end

采纳的回答

Bharath Venkataraman
You can try using a lookup table to implement exponent for a given input range. Another option is to try the CORDIC implementation .
  2 个评论
Fabig
Fabig 2017-4-20
Thanks that was an easy fix. Using cordiccexp(real(x)) worked very well. How would I create a lookup table with a complex input range? Would I use two lookup tabels one with the complex and one with the real value?
Bharath Venkataraman
In MATLAB, you can have one lookup table with complex values and HDL Coder will do the right thing in generating code for the complex numbers. You may also split it up if that is more readable.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Code Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by