Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions FilterReview/FilterReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,18 @@ function MultiNotch(attenuation_dB, bandwidth_hz, harmonic, min_freq_fun, num, c
this.notches = []
this.notches.push(new NotchFilter(attenuation_dB, bw_scaled, harmonic, min_freq_fun, 1.0 - notch_spread))
this.notches.push(new NotchFilter(attenuation_dB, bw_scaled, harmonic, min_freq_fun, 1.0 + notch_spread))
if (num == 3) {
if (num >= 3) {
this.notches.push(new NotchFilter(attenuation_dB, bw_scaled, harmonic, min_freq_fun, 1.0))
}
if (num == 5) {
this.notches.push(new NotchFilter(attenuation_dB, bw_scaled, harmonic, min_freq_fun, 1.0 - (2.0 * notch_spread)))
this.notches.push(new NotchFilter(attenuation_dB, bw_scaled, harmonic, min_freq_fun, 1.0 + (2.0 * notch_spread)))
}

this.transfer = function(Hn, Hd, center, sample_freq, Z1, Z2) {
this.notches[0].transfer(Hn, Hd, center, sample_freq, Z1, Z2)
this.notches[1].transfer(Hn, Hd, center, sample_freq, Z1, Z2)
if (this.notches.length == 3) {
this.notches[2].transfer(Hn, Hd, center, sample_freq, Z1, Z2)
const len = this.notches.length
for (let i = 0; i<len; i++) {
this.notches[i].transfer(Hn, Hd, center, sample_freq, Z1, Z2)
}
}

Expand Down Expand Up @@ -200,11 +203,26 @@ function HarmonicNotchFilter(params) {
return this
}

const filter_version = get_filter_version()

const quintuple = (this.params.options & 64) != 0
const triple = (this.params.options & 16) != 0
const double = (this.params.options & 1) != 0
const single = !double && !triple

const filter_V1 = get_filter_version() == 1
let num_composite_notches = 1
if (double) {
num_composite_notches = 2
} else if (triple) {
num_composite_notches = 3
} else if (quintuple) {
if (filter_version < 3) {
alert("Quintuple notch only supported with filter version 3 or later")
} else {
num_composite_notches = 5
}
}

const filter_V1 = filter_version == 1
const treat_low_freq_as_min = (this.params.options & 32) != 0

this.get_min_freq = function(harmonic) {
Expand All @@ -222,10 +240,10 @@ function HarmonicNotchFilter(params) {
for (var n=0; n<max_num_harmonics; n++) {
if (this.params.harmonics & (1<<n)) {
const harmonic = n + 1
if (single) {
if (num_composite_notches == 1) {
this.notches.push(new NotchFilter(this.params.attenuation, this.params.bandwidth * harmonic, harmonic, (h) => { return this.get_min_freq(h) }, 1.0))
} else {
this.notches.push(new MultiNotch(this.params.attenuation, this.params.bandwidth, harmonic, (h) => { return this.get_min_freq(h) }, double ? 2 : 3, this.params.freq))
this.notches.push(new MultiNotch(this.params.attenuation, this.params.bandwidth, harmonic, (h) => { return this.get_min_freq(h) }, num_composite_notches, this.params.freq))
}
}
}
Expand Down Expand Up @@ -356,6 +374,7 @@ function reset() {
document.getElementById("filter_version_1").disabled = true
document.getElementById("filter_version_1").checked = true
document.getElementById("filter_version_2").disabled = true
document.getElementById("filter_version_3").disabled = true
document.getElementById("calculate").disabled = true
document.getElementById("calculate_filters").disabled = true
document.getElementById("OpenFilterTool").disabled = true
Expand Down Expand Up @@ -1991,7 +2010,7 @@ function get_filter_version() {

// Update the filter vesion from user buttons
function update_filter_version() {
const versions = [1, 2]
const versions = [1, 2, 3]
for (const version of versions) {
const version_radio_button = document.getElementById("filter_version_" + version)
if (version_radio_button.checked) {
Expand Down Expand Up @@ -2407,6 +2426,7 @@ async function load(log_file) {
}
document.getElementById("filter_version_1").disabled = false
document.getElementById("filter_version_2").disabled = false
document.getElementById("filter_version_3").disabled = false

// Load potential sources of notch tracking targets
tracking_methods = [new StaticTarget(),
Expand Down
2 changes: 2 additions & 0 deletions FilterReview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ <h1 style="text-align:center; margin-block-end: 0.25em;"><a href="" style="color
<label for="filter_version_1">1.0</label><br>
<input type="radio" id="filter_version_2" name="filter_version" onchange="loading_call(re_calc)">
<label for="filter_version_2">2.0</label><br>
<input type="radio" id="filter_version_3" name="filter_version" onchange="loading_call(re_calc)">
<label for="filter_version_3">3.0</label><br>
</fieldset>
</td>
<td style="width: 10px;"></td>
Expand Down
Loading