Module:Harmonics in edo: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
ArrowHead294 (talk | contribs) |
||
(23 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
local function edoprox(edo, odds, title, prec) | local function edoprox(edo, odds, title, prec) | ||
local f = 1/edo | local f = 1/edo | ||
local todd = {'! | Odd harmonic '} | local todd = {'! colspan="2" | Odd harmonic '} | ||
local tabs = {'! | Error ([[cent|¢]]) '} | local tapprox = {'! colspan="2" | Approximation '} | ||
local tdeg = {'! | Steps'} | local tabs = {'! rowspan="2" | Error \n! absolute ([[cent|¢]]) '} | ||
local trel = {'! [[Relative error|relative]] (%) '} | |||
local tdeg = {'! colspan="2" | Steps ([[octave reduction|reduced]])'} | |||
local fmt_approx = string.format(' %%.%df', prec) | |||
local fmt_abs = string.format(' %%+.%df', prec) | local fmt_abs = string.format(' %%+.%df', prec) | ||
local fmt_rel = ' %+.0f' | local fmt_rel = ' %+.0f' | ||
Line 12: | Line 15: | ||
v = s*edo | v = s*edo | ||
ev = math.floor(v + .5) | ev = math.floor(v + .5) | ||
table.insert(todd, ' ' .. p .. | table.insert(todd, ' ' .. p ) | ||
table.insert(tapprox, string.format(fmt_approx, 1200*(ev % edo)/edo) ) | |||
table.insert(tabs, string.format(fmt_abs, 1200 * (ev - v ) / edo)) | table.insert(tabs, string.format(fmt_abs, 1200 * (ev - v ) / edo)) | ||
table.insert(tdeg, ' ' .. ev % edo .. ' ') | table.insert(trel, string.format(fmt_rel, 100 * (ev - v))) | ||
table.insert(tdeg, ' ' .. ev .. ' ('.. ev % edo .. ')') | |||
end | end | ||
local titleMarkup = '' | local titleMarkup = '' | ||
Line 27: | Line 32: | ||
'|-\n' .. | '|-\n' .. | ||
table.concat(tabs, '\n|') .. '\n' .. | table.concat(tabs, '\n|') .. '\n' .. | ||
'|-\n' .. | |||
table.concat(trel, '\n|') .. '\n' .. | |||
'|-\n' .. | '|-\n' .. | ||
table.concat(tdeg, '\n|') .. '\n' .. | table.concat(tdeg, '\n|') .. '\n' .. | ||
Line 36: | Line 43: | ||
function p.harmonics_in_edo (frame) | function p.harmonics_in_edo (frame) | ||
local edo = frame.args[1] or frame.args['edo'] or 12 -- edo (default=12) | local edo = frame.args[1] or frame.args['edo'] or 12 -- edo (default=12) | ||
local columns = frame.args['columns'] or | local columns = frame.args['columns'] or 15 -- number of columns (default = 15, harmonics 3 to 31) | ||
local start = frame.args['start'] or 1 -- start column, default: start with harmonic 3 | local start = frame.args['start'] or 1 -- start column, default: start with harmonic 3 | ||
local title = frame.args['title'] or 'Approximation of odd harmonics in ' .. edo .. ' | local title = frame.args['title'] or 'Approximation of odd harmonics in ' .. edo .. 'edo' | ||
local prec = frame.args['prec'] or 1 -- for now only variable precision for abs error | local prec = frame.args['prec'] or 1 -- for now only variable precision for abs error | ||
return edoprox( edo, {unpack(odds, start, start+columns-1)}, title, prec) | return edoprox( edo, {unpack(odds, start, start+columns-1)}, title, prec) |
Latest revision as of 18:25, 23 May 2024
![]() |
This page is deprecated. It is being kept for posterity and for reference, but is no longer being actively maintained.
If you have contributions to add to this page, it would be advisable to add them to a different, related page instead. When writing other pages, avoid including links to this page. |
Used in Template:Odd harmonics in edo.
local p = {}
local function edoprox(edo, odds, title, prec)
local f = 1/edo
local todd = {'! colspan="2" | Odd harmonic '}
local tapprox = {'! colspan="2" | Approximation '}
local tabs = {'! rowspan="2" | Error \n! absolute ([[cent|¢]]) '}
local trel = {'! [[Relative error|relative]] (%) '}
local tdeg = {'! colspan="2" | Steps ([[octave reduction|reduced]])'}
local fmt_approx = string.format(' %%.%df', prec)
local fmt_abs = string.format(' %%+.%df', prec)
local fmt_rel = ' %+.0f'
for _, p in pairs(odds) do
s = math.log(p) / math.log(2)
v = s*edo
ev = math.floor(v + .5)
table.insert(todd, ' ' .. p )
table.insert(tapprox, string.format(fmt_approx, 1200*(ev % edo)/edo) )
table.insert(tabs, string.format(fmt_abs, 1200 * (ev - v ) / edo))
table.insert(trel, string.format(fmt_rel, 100 * (ev - v)))
table.insert(tdeg, ' ' .. ev .. ' ('.. ev % edo .. ')')
end
local titleMarkup = ''
if title then
titleMarkup = '|-\n|+ ' .. title .. '\n'
end
return '{| class="wikitable center-all"\n' ..
titleMarkup ..
'|-\n' ..
table.concat(todd, '\n!') .. '\n' ..
'|-\n' ..
table.concat(tabs, '\n|') .. '\n' ..
'|-\n' ..
table.concat(trel, '\n|') .. '\n' ..
'|-\n' ..
table.concat(tdeg, '\n|') .. '\n' ..
'|}'
end
local odds = { 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43 }
function p.harmonics_in_edo (frame)
local edo = frame.args[1] or frame.args['edo'] or 12 -- edo (default=12)
local columns = frame.args['columns'] or 15 -- number of columns (default = 15, harmonics 3 to 31)
local start = frame.args['start'] or 1 -- start column, default: start with harmonic 3
local title = frame.args['title'] or 'Approximation of odd harmonics in ' .. edo .. 'edo'
local prec = frame.args['prec'] or 1 -- for now only variable precision for abs error
return edoprox( edo, {unpack(odds, start, start+columns-1)}, title, prec)
end
return p;