Forum Discussion
Altera_Forum
Honored Contributor
15 years agoHello all,
After a little bit of digging, I could plot the signals on log scale in the wave window, thanks to some new HDL packages and libraries that come installed with the latest ModelSim versions. For the sake of benefit for other users, here is the code to get the values in log scale: (I have assumed that my signal is complex (= I+jQ = S) in a fixed point format s24:16)
-- Following packages required in addition to the existing ones
LIBRARY IEEE;
USE IEEE.MATH_REAL.ALL;
USE IEEE.MATH_COMPLEX.ALL;
LIBRARY FLOATFIXLIB;
USE FLOATFIXLIB.FIXED_PKG.ALL;
-- Entity declaration
...
-- Architecture definition
...
-- Component instantiations
...
-- Signal and attribute declarations
...
SIGNAL I_std, Q_std : std_logic_vector (23 downto 0);
SIGNAL I_real, Q_real : real;
SIGNAL S_cmplx : complex;
SIGNAL S_abs_real, S_log_real : real;
BEGIN
-- Rest of the code
I_real <= to_real(to_SFix(I_std, 24, 18));
Q_real <= to_real(to_SFix(Q_std, 24, 18));
S_cmplx <= CMPLX(I_real, Q_real);
S_abs_real <= ABS(S_cmplx);
S_log_real <= 10.0*(log10(S_abs_real)); -- Plot S_log_real in the wave window
-- End of architecture
You may also be required to check the overflow of real values depending on the signal range. Hope it helps.