HDL Coder: Replace the exp Function with a Lookup Table

조회 수: 14 (최근 30일)
Fabig
Fabig 2017년 4월 19일
댓글: Bharath Venkataraman 2017년 4월 20일
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
Bharath Venkataraman 2017년 4월 19일
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
Bharath Venkataraman 2017년 4월 20일
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