Quadrature oscillators

8 views
Skip to first unread message

Remington Furman

unread,
Nov 7, 2025, 1:35:24 AM (3 days ago) Nov 7
to fo...@jsoftware.com
I had fun investigating quadrature oscillators using J and the plot
library.  A quadrature oscillator outputs a pair of sine and cosine
values at evenly spaced angles (fixed frequency).

Blog post: https://remcycles.net/blog/viete_cheb.html

All the code: https://remcycles.net/files/j/osc.ijs

In theory, such oscillators could be used to optimize circle function
verbs applied to evenly spaced angles, something like 0.1 ([: _12&o. (*
i.)) 100 (100 points with a phase increment of 0.1 radians).  In
practice, I'm not sure it would be worth the effort to special case that
in the J Engine.

-Remington

PS. Here's a snippet showing one of the oscillators:

NB. Levine-Vicanek Quadrature Oscillator
NB. Notation from "A New Contender in the Quadrature Oscillator Race"
NB. by Richard Lyons.

NB. f_hz:  oscillator frequency
NB. p_rad: phase
NB. s_hz:  sample rate
lv_init=: 3 : 0 "1
  'f_hz p_rad s_hz' =. y
  rps=.(2p1*f_hz)%s_hz                  NB. radians per sample
  rad=. 2p1#:!.0 p_rad                  NB. Unwrap phase.
  (2 o. rad), (1 o. rad), (3 o. rps%2), (1 o. rps)   NB. u v k1 k2
)

lv_step=: 3 : 0 "1
  'u v k1 k2'=. y
  w=.  u - k1 * v
  nv=. v + k2 * w
  nu=. w - k1 * nv
  nu, nv, k1, k2
)

lv_osc=: 3 : 0 "1
  0 lv_osc y
:
  NB. One-liner:
  NB. (j./)@:(2&{.)"1 lv_step^:(<x) lv_init y
  lv=. lv_step^:(<x) lv_init y
  (0{"1 lv) j. (1{"1 lv)
)


Reply all
Reply to author
Forward
0 new messages