mirror of
https://github.com/cnlohr/lolra.git
synced 2026-06-15 07:19:25 +00:00
Working with arbitrary goertzel's
This commit is contained in:
+163
-87
@@ -11,18 +11,18 @@ body { background-color: Canvas; color: CanvasText; }
|
||||
<SCRIPT src=webhidcontrol.js></SCRIPT>
|
||||
|
||||
<SCRIPT>
|
||||
function DrawSpan( colspan, freq, target, docolor, extrastr = "" )
|
||||
function DrawSpan( rowspan, colspan, freq, target, docolor, extrastr = "" )
|
||||
{
|
||||
var fdist = Math.abs( freq - target );
|
||||
fdist = Math.pow( fdist, 0.5 ) * 500;
|
||||
// if( fdist > 255 ) fdist = 255;
|
||||
let ret = "<TD COLSPAN=" + colspan + ' ';
|
||||
let ret = "<TD COLSPAN=" + colspan + ' ROWSPAN' + rowspan + ' ';
|
||||
if( docolor ) ret += 'STYLE="color:black;background-color:rgb(' + fdist + ',' + (511-fdist) + ',0)";';
|
||||
ret += '>' + extrastr + freq.toFixed(6) + "</TD>";
|
||||
return ret;
|
||||
}
|
||||
|
||||
function Goertz( n, mhz, fr, brf )
|
||||
function Goertz( n, mhz, fr, brf, exact_compute )
|
||||
{
|
||||
let omega = fr * 3.1415926535*2.0;
|
||||
var textarea = document.getElementById("goertzeloutput");
|
||||
@@ -30,8 +30,10 @@ function Goertz( n, mhz, fr, brf )
|
||||
var g_goertzel_omega_per_sample = Math.round( ( omega*2*(1<<29)) );
|
||||
var g_goertzel_coefficient = Math.round( (2 * Math.cos( omega ) * (1<<30)) );
|
||||
var g_goertzel_coefficient_s = Math.round( (2 * Math.sin( omega ) * (1<<30)) );
|
||||
var g_exactcompute = exact_compute;
|
||||
textarea.value =
|
||||
"int g_pwm_period = ("+n+"-1);\n" +
|
||||
"int g_exactcompute = ("+exact_compute+");\n" +
|
||||
"int g_goertzel_buffer = ("+brf+");\n" +
|
||||
"int32_t g_goertzel_omega_per_sample = " + g_goertzel_coefficient.toFixed(0) + "; // " + ( omega / (3.1415926535*2.0)).toFixed(6) + " of whole per step / " + mhz.toFixed(6) + "MHz\n" +
|
||||
"int32_t g_goertzel_coefficient = " + g_goertzel_coefficient.toFixed(0) + ";\n" +
|
||||
@@ -43,7 +45,7 @@ function Goertz( n, mhz, fr, brf )
|
||||
// Copy the highlighted text
|
||||
document.execCommand("copy");
|
||||
|
||||
updateWebHidDeviceWithParameters( [ (n-1)|0, brf|0, g_goertzel_omega_per_sample|0, g_goertzel_coefficient|0, g_goertzel_coefficient_s|0 ] );
|
||||
updateWebHidDeviceWithParameters( [ (n-1)|0, brf|0, g_goertzel_omega_per_sample|0, g_goertzel_coefficient|0, g_goertzel_coefficient_s|0, exact_compute|0 ] );
|
||||
}
|
||||
|
||||
function computeTable()
|
||||
@@ -51,6 +53,8 @@ function computeTable()
|
||||
let xtal = Number(document.getElementById("crystalmhz").value );
|
||||
let target = Number(document.getElementById("targetmhz").value );
|
||||
let quadrature = document.getElementById("QUADRATURE").checked;
|
||||
let goertzels = document.getElementById("GOERTZELS").checked;
|
||||
let goertzel2 = document.getElementById("GOERTZEL2").checked;
|
||||
let quanta = Math.round(Number(document.getElementById("quanta").value));
|
||||
let quantasearch = Math.round(Number(document.getElementById("quantasearch").value));
|
||||
|
||||
@@ -78,7 +82,7 @@ function computeTable()
|
||||
"<TR><TD>Differential Frequency</TD></TR>" +
|
||||
"</TABLE>";
|
||||
}
|
||||
else
|
||||
else if( goertzels )
|
||||
{
|
||||
contents +=
|
||||
"<TABLE BORDER=1>" +
|
||||
@@ -90,102 +94,170 @@ function computeTable()
|
||||
"<P>Goertzel's mode is for the ch32v203</P>";
|
||||
}
|
||||
|
||||
contents += "<TABLE BORDER=1>";
|
||||
contents += '<TR><TH>d\\h</div></TH>';
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics; h++ )
|
||||
if( goertzels || quadrature )
|
||||
{
|
||||
contents += "<TH COLSPAN=2>" + h + "</TH>";
|
||||
}
|
||||
|
||||
for( let n = 0|28; n <= 66; n++ )
|
||||
{
|
||||
let freq = ( xtal / n );
|
||||
let goertzelpoint = 0;
|
||||
let goertzelpointinv = 0;
|
||||
let tgoertzelp = 0;
|
||||
let tgoertzelpi = 0;
|
||||
let quantaA = 0;
|
||||
let quantaINV = 0;
|
||||
contents += "<TABLE BORDER=1>";
|
||||
contents += '<TR><TH>d\\h</div></TH>';
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics; h++ )
|
||||
{
|
||||
let base = freq * h;
|
||||
let next = freq * (h+1);
|
||||
|
||||
// Round quanta down to next order-of-4-even
|
||||
for( let tquanta = (quanta&0xffffc) - (quantasearch&0xffffc); tquanta < (quanta&0xffffc) + (quantasearch&0xffffc); tquanta+=4 )
|
||||
{
|
||||
if( target <= next && target >= base )
|
||||
{
|
||||
var t;
|
||||
let tgoertzelpoint = ( target - base ) / ( next - base );
|
||||
tgoertzelpoint = Math.round(tquanta * tgoertzelpoint)/tquanta;
|
||||
if( Math.abs( freq*(h+tgoertzelpoint) - target ) < Math.abs( freq*(h+goertzelpoint) - target ) )
|
||||
{
|
||||
goertzelpoint = tgoertzelpoint;
|
||||
tgoertzelp = h;
|
||||
quantaA = tquanta;
|
||||
}
|
||||
|
||||
let tgoertzelpointinv = (1.0 - ( target - base ) / ( next - base ));
|
||||
tgoertzelpointinv = Math.round(tquanta * tgoertzelpointinv)/tquanta;
|
||||
|
||||
if( Math.abs( freq*(h-tgoertzelpointinv+1) - target ) < Math.abs( freq*(h-goertzelpointinv+1) - target ) )
|
||||
{
|
||||
goertzelpointinv = tgoertzelpointinv;
|
||||
tgoertzelpi = h;
|
||||
quantaINV = tquanta;
|
||||
}
|
||||
}
|
||||
}
|
||||
contents += "<TH COLSPAN=2>" + h + "</TH>";
|
||||
}
|
||||
contents += "</TR>";
|
||||
|
||||
for( let mode = 0; mode < 4; mode++ )
|
||||
for( let n = 0|28; n <= 66; n++ )
|
||||
{
|
||||
contents += "<TR>";
|
||||
if( mode == 0 )
|
||||
contents += "<TD ROWSPAN=" + 4 + ">" + n + "</TD>";
|
||||
let freq = ( xtal / n );
|
||||
let goertzelpoint = 0;
|
||||
let goertzelpointinv = 0;
|
||||
let tgoertzelp = 0;
|
||||
let tgoertzelpi = 0;
|
||||
let quantaA = 0;
|
||||
let quantaINV = 0;
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics; h++ )
|
||||
{
|
||||
if( quadrature )
|
||||
let base = freq * h;
|
||||
let next = freq * (h+1);
|
||||
|
||||
// Round quanta down to next order-of-4-even
|
||||
for( let tquanta = (quanta&0xffffc) - (quantasearch&0xffffc); tquanta < (quanta&0xffffc) + (quantasearch&0xffffc); tquanta+=4 )
|
||||
{
|
||||
if( mode == 0 )
|
||||
contents += DrawSpan( 2, freq * h, target, false );
|
||||
else if( mode == 1 )
|
||||
contents += DrawSpan( 2, freq * (h-.25), target, true );
|
||||
else if( mode == 2 )
|
||||
contents += DrawSpan( 2, freq * (h+.25), target, true );
|
||||
else if( mode == 3 )
|
||||
contents += DrawSpan( 2, freq * (h+0.5), target, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( mode == 0 )
|
||||
if( target <= next && target >= base )
|
||||
{
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelp == h ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+goertzelpoint) + ", " + (goertzelpoint) + ", " + quantaA + ")'>↑" + (goertzelpoint).toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 1 )
|
||||
{
|
||||
contents += DrawSpan( 2, freq * (h+goertzelpoint), target, true );
|
||||
}
|
||||
else if( mode == 2 )
|
||||
{
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelpi == h-1 ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h-goertzelpointinv) + ", " + goertzelpointinv + ", " + quantaINV + ")'>↓" + goertzelpointinv.toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 3 )
|
||||
{
|
||||
contents += DrawSpan( 2, freq * (h-goertzelpointinv), target, true );
|
||||
var t;
|
||||
let tgoertzelpoint = ( target - base ) / ( next - base );
|
||||
tgoertzelpoint = Math.round(tquanta * tgoertzelpoint)/tquanta;
|
||||
if( Math.abs( freq*(h+tgoertzelpoint) - target ) < Math.abs( freq*(h+goertzelpoint) - target ) )
|
||||
{
|
||||
goertzelpoint = tgoertzelpoint;
|
||||
tgoertzelp = h;
|
||||
quantaA = tquanta;
|
||||
}
|
||||
|
||||
let tgoertzelpointinv = (1.0 - ( target - base ) / ( next - base ));
|
||||
tgoertzelpointinv = Math.round(tquanta * tgoertzelpointinv)/tquanta;
|
||||
|
||||
if( Math.abs( freq*(h-tgoertzelpointinv+1) - target ) < Math.abs( freq*(h-goertzelpointinv+1) - target ) )
|
||||
{
|
||||
goertzelpointinv = tgoertzelpointinv;
|
||||
tgoertzelpi = h;
|
||||
quantaINV = tquanta;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
contents += "</TD>";
|
||||
contents += "</TR>";
|
||||
|
||||
for( let mode = 0; mode < 4; mode++ )
|
||||
{
|
||||
contents += "<TR>";
|
||||
if( mode == 0 )
|
||||
contents += "<TD ROWSPAN=" + 4 + ">" + n + "</TD>";
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics; h++ )
|
||||
{
|
||||
if( quadrature )
|
||||
{
|
||||
if( mode == 0 )
|
||||
contents += DrawSpan( 1, 2, freq * h, target, false );
|
||||
else if( mode == 1 )
|
||||
contents += DrawSpan( 1, 2, freq * (h-.25), target, true );
|
||||
else if( mode == 2 )
|
||||
contents += DrawSpan( 1, 2, freq * (h+.25), target, true );
|
||||
else if( mode == 3 )
|
||||
contents += DrawSpan( 1, 2, freq * (h+0.5), target, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( mode == 0 )
|
||||
{
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelp == h ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+goertzelpoint) + ", " + (goertzelpoint) + ", " + quantaA + ", 0)'>↑" + (goertzelpoint).toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 1 )
|
||||
{
|
||||
contents += DrawSpan( 1, 2, freq * (h+goertzelpoint), target, true );
|
||||
}
|
||||
else if( mode == 2 )
|
||||
{
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelpi == h-1 ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h-goertzelpointinv) + ", " + goertzelpointinv + ", " + quantaINV + ", 0)'>↓" + goertzelpointinv.toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 3 )
|
||||
{
|
||||
contents += DrawSpan( 1, 2, freq * (h-goertzelpointinv), target, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
contents += "</TD>";
|
||||
}
|
||||
}
|
||||
contents += "</TABLE>";
|
||||
}
|
||||
contents += "</TABLE>";
|
||||
else if( goertzel2 )
|
||||
{
|
||||
contents += "</TABLE><TEXTAREA ROWS=6 COLS=120 ID=goertzeloutput></TEXTAREA><BR>";
|
||||
contents += "<TABLE BORDER=1>";
|
||||
contents += '<TR><TH>d\\h</div></TH>';
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics+1; h++ )
|
||||
{
|
||||
contents += "<TH COLSPAN=1>" + h + "</TH>";
|
||||
}
|
||||
|
||||
for( let n = 0|28; n <= 96; n++ )
|
||||
{
|
||||
let freq = ( xtal / n );
|
||||
let goertzelpoint = 0;
|
||||
let goertzelpointinv = 0;
|
||||
let tgoertzelp = 0;
|
||||
let tgoertzelpi = 0;
|
||||
let quantaA = 0;
|
||||
let quantaINV = 0;
|
||||
|
||||
for( let rid = 0|0; rid < 2|0; rid++ )
|
||||
{
|
||||
contents += "<TR>";
|
||||
for( let h = -2|min_harmonics; h <= max_harmonics; h++ )
|
||||
{
|
||||
let tquanta = (quanta&0xffffc);
|
||||
let base = freq * h;
|
||||
let next = freq * (h+1);
|
||||
|
||||
let tgoertzelpoint = tquanta;
|
||||
tgoertzelpoint = ( target - base ) / ( next - base );
|
||||
tgoertzelpoint = ((tgoertzelpoint%1)+1)%1;
|
||||
|
||||
quantaA = tquanta;
|
||||
tgoertzelp = h;
|
||||
if( h == -2 )
|
||||
{
|
||||
if( rid == 0 )
|
||||
{
|
||||
contents += "<TD COLSPAN=1 ROWSPAN=2>"
|
||||
contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+tgoertzelpoint) + ", " + (tgoertzelpoint) + ", " + quantaA + ", 1)'>↑" + n + "</SPAN>";
|
||||
contents += "</TD>"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( rid == 0 )
|
||||
{
|
||||
contents += DrawSpan( 1, 1, freq * (h+tgoertzelpoint), target, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
contents += DrawSpan( 1, 1, freq * (h-tgoertzelpoint), target, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
contents += "</TR>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
contents += "</TABLE>";
|
||||
}
|
||||
|
||||
|
||||
document.getElementById( "TABLE" ).innerHTML = contents;
|
||||
}
|
||||
|
||||
@@ -213,7 +285,11 @@ function onLoad()
|
||||
<TR><TD>Target MHz</TD><TD><INPUT ID=targetmhz VALUE=27.019360></TD></TR>
|
||||
<TR><TD>Quanta</TD><TD><INPUT ID=quanta VALUE=1024> (Goertzel's Only)</TD></TR>
|
||||
<TR><TD>Quanta Search Range</TD><TD><INPUT ID=quantasearch VALUE=64> (Goertzel's Only)</TD></TR>
|
||||
<TR><TD>Table Type</TD><TD><INPUT TYPE=RADIO ID=QUADRATURE NAME=computetype checked>Quadrature</INPUT><INPUT TYPE=RADIO ID=GOERTZELS NAME=computetype>Goertzels</INPUT></TD></TR>
|
||||
<TR><TD>Table Type</TD><TD>
|
||||
<INPUT TYPE=RADIO ID=QUADRATURE NAME=computetype>Quadrature</INPUT>
|
||||
<INPUT TYPE=RADIO ID=GOERTZELS NAME=computetype>Goertzels</INPUT>
|
||||
<INPUT TYPE=RADIO ID=GOERTZEL2 NAME=computetype checked>Goertzel (unalign)</INPUT>
|
||||
</TD></TR>
|
||||
<TR><TD COLSPAN=2><INPUT TYPE=SUBMIT VALUE="Compute" ONCLICK="computeTable()"></TD></TR>
|
||||
</TABLE>
|
||||
</TD>
|
||||
|
||||
Reference in New Issue
Block a user