2

How do I find the integers $x$ and $y$ minimizing $| t - x \cdot y |$ with $1 \leq x < N$ and $1 \leq y < M$ ?

Background: A clock signal is divided by two hardware prescalers (with a limited number of bits), how do I produce an output frequency that is as close as possible to the desired frequency ?

naslundx
  • 9,720
Julien
  • 243
  • Do you search theoretical or practical solutions? How to deal with multiple solutions, e.g. for $t=10007, x<512, y<512$ you have 6 pairs with minimum distance 1: (24,417), (36,278), (72,139), (139,72), (278,36), (417,24) i.e. the solution maybe does no exist, there is no solution with distance $0$ because t is prime. I have used a simple linear search for $x=\lfloor t / (y_{max}+1\rfloor.. x_{max}$ – gammatester Mar 20 '14 at 15:01
  • I'm looking for a practical solution faster than O(N) or O(M). I am aware that there may be multiple solutions, finding one of them is enough. – Julien Mar 20 '14 at 15:42
  • So N and M are necessarily powers of 2? How big is t? Does it factor nicely? – Tavian Barnes Dec 08 '14 at 21:16

0 Answers0