-- thomas-examples.lua -- Examples how to use thomas.lua -- (Calculate phase from attenuation for minimum-phase networks) -- 2020-02-24, H. Henkel local th = require("thomas") local sixdb = 20 * math.log10(2) -- simple function for printing (omega, phase) sequence local print_phase = function(t) local omega = t.omega_min local omega_inc = t.omega_inc or 1.01 local omega_max = t.omega_max local a = t.a for i = 1, math.huge do local phase = th.phase(omega, a) print(omega, phase * 180 / math.pi) -- phase [degrees] omega = omega * omega_inc if omega > omega_max then break end end end -- Tuttle: Electric Networks: Analysis and Synthesis -- Figure 11.12-E, p. 242 local a_tuttle = { {10, 0}, -- constant down to 0 Hz (added) {15, 0}, {20, 13}, {30, 8}, {60, 8 + 2 * sixdb}, -- rising with 12 dB per octave } -- D. E. Thomas: Tables of Phase Associated with -- a Semi-Infinite Unit Slope of Attenuation -- Fig. 5, p. 890 local a_thomas_fig5 = { { 0.1, 0}, -- constant down to 0 Hz (added) { 0.13, 0}, { 0.433, -1.4}, { 1.19, -5.55}, { 1.38, -5.55}, { 1.62, -4.30}, { 1.96, -0.45}, { 2.20, -0.45}, { 3.0, -6.70}, { 5.0, -13.40}, {20.0, -26.0}, {40.0, -32.0}, } -- fictional quartz filter, center frequency at 10 MHz, -- bandwidth +/- 1 kHz local a_qf = { {(10e6 - 10000) / 2, 60 + sixdb}, -- attenuation towards 0 Hz {10e6 - 10000, 60}, {10e6 - 1000, 3}, {10e6 - 800, 0}, {10e6 - 600, 3}, {10e6 - 400, 0}, {10e6 - 200, 3}, {10e6 - 0, 0}, {10e6 + 200, 3}, {10e6 + 400, 0}, {10e6 + 600, 3}, {10e6 + 800, 0}, {10e6 + 1000, 3}, {10e6 + 10000, 60}, {(10e6 + 10000) * 2, 60 + sixdb}, -- attenuation towards infinity } ------------------------------------------------------------------------ -- Example 1, from Tuttle book --print_phase({omega_min = 1, omega_max = 200, a = a_tuttle}) -- Example 2, from Thomas' paper -- this results in the phase values of Fig. 6: print_phase({omega_min = 0.1, omega_max = 5, a = a_thomas_fig5}) -- Example 3, fictional quartz filter -- wide range plot --print_phase({omega_min = 10e6 - 1e6, omega_max = 10e6 + 1e6, omega_inc = 1 + 1e-5, a = a_qf}) -- narrow range plot --print_phase({omega_min = 10e6 - 10e3, omega_max = 10e6 + 10e3, omega_inc = 1 + 1e-6, a = a_qf})