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
61 changes: 61 additions & 0 deletions FilterReview/FilterReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,62 @@ function HarmonicNotchFilter(params) {
return this
}

// Show how much of the analysis time is used for raw data, highlight if a lot is lost
function update_usable_data() {
for (let i = 0; i < 3; i++) {
let usable = null
if (Gyro_batch.type == "raw") {
for (let j = 0; j < Gyro_batch.length; j++) {
if ((Gyro_batch[j] == null) || (Gyro_batch[j].sensor_num != i) || (Gyro_batch[j].FFT == null)) {
continue
}
const fraction = get_usable_fraction(Gyro_batch[j].FFT)
if ((fraction != null) && ((usable == null) || (fraction < usable))) {
usable = fraction
}
}
}
// Only shown when there is a value
document.getElementById("Gyro" + i + "_usable_line").style.display = (usable == null) ? "none" : ""
const percent = Math.round((usable ?? 0) * 100)
let label = document.getElementById("Gyro" + i + "_usable")
label.style.color = ((usable != null) && (percent < usable_data_warn_fraction * 100)) ? "#c00000" : ""
label.textContent = "Usable data: " + percent + "% of analysis time"
}
}

// Fraction of the analysis time covered by the FFT windows used. Data is lost where it is missing from the
// log, and at the end of each continuous section where there is not enough left for another whole window,
// so this depends on the window size.
const usable_data_warn_fraction = 0.9
function get_usable_fraction(FFT) {
// Clip to the time covered by all IMUs, so an IMU that starts late or stops early counts as lost data
const start = Math.max(parseFloat(document.getElementById("TimeStart").value), Gyro_batch.start_time)
const end = Math.min(parseFloat(document.getElementById("TimeEnd").value), Gyro_batch.end_time)
if (!(end > start)) {
return null
}
if (FFT.time.length == 0) {
return 0
}

// Windows are in time order and overlap, count the time covered by any window once
const half_window = FFT.window_size / FFT.average_sample_rate / 2
let covered = 0
let covered_to = start
const start_index = find_start_index(FFT.time)
const end_index = find_end_index(FFT.time)
for (let j = start_index; j <= end_index; j++) {
const window_start = Math.max(FFT.time[j] - half_window, covered_to)
const window_end = Math.min(FFT.time[j] + half_window, end)
if (window_end > window_start) {
covered += window_end - window_start
covered_to = window_end
}
}
return covered / (end - start)
}

function run_batch_fft(data_set) {
const num_batch = data_set.length
const num_points = data_set[0].x.length
Expand Down Expand Up @@ -394,6 +450,7 @@ function reset() {
}
document.getElementById("SpecGyroInst" + i).disabled = true
document.getElementById("BodeGyroInst" + i).disabled = true
document.getElementById("Gyro" + i + "_usable_line").style.display = "none"

let fieldset = document.getElementById("Gyro" + i)
fieldset.style["border-color"] = "rgb(192, 192, 192)"
Expand Down Expand Up @@ -763,6 +820,8 @@ function re_calc() {

calculate()

update_usable_data()

load_filters()

calculate_transfer_function()
Expand Down Expand Up @@ -2690,6 +2749,8 @@ async function load(log_file) {
// Calculate FFT
calculate()

update_usable_data()

// Update transfer function from filter setting
calculate_transfer_function()

Expand Down
3 changes: 3 additions & 0 deletions FilterReview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ <h2 style="text-align:center">IMU Spectrum
</p>
Logging rate: <label id="Gyro0_FFT_infoA"></label> Hz<br><br>
Frequency resolution: <label id="Gyro0_FFT_infoB"></label> Hz
<span id="Gyro0_usable_line" style="display:none"><br><br><label id="Gyro0_usable">Usable data:</label></span>
</fieldset>
</td>
<td>
Expand Down Expand Up @@ -284,6 +285,7 @@ <h2 style="text-align:center">IMU Spectrum
</p>
Logging rate: <label id="Gyro1_FFT_infoA"></label> Hz<br><br>
Frequency resolution: <label id="Gyro1_FFT_infoB"></label> Hz
<span id="Gyro1_usable_line" style="display:none"><br><br><label id="Gyro1_usable">Usable data:</label></span>
</fieldset>
</td>
<td>
Expand Down Expand Up @@ -337,6 +339,7 @@ <h2 style="text-align:center">IMU Spectrum
</p>
Logging rate: <label id="Gyro2_FFT_infoA"></label> Hz<br><br>
Frequency resolution: <label id="Gyro2_FFT_infoB"></label> Hz
<span id="Gyro2_usable_line" style="display:none"><br><br><label id="Gyro2_usable">Usable data:</label></span>
</fieldset>
</td>
</tr>
Expand Down
Loading