Fix RTA peak hold and FFT band energy

This commit is contained in:
Mikei386
2026-07-22 08:42:32 +02:00
parent caec1edfcf
commit 3a0bdbb5ad
13 changed files with 394 additions and 87 deletions
+1 -5
View File
@@ -138,22 +138,18 @@ export function buildBandBinMapping(bands, nyq, binCount) {
const bins = [];
const start = Math.max(0, Math.floor((band.fLo / nyq) * binCount));
const end = Math.min(binCount - 1, Math.ceil((band.fHi / nyq) * binCount));
let weightSum = 0;
for (let i = start; i <= end; i++) {
const binStart = i * binWidth;
const binEnd = binStart + binWidth;
const overlap = Math.max(0, Math.min(binEnd, band.fHi) - Math.max(binStart, band.fLo));
if (overlap > 0) {
bins.push({ index: i, weight: overlap });
weightSum += overlap;
bins.push({ index: i, weight: Math.min(1, overlap / binWidth) });
}
}
if (!bins.length) {
const idx = Math.max(0, Math.min(binCount - 1, Math.round((band.center / nyq) * binCount)));
bins.push({ index: idx, weight: 1 });
weightSum = 1;
}
bins.forEach((b) => { b.weight /= weightSum || 1; });
result.push({
center: band.center,
fLo: band.fLo,