spec: Move gain estimation in fixed point

This commit is contained in:
Antoine SOULIER
2022-05-12 10:17:20 +02:00
parent 15240c5f9e
commit bba71917f2
3 changed files with 104 additions and 23 deletions

View File

@@ -92,6 +92,22 @@ def approx_log2():
plt.show()
def table_db_q16():
k = 10 * np.log10(2);
for i in range(32):
a = k * np.log2(np.ldexp(32 + i , -5)) - (i // 16) * (k/2);
b = k * np.log2(np.ldexp(32 + i+1, -5)) - (i // 16) * (k/2);
an = np.ldexp(a, 15) + 0.5
bn = np.ldexp(b - a, 15) + 0.5
print('{{ {:5d}, {:4d} }},'
.format(int(np.ldexp(a, 15) + 0.5),
int(np.ldexp(b - a, 15) + 0.5)),
end = ' ' if i % 4 < 3 else '\n')
if __name__ == '__main__':
print('\n--- Approximation of 2^n ---')
@@ -100,4 +116,7 @@ if __name__ == '__main__':
print('\n--- Approximation of log2(n) ---')
approx_log2()
print('\n--- Table of fixed Q16 dB ---')
table_db_q16()
print('')