Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17258 Discussions

MATLAB and Modelsim results

Altera_Forum
Honored Contributor II
1,782 Views

Hi.  

 

why results of a megafunction is different from matlab single precision results of the same computations? is there a problem in my implementation? if not what is the truncate error of the megafunctions? 

 

Regars 

 

 

Bedri
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
824 Views

What megafunctions are you referring to?

0 Kudos
Altera_Forum
Honored Contributor II
824 Views

 

--- Quote Start ---  

What megafunctions are you referring to? 

--- Quote End ---  

 

 

thank you for your reply. 

 

i use matlab for computer simulation and model sim altera for vhdl simulation. to solve such equation (3*k*x3)/(m*x1^4) in 32-bit precision in matlab i use single((3*k*x3)/(m*x1^4)) and in vhdl i use altfp_mul, altfp_div megafunctions in 32-bit precision. matlab results may be different from modelsim results. before the real implementation to my de2-115 board i have to verify matlab results and modelsim results whether they are equal. differences are too small at the beginning but in iteration it getting bigger. what is wrong in my application: matlab usage or implementation? 

 

thank you. 

 

Bedri
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

??????????????

0 Kudos
Altera_Forum
Honored Contributor II
824 Views

how much are the differences? are you sure you have all the correct parameters set in the megafunctions? can you post the code here? Have you gopt all the latencies balanced properly? 

 

On the subject of floating point, why are you even using it at all? FPGAs are not idea for it, but set up for fixed point. Is there any reason you cannot use fixed point?
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

Thank you for your reply. 

 

 

--- Quote Start ---  

how much are the differences? are you sure you have all the correct parameters set in the megafunctions? can you post the code here? Have you gopt all the latencies balanced properly? 

--- Quote End ---  

 

 

I have used altfp_mul megafunction with the properties;  

--altfp_mult CBX_AUTO_BLACKBOX="ALL" DEDICATED_MULTIPLIER_CIRCUITRY="YES" DENORMAL_SUPPORT="NO" DEVICE_FAMILY="Cyclone IV E" EXCEPTION_HANDLING="NO" PIPELINE=5 REDUCED_FUNCTIONALITY="NO" ROUNDING="TO_NEAREST" WIDTH_EXP=8 WIDTH_MAN=23 aclr clk_en clock dataa datab result 

--VERSION_BEGIN 10.1SP1 cbx_alt_ded_mult_y 2011:01:19:22:08:03:SJ cbx_altbarrel_shift 2011:01:19:22:08:04:SJ cbx_altfp_mult 2011:01:19:22:08:05:SJ cbx_altmult_add 2011:01:19:22:08:05:SJ cbx_cycloneii 2011:01:19:22:08:06:SJ cbx_lpm_add_sub 2011:01:19:22:08:06:SJ cbx_lpm_compare 2011:01:19:22:08:07:SJ cbx_lpm_mult 2011:01:19:22:08:07:SJ cbx_mgl 2011:01:19:22:15:52:SJ cbx_padd 2011:01:19:22:08:07:SJ cbx_parallel_add 2011:01:19:22:08:07:SJ cbx_stratix 2011:01:19:22:08:08:SJ cbx_stratixii 2011:01:19:22:08:08:SJ cbx_util_mgl 2011:01:19:22:08:07:SJ VERSION_END 

 

 

--- Quote Start ---  

On the subject of floating point, why are you even using it at all? FPGAs are not idea for it, but set up for fixed point. Is there any reason you cannot use fixed point? 

--- Quote End ---  

 

As I said before I'm a beginner in vhdl. Beside I'm a Phd Student. I have trying to develop my vhdl technique. i did not prefer fixed point because i cant utilize some megafunctions such as fixed point sqrt.  

Especially I've writing something here to teach right methods to use megafunctions in my implementation. So could you please inform me about fixed point sqrt megafunction. For example while implementing such an arithmetic operation ((4)^(1/2))+5 how can i carry the output of altsqrt (remainder and q) to lpm_add_sub? 

 

Best Regards. 

 

Bedri
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

Those numbers dont mean alot, how about poosting the code? This would also show the pipeline. You also didnt say what the differences were. 

 

Using megafunctions doesnt really teach you VHDL.
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

 

--- Quote Start ---  

Those numbers dont mean alot, how about poosting the code? This would also show the pipeline. You also didnt say what the differences were. 

 

Using megafunctions doesnt really teach you VHDL. 

--- Quote End ---  

 

 

I did an example. In matlab command window i wrote  

>> num2hex( single(0.123456712)) 

ans = 

3dfcd6df 

>> num2hex( single(0.123456712)* single(0.123456712) ) 

ans = 

3c79b7bb 

 

 

 

Afterwards in modelsim altera i implemented this multiplication by using aaltfp_mul with 32-bit precision and latency of 5. dataa and datab of altfp_mul is x"3dfcd6df". after 5 clock sequences result of altfp_mul is x"3c79b7bb" which is the same with matlab result. i think that some constant values in my algorithm may be defined different in matlab than vhdl. i'm going to detect the wrong definition. thank you for your help.  

 

could you please answer my last question: while implementing such an arithmetic operation (sqrt(4))+5 how can i carry the output of altsqrt (remainder and q) to lpm_add_sub? 

 

regards. 

 

Bedri
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

you would just pass the Q value to add sub. the remainder would usually be discarded. The trick is aligning the fixed point properly to only discard a remainder that has an insignificant affect on the output. 

Fixed point is just integer with a 2^n offset.
0 Kudos
Altera_Forum
Honored Contributor II
824 Views

 

--- Quote Start ---  

you would just pass the Q value to add sub. the remainder would usually be discarded. The trick is aligning the fixed point properly to only discard a remainder that has an insignificant affect on the output. 

Fixed point is just integer with a 2^n offset. 

--- Quote End ---  

 

 

Thank you for your reply. 

 

 

i examined a simple example acording to your reply. let the data to be squared is 0.0625, so; the corresponding value is x"0010" in 16-bit precision fixed point. the input radical of the altsqrt should be modified as x"00001000", in order to discard remainder. if so, q shows the result as x"0040" which corresponds 0.25 that is sqrt of 0.0625. am i correct? 

 

Regards. 

 

Bedri
0 Kudos
Reply