@ -360,7 +360,8 @@ function run_filters(filters,freq,sample_rate,samples,fast_filters = null,fast_s
@@ -360,7 +360,8 @@ function run_filters(filters,freq,sample_rate,samples,fast_filters = null,fast_s
return [ amplitude , phase ] ;
}
var chart ;
var chart _attenuation ;
var chart _phase ;
var freq _log _scale ;
function get _filters ( sample _rate ) {
@ -466,25 +467,25 @@ function calculate_filter() {
@@ -466,25 +467,25 @@ function calculate_filter() {
setCookie ( "feq_scale" , freq _log ? "Log" : "Linear" ) ;
if ( ( freq _log _scale != null ) && ( freq _log _scale != freq _log ) ) {
// Scale changed, no easy way to update, delete chart and re-draw
chart . clear ( ) ;
chart . destroy ( ) ;
chart = null ;
chart _attenuation . clear ( ) ;
chart _attenuation . destroy ( ) ;
chart _attenuation = null ;
chart _phase . clear ( ) ;
chart _phase . destroy ( ) ;
chart _phase = null ;
}
freq _log _scale = freq _log ;
if ( chart ) {
chart . data . datasets [ 0 ] . data = attenuation ;
chart . data . datasets [ 1 ] . data = phase _lag ;
chart . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
chart . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
chart . options . scales . yAxes [ 0 ] . ticks . min = min _atten
chart . options . scales . yAxes [ 0 ] . ticks . max = max _atten ;
chart . options . scales . yAxes [ 0 ] . scaleLabel . labelString = atten _string ;
chart . options . scales . yAxes [ 1 ] . ticks . min = - max _phase _lag ;
chart . options . scales . yAxes [ 1 ] . ticks . max = - min _phase _lag ;
chart . update ( ) ;
if ( chart _attenuation ) {
chart _attenuation . data . datasets [ 0 ] . data = attenuation ;
chart _attenuation . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
chart _attenuation . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
chart _attenuation . options . scales . yAxes [ 0 ] . ticks . min = min _atten
chart _attenuation . options . scales . yAxes [ 0 ] . ticks . max = max _atten ;
chart _attenuation . options . scales . yAxes [ 0 ] . scaleLabel . labelString = atten _string ;
chart _attenuation . update ( ) ;
} else {
chart = new Chart ( "Attenuation" , {
chart _attenuation = new Chart ( "Attenuation" , {
type : "scatter" ,
data : {
datasets : [
@ -499,6 +500,59 @@ function calculate_filter() {
@@ -499,6 +500,59 @@ function calculate_filter() {
showLine : true ,
fill : false
} ,
]
} ,
options : {
aspectRatio : 3 ,
legend : { display : false } ,
scales : {
yAxes : [
{
scaleLabel : { display : true , labelString : atten _string } ,
id : 'Magnitude' ,
ticks : { min : min _atten , max : max _atten }
} ,
] ,
xAxes : [
{
type : ( freq _log ? "logarithmic" : "linear" ) ,
scaleLabel : { display : true , labelString : freq _string } ,
ticks :
{
min : 0.0 ,
max : freq _max ,
callback : function ( value , index , ticks ) {
return value ;
} ,
}
}
] ,
} ,
tooltips : {
callbacks : {
label : function ( tooltipItem , data ) {
// round tooltip to two decimal places
return tooltipItem . xLabel . toFixed ( 2 ) + ', ' + tooltipItem . yLabel . toFixed ( 2 ) ;
}
}
}
}
} ) ;
}
if ( chart _phase ) {
chart _phase . data . datasets [ 0 ] . data = phase _lag ;
chart _phase . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
chart _phase . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
chart _phase . options . scales . yAxes [ 0 ] . ticks . min = - max _phase _lag ;
chart _phase . options . scales . yAxes [ 0 ] . ticks . max = - min _phase _lag ;
chart _phase . update ( ) ;
} else {
chart _phase = new Chart ( "Phase" , {
type : "scatter" ,
data : {
datasets : [
{
label : 'Phase' ,
yAxisID : 'Phase' ,
@ -513,20 +567,13 @@ function calculate_filter() {
@@ -513,20 +567,13 @@ function calculate_filter() {
]
} ,
options : {
legend : { display : true } ,
aspectRatio : 3 ,
legend : { display : false } ,
scales : {
yAxes : [
{
scaleLabel : { display : true , labelString : atten _string } ,
id : 'Magnitude' ,
position : 'left' ,
ticks : { min : min _atten , max : max _atten }
} ,
{
scaleLabel : { display : true , labelString : "Phase (deg)" } ,
id : 'Phase' ,
position : 'right' ,
gridLines : { display : false } ,
ticks : { min : - max _phase _lag , max : - min _phase _lag }
}
] ,
@ -558,7 +605,8 @@ function calculate_filter() {
@@ -558,7 +605,8 @@ function calculate_filter() {
}
}
var PID _chart ;
var PID _attenuation ;
var PID _phase ;
var PID _freq _log _scale ;
function calculate _pid ( axis _id ) {
@ -668,25 +716,25 @@ function calculate_pid(axis_id) {
@@ -668,25 +716,25 @@ function calculate_pid(axis_id) {
setCookie ( "PID_feq_scale" , use _dB ? "Log" : "Linear" ) ;
if ( ( PID _freq _log _scale != null ) && ( PID _freq _log _scale != freq _log ) ) {
// Scale changed, no easy way to update, delete chart and re-draw
PID _chart . clear ( ) ;
PID _chart . destroy ( ) ;
PID _chart = null ;
PID _attenuation . clear ( ) ;
PID _attenuation . destroy ( ) ;
PID _attenuation = null ;
PID _phase . clear ( ) ;
PID _phase . destroy ( ) ;
PID _phase = null ;
}
PID _freq _log _scale = freq _log ;
if ( PID _chart ) {
PID _chart . data . datasets [ 0 ] . data = attenuation ;
PID _chart . data . datasets [ 1 ] . data = phase _lag ;
PID _chart . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
PID _chart . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
PID _chart . options . scales . yAxes [ 0 ] . ticks . min = min _atten
PID _chart . options . scales . yAxes [ 0 ] . ticks . max = max _atten ;
PID _chart . options . scales . yAxes [ 0 ] . scaleLabel . labelString = atten _string ;
PID _chart . options . scales . yAxes [ 1 ] . ticks . min = - max _phase _lag ;
PID _chart . options . scales . yAxes [ 1 ] . ticks . max = - min _phase _lag ;
PID _chart . update ( ) ;
if ( PID _attenuation ) {
PID _attenuation . data . datasets [ 0 ] . data = attenuation ;
PID _attenuation . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
PID _attenuation . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
PID _attenuation . options . scales . yAxes [ 0 ] . ticks . min = min _atten
PID _attenuation . options . scales . yAxes [ 0 ] . ticks . max = max _atten ;
PID _attenuation . options . scales . yAxes [ 0 ] . scaleLabel . labelString = atten _string ;
PID _attenuation . update ( ) ;
} else {
PID _ch ar t = new Chart ( "PID_Attenuation" , {
PID _attenuation = new Chart ( "PID_Attenuation" , {
type : "scatter" ,
data : {
datasets : [
@ -701,6 +749,60 @@ function calculate_pid(axis_id) {
@@ -701,6 +749,60 @@ function calculate_pid(axis_id) {
showLine : true ,
fill : false
} ,
]
} ,
options : {
aspectRatio : 3 ,
legend : { display : false } ,
scales : {
yAxes : [
{
scaleLabel : { display : true , labelString : atten _string } ,
id : 'Gain' ,
position : 'left' ,
ticks : { min : min _atten , max : max _atten }
} ,
] ,
xAxes : [
{
type : ( freq _log ? "logarithmic" : "linear" ) ,
scaleLabel : { display : true , labelString : freq _string } ,
ticks :
{
min : 0.0 ,
max : freq _max ,
callback : function ( value , index , ticks ) {
return value ;
} ,
}
}
] ,
} ,
tooltips : {
callbacks : {
label : function ( tooltipItem , data ) {
// round tooltip to two decimal places
return tooltipItem . xLabel . toFixed ( 2 ) + ', ' + tooltipItem . yLabel . toFixed ( 2 ) ;
}
}
}
}
} ) ;
}
if ( PID _phase ) {
PID _phase . data . datasets [ 0 ] . data = phase _lag ;
PID _phase . options . scales . xAxes [ 0 ] . ticks . max = freq _max ;
PID _phase . options . scales . xAxes [ 0 ] . scaleLabel . labelString = freq _string
PID _phase . options . scales . yAxes [ 0 ] . ticks . min = - max _phase _lag ;
PID _phase . options . scales . yAxes [ 0 ] . ticks . max = - min _phase _lag ;
PID _phase . update ( ) ;
} else {
PID _phase = new Chart ( "PID_Phase" , {
type : "scatter" ,
data : {
datasets : [
{
label : 'PhaseLag' ,
yAxisID : 'PhaseLag' ,
@ -715,20 +817,13 @@ function calculate_pid(axis_id) {
@@ -715,20 +817,13 @@ function calculate_pid(axis_id) {
]
} ,
options : {
legend : { display : true } ,
aspectRatio : 3 ,
legend : { display : false } ,
scales : {
yAxes : [
{
scaleLabel : { display : true , labelString : atten _string } ,
id : 'Gain' ,
position : 'left' ,
ticks : { min : min _atten , max : max _atten }
} ,
{
scaleLabel : { display : true , labelString : "Phase (deg)" } ,
id : 'PhaseLag' ,
position : 'right' ,
gridLines : { display : false } ,
ticks : { min : - max _phase _lag , max : - min _phase _lag }
}
] ,