Q auto-suggest
Recommend a Q-factor from sample data. Two modes: recover Q when you have both a float reference and the fixed-point integers (mirrors the Debugger's per-row Auto-Q button); pick Q when you only have a float signal and a target Word width.
How "recover" works
For each pair where the float reference is non-zero, compute
ratioi = fixedi / floati.
Since fixed = float ยท 2Q for the matching
Q-format, the ratios cluster around 2Q.
Take the mean of the positive finite ratios, log2 it,
and round โ that's your Q. The standard deviation across ratios
indicates how confident the suggestion is (low ฯ โ a single
consistent Q produced the data).
How "pick" works
Take max|x| across the float samples. The smallest
integer E with 2E > max|x| is the number
of integer bits needed to represent the signal without saturating
the positive peak; Q = (N โ 1) โ E. The result is
the tightest Q for that Word width โ i.e. the most fractional
precision you can afford.