HDL Coder: Replace the exp Function with a Lookup Table
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Fabig
il 19 Apr 2017
Commentato: Bharath Venkataraman
il 20 Apr 2017
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
0 Commenti
Risposta accettata
Bharath Venkataraman
il 19 Apr 2017
You can try using a lookup table to implement exponent for a given input range. Another option is to try the CORDIC implementation .
2 Commenti
Bharath Venkataraman
il 20 Apr 2017
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.
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!