mirror of
https://github.com/cnlohr/lolra.git
synced 2026-06-15 07:19:25 +00:00
Update table working with goertzel's
This commit is contained in:
@@ -68,20 +68,32 @@ SOFTWARE.
|
||||
#include "ssd1306.h"
|
||||
|
||||
|
||||
#define PWM_PERIOD (31-1)
|
||||
|
||||
#define ADC_BUFFSIZE 512
|
||||
|
||||
#define GOERTZEL_BUFFER 16384
|
||||
#define GOERTZEL_BUFFER 8192
|
||||
|
||||
volatile uint16_t adc_buffer[ADC_BUFFSIZE];
|
||||
|
||||
//const int32_t g_goertzel_omega_per_sample = 151198; // 51/128 * 3.14159 * 65536 * 2
|
||||
//const int32_t g_goertzel_coefficient = -88021;//2 * cos( g_goertzel_omega_per_sample / 65536 * 180 / 3.141592) * 65536;
|
||||
//const int32_t g_goertzel_coefficient_s = 97118;//2 * sin( g_goertzel_omega_per_sample / 65536 * 180 / 3.141592 ) * 65536;
|
||||
const int32_t g_goertzel_omega_per_sample = 1238618695; // 47/256 -> 27.01920 MHz
|
||||
const int32_t g_goertzel_coefficient = 870249096;
|
||||
const int32_t g_goertzel_coefficient_s = 1963250500;
|
||||
//#define PWM_PERIOD (31-1)
|
||||
//const int32_t g_goertzel_omega_per_sample = 1238618695; // 47/256 -> 27.01920 MHz
|
||||
//const int32_t g_goertzel_coefficient = 870249096;
|
||||
//const int32_t g_goertzel_coefficient_s = 1963250500;
|
||||
|
||||
/*
|
||||
#define PWM_PERIOD (31-1)
|
||||
const int32_t g_goertzel_omega_per_sample = 1228662895; // 0.182118 of whole per step / 27.025000MHz
|
||||
const int32_t g_goertzel_coefficient = 888414806;
|
||||
const int32_t g_goertzel_coefficient_s = 1955097223;
|
||||
*/
|
||||
|
||||
#define PWM_PERIOD (28-1)
|
||||
const int32_t g_goertzel_omega_per_sample = 1154616630; // 0.171143 of whole per step / 0.880162MHz
|
||||
const int32_t g_goertzel_coefficient = 1021021706;
|
||||
const int32_t g_goertzel_coefficient_s = 1889232832;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LOG_GOERTZEL_LIST 256
|
||||
int32_t gertzellogs[LOG_GOERTZEL_LIST*2];
|
||||
|
||||
@@ -25,11 +25,11 @@ function DrawSpan( colspan, freq, target, docolor, extrastr = "" )
|
||||
|
||||
function Goertz( n, mhz, fr )
|
||||
{
|
||||
let omega = fr * 2 * 3.1415926535*2.0;
|
||||
let omega = fr * 3.1415926535*2.0;
|
||||
var textarea = document.getElementById("goertzeloutput");
|
||||
textarea.value =
|
||||
"#define PWM_PERIOD ("+n+"-1)\n" +
|
||||
"const int32_t g_goertzel_omega_per_sample = " + ( omega*2*(1<<29)).toFixed(0) + "; // " + mhz.toFixed(6) + "MHz\n" +
|
||||
"const int32_t g_goertzel_omega_per_sample = " + ( omega*2*(1<<29)).toFixed(0) + "; // " + ( omega / (3.1415926535*2.0)).toFixed(6) + " of whole per step / " + mhz.toFixed(6) + "MHz\n" +
|
||||
"const int32_t g_goertzel_coefficient = " + (2 * Math.cos( omega ) * (1<<30)).toFixed(0) + ";\n" +
|
||||
"const int32_t g_goertzel_coefficient_s = "+ (2 * Math.sin( omega ) * (1<<30)).toFixed(0) + ";\n";
|
||||
|
||||
@@ -42,11 +42,14 @@ function Goertz( n, mhz, fr )
|
||||
|
||||
function computeTable()
|
||||
{
|
||||
const max_harmonics = 28|0;
|
||||
const min_harmonics = 1|0;
|
||||
let xtal = Number(document.getElementById("crystalmhz").value );
|
||||
let target = Number(document.getElementById("targetmhz").value );
|
||||
let quadrature = document.getElementById("QUADRATURE").checked;
|
||||
let quanta = Math.round(Number(document.getElementById("quanta").value));
|
||||
|
||||
|
||||
const max_harmonics = 28|0;
|
||||
const min_harmonics = (quadrature?1:0)|0;
|
||||
|
||||
let contents = "";
|
||||
|
||||
@@ -74,7 +77,7 @@ function computeTable()
|
||||
"<TABLE BORDER=1>" +
|
||||
"<TR><TD>Goertzel</TD></TR>" +
|
||||
"<TR><TD>Goertzel (Inverse)</TD></TR>" +
|
||||
"</TABLE><TEXTAREA ROWS=5 COLS=80 ID=goertzeloutput></TEXTAREA>";
|
||||
"</TABLE><TEXTAREA ROWS=5 COLS=120 ID=goertzeloutput></TEXTAREA>";
|
||||
}
|
||||
|
||||
contents += "<TABLE BORDER=1>";
|
||||
@@ -89,15 +92,22 @@ function computeTable()
|
||||
let freq = ( xtal / n );
|
||||
let goertzelpoint = 0;
|
||||
let goertzelpointinv = 0;
|
||||
let tgoertzelp = 0;
|
||||
let tgoertzelpi = 0;
|
||||
for( let h = 0|min_harmonics; h <= max_harmonics; h++ )
|
||||
{
|
||||
let base = freq * h;
|
||||
let next = freq * (h+1);
|
||||
if( target <= next && target >= base )
|
||||
{
|
||||
var t;
|
||||
goertzelpoint = ( target - base ) / ( next - base );
|
||||
goertzelpoint = Math.round(quanta * goertzelpoint)/quanta;
|
||||
|
||||
goertzelpointinv = - (1.0 - ( target - base ) / ( next - base ));
|
||||
tgoertzelp = h;
|
||||
goertzelpointinv = (1.0 - ( target - base ) / ( next - base ));
|
||||
goertzelpointinv = Math.round(quanta * goertzelpointinv)/quanta;
|
||||
tgoertzelpi = h+1;
|
||||
}
|
||||
}
|
||||
contents += "</TR>";
|
||||
@@ -124,7 +134,9 @@ function computeTable()
|
||||
{
|
||||
if( mode == 0 )
|
||||
{
|
||||
contents += "<TD COLSPAN=2><SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+goertzelpoint) + ", " + (-goertzelpointinv) + ")'>↑" + (-goertzelpointinv).toFixed(6) + "</SPAN></TD>";
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelp == h ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+goertzelpoint) + ", " + (goertzelpoint) + ")'>↑" + (goertzelpoint).toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 1 )
|
||||
{
|
||||
@@ -132,11 +144,13 @@ function computeTable()
|
||||
}
|
||||
else if( mode == 2 )
|
||||
{
|
||||
contents += "<TD COLSPAN=2><SPAN ONCLICK='Goertz(" + n + ", " + freq * (h+goertzelpointinv) + ", " + goertzelpoint + ")'>↓" + goertzelpoint.toFixed(6) + "</SPAN></TD>";
|
||||
contents += "<TD COLSPAN=2>"
|
||||
if( tgoertzelp == h-1 ) contents += "<SPAN ONCLICK='Goertz(" + n + ", " + freq * (h-goertzelpointinv) + ", " + goertzelpointinv + ")'>↓" + goertzelpointinv.toFixed(6) + "</SPAN>";
|
||||
contents += "</TD>";
|
||||
}
|
||||
else if( mode == 3 )
|
||||
{
|
||||
contents += DrawSpan( 2, freq * (h+goertzelpointinv), target, true );
|
||||
contents += DrawSpan( 2, freq * (h-goertzelpointinv), target, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,6 +170,7 @@ function computeTable()
|
||||
<TABLE>
|
||||
<TR><TD>Crystal MHz</TD><TD><INPUT ID=crystalmhz VALUE=144></TD></TR>
|
||||
<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 Algorithm 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 COLSPAN=2><INPUT TYPE=SUBMIT VALUE="Compute" ONCLICK="computeTable()"></TD></TR>
|
||||
</TABLE>
|
||||
|
||||
Reference in New Issue
Block a user