Fixed point coder log10 implementation

I am using 20*log10(val) to get power in a dB
y = 20*log10(3)
But When i am using matlab coder to convert the in c/c++ code.I am gettig an error
Function 'log10' is not defined for values of class 'embedded.fi'.
Can someone help me with alternate way of doing dB calculation.
Thank you

 Risposta accettata

Life is Wonderful
Life is Wonderful il 26 Dic 2020
qsb = fixed.Quantizer(numerictype(1,32,24));
y0 = quantize(qsb,20*fi(log(double(x)),1,32,24)/fi(log(double(10)),1,32,24)); % log(x)/log(10) for log base 10 i.e. log10
y1 = 20*log10(x);

Più risposte (2)

Darshan Ramakant Bhat
Darshan Ramakant Bhat il 19 Nov 2020
The function "log10" is supported for code generation in the latest version (R2020b) of MATLAB. You can find the list of supported functions in the below page :
I made a test and I don't see the expected result
I am still getting the error following error
??? Function 'log10' is not defined for values of class 'embedded.fi'.
My question - did you verify log10 ?
Below is the matlab version
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.9.0.1524771 (R2020b) Update 2
MATLAB License Number: 40523231
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 18363)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.9 (R2020b)
Fixed-Point Designer Version 7.1 (R2020b)
HDL Coder Version 3.17 (R2020b)
HDL Verifier Version 6.2 (R2020b)
MATLAB Coder Version 5.1 (R2020b)
Parallel Computing Toolbox Version 7.3 (R2020b)

6 Commenti

I tried with the below function and it worked in my MATLAB
function y = myLogFunc(x)
y = 20*log10(x);
end
>> codegen -config:lib myLogFunc -args {3} -report
Code generation successful: View report
Please provide me your sample function along with the script to reproduce the issue.
i don't see you generating the Fix point matlab file ? For me - the problem is with coder app generating the fixpoint matlab script
Did you notice your C code still had double for nargin? You have to consider sign, WL and FL for your input and then feed to log10 . Another point for your notice - 20*log10 (x) is NOT fixed point-
Several compiler ask to log function as they won't include the log10 in math.h . For example of Linux based implementation.
Try following sequence
fixptcfg = coder.config('fixpt')
fixptcfg.TestBenchName = 'compute_log_tb';
cfg = coder.config('lib');
codegen -float2fixed fixptcfg -config cfg compute_log -args {3}
============= Step3: Generate Fixed Point Code ==============
### Generating Fixed Point MATLAB Code compute_log_fixpt using Proposed Types
### Generating Fixed Point MATLAB Design Wrapper compute_log_wrapper_fixpt
### Generating Mex file for ' compute_log_wrapper_fixpt '
??? Function 'log10' is not defined for values of class 'embedded.fi'.
Error in ==> compute_log_fixpt Line: 10 Column: 28
Code generation failed: View Error Report
Build failed.
Use help codegen for more information on using this command.
Thanks for attaching the sample script and explaining the issue clearly. I completely missed the fixed point conversion part earlier.
The error is happening because the function "log10()" cannot take the fixed point inputs. If you do "log10(fi(3))" it will error out.
I found below documentations on fixing such errors :
Based on the above doc I modified the function like below :
function y = compute_log(x)
%#codegen
y = 20*fi(log(double(x)),1,16,0);
end
I think it is still wrong
y = 20*fi(log(double(3)),1,16,0)
&
y = 20*log10(3)
Life is Wonderful
Life is Wonderful il 20 Nov 2020
Modificato: Life is Wonderful il 20 Nov 2020
May I know what is the difference ?
Why No Fraction length ?
How did you arrive to the conclusion ?
what if y = 20*fi(log(double(x)),1,16,FL) is considerd ?if FL is 16- we get overflow but correct conversion value
Can please share the explanation in case of WL = 8,16,24,32,64- what should be the FL ?
What is range , slope , bias , resolution & precision in that case.
When do we see Overflow and Underflow . Why double is considerd that unsupported in fixed point converter?
I think log (Natural logarithm) is unsupported. We need common logarithm base 10.
How enable logging Mode fipref ? How it help me in verification
Can you please help?Thank you!
I found the right implementation -
qsb = fixed.Quantizer(numerictype(1,32,24));
y0 = quantize(qsb,20*fi(log(double(x)),1,32,24)/fi(log(double(10)),1,32,24)); % log(x)/log(10) for log base 10 i.e. log10
y1 = 20*log10(x);
Question - Matlab fixed point suggestion using fi(value) is not reliable .I don't know why it suggest that results in overflow.
You can try fi(3)
WL =16
FL= 13
Signedness =1
Try , you can see overflow. For me its not clear . Please help me
Thanks

Accedi per commentare.

Categorie

Scopri di più su Get Started with GPU Coder in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by