Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6676b66993 | ||
|
|
412651d612 | ||
|
|
d347b493d9 |
@@ -840,6 +840,8 @@ let jogMult = loadSetting("jogMult", 1); // divisor: 1, 10, 100
|
|||||||
let jogStep = Math.max(Math.round(jogUnit / jogMult), 1);
|
let jogStep = Math.max(Math.round(jogUnit / jogMult), 1);
|
||||||
let minFreqStepHz = 1;
|
let minFreqStepHz = 1;
|
||||||
let lastModeName = "";
|
let lastModeName = "";
|
||||||
|
let lastWfmCci = 0;
|
||||||
|
let lastWfmAci = 0;
|
||||||
const VFO_COLORS = ["var(--accent-green)", "var(--accent-yellow)"];
|
const VFO_COLORS = ["var(--accent-green)", "var(--accent-yellow)"];
|
||||||
function vfoColor(idx) {
|
function vfoColor(idx) {
|
||||||
if (idx < VFO_COLORS.length) return VFO_COLORS[idx];
|
if (idx < VFO_COLORS.length) return VFO_COLORS[idx];
|
||||||
@@ -3293,8 +3295,14 @@ function render(update) {
|
|||||||
wfmStFlagEl.classList.toggle("wfm-st-flag-stereo", detected);
|
wfmStFlagEl.classList.toggle("wfm-st-flag-stereo", detected);
|
||||||
wfmStFlagEl.classList.toggle("wfm-st-flag-mono", !detected);
|
wfmStFlagEl.classList.toggle("wfm-st-flag-mono", !detected);
|
||||||
}
|
}
|
||||||
if (typeof update.filter.wfm_cci === "number") updateIntfBar(wfmCciFillEl, wfmCciValEl, update.filter.wfm_cci);
|
if (typeof update.filter.wfm_cci === "number") {
|
||||||
if (typeof update.filter.wfm_aci === "number") updateIntfBar(wfmAciFillEl, wfmAciValEl, update.filter.wfm_aci);
|
lastWfmCci = Math.max(0, Math.min(100, update.filter.wfm_cci));
|
||||||
|
updateIntfBar(wfmCciFillEl, wfmCciValEl, lastWfmCci);
|
||||||
|
}
|
||||||
|
if (typeof update.filter.wfm_aci === "number") {
|
||||||
|
lastWfmAci = Math.max(0, Math.min(100, update.filter.wfm_aci));
|
||||||
|
updateIntfBar(wfmAciFillEl, wfmAciValEl, lastWfmAci);
|
||||||
|
}
|
||||||
if (samStereoWidthEl && typeof update.filter.sam_stereo_width === "number") {
|
if (samStereoWidthEl && typeof update.filter.sam_stereo_width === "number") {
|
||||||
samStereoWidthEl.value = String(Math.round(update.filter.sam_stereo_width * 100));
|
samStereoWidthEl.value = String(Math.round(update.filter.sam_stereo_width * 100));
|
||||||
}
|
}
|
||||||
@@ -4268,7 +4276,7 @@ const MODE_BW_DEFAULTS = {
|
|||||||
FM: [12_500, 2_500, 25_000, 500],
|
FM: [12_500, 2_500, 25_000, 500],
|
||||||
AIS: [25_000, 12_500, 50_000, 500],
|
AIS: [25_000, 12_500, 50_000, 500],
|
||||||
VDES: [100_000, 25_000, 200_000, 1_000],
|
VDES: [100_000, 25_000, 200_000, 1_000],
|
||||||
WFM: [180_000, 50_000,300_000,5_000],
|
WFM: [180_000, 60_000,300_000,5_000],
|
||||||
DIG: [3_000, 300, 6_000, 100],
|
DIG: [3_000, 300, 6_000, 100],
|
||||||
PKT: [25_000, 300, 50_000, 500],
|
PKT: [25_000, 300, 50_000, 500],
|
||||||
};
|
};
|
||||||
@@ -4348,64 +4356,110 @@ async function applyBandwidthFromInput() {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function estimateBandwidthAroundPeak(data, centerHz) {
|
function estimateOccupiedBandwidth(data, centerHz, interference = {}) {
|
||||||
if (!data || !isBinsArray(data.bins) || data.bins.length < 3 || !Number.isFinite(centerHz)) {
|
if (!data || !isBinsArray(data.bins) || data.bins.length < 3 || !Number.isFinite(centerHz)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bins = data.bins;
|
const bins = data.bins;
|
||||||
const maxIdx = bins.length - 1;
|
const maxIdx = bins.length - 1;
|
||||||
|
const hzPerBin = data.sample_rate / maxIdx;
|
||||||
const fullLoHz = data.center_hz - data.sample_rate / 2;
|
const fullLoHz = data.center_hz - data.sample_rate / 2;
|
||||||
const centerIdx = Math.max(
|
const centerIdx = Math.max(
|
||||||
1,
|
1,
|
||||||
Math.min(maxIdx - 1, Math.round(((centerHz - fullLoHz) / data.sample_rate) * maxIdx)),
|
Math.min(maxIdx - 1, Math.round(((centerHz - fullLoHz) / data.sample_rate) * maxIdx)),
|
||||||
);
|
);
|
||||||
const searchRadius = Math.max(6, Math.min(120, Math.round(maxIdx * 0.03)));
|
const mode = (modeEl ? modeEl.value : "USB").toUpperCase();
|
||||||
const searchLo = Math.max(1, centerIdx - searchRadius);
|
const [defaultBw, minBw, maxBw, stepBw] = mwDefaultsForMode(mode);
|
||||||
const searchHi = Math.min(maxIdx - 1, centerIdx + searchRadius);
|
const oneSided = mode === "USB" || mode === "DIG" || mode === "CW"
|
||||||
|
? 1
|
||||||
let peakIdx = centerIdx;
|
: mode === "LSB" || mode === "CWR" ? -1 : 0;
|
||||||
for (let i = searchLo; i <= searchHi; i++) {
|
const isWfm = mode === "WFM";
|
||||||
if (bins[i] > bins[peakIdx]) peakIdx = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Reduce single-bin peaks and holes before finding occupied-channel edges.
|
||||||
|
// WFM needs a wider smoothing window because its energy is noise-like and
|
||||||
|
// spread across the entire channel rather than concentrated at a carrier.
|
||||||
|
const smoothRadius = isWfm ? 3 : 1;
|
||||||
|
const smoothed = bins.map((_, i) => {
|
||||||
|
let sum = 0;
|
||||||
|
let count = 0;
|
||||||
|
for (let j = Math.max(0, i - smoothRadius); j <= Math.min(maxIdx, i + smoothRadius); j++) {
|
||||||
|
sum += bins[j];
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
return sum / count;
|
||||||
|
});
|
||||||
const sorted = [...bins].sort((a, b) => a - b);
|
const sorted = [...bins].sort((a, b) => a - b);
|
||||||
const noise = sorted[Math.floor(sorted.length * 0.2)];
|
const noise = sorted[Math.floor(sorted.length * 0.2)];
|
||||||
const peak = bins[peakIdx];
|
const maxSpanBins = Math.max(2, Math.ceil(maxBw / hzPerBin));
|
||||||
const threshold = Math.max(noise + 4, peak - Math.max(8, (peak - noise) * 0.35));
|
const searchHalfBins = oneSided === 0 ? Math.ceil(maxSpanBins / 2) : maxSpanBins;
|
||||||
|
const searchLo = Math.max(1, centerIdx - (oneSided > 0 ? 2 : searchHalfBins));
|
||||||
|
const searchHi = Math.min(maxIdx - 1, centerIdx + (oneSided < 0 ? 2 : searchHalfBins));
|
||||||
|
let peak = -Infinity;
|
||||||
|
for (let i = searchLo; i <= searchHi; i++) peak = Math.max(peak, smoothed[i]);
|
||||||
|
const snr = peak - noise;
|
||||||
|
if (!Number.isFinite(snr) || snr < (isWfm ? 5 : 4)) return isWfm ? minBw : defaultBw;
|
||||||
|
|
||||||
let left = peakIdx;
|
// A threshold relative to the noise floor finds occupied bandwidth much
|
||||||
let right = peakIdx;
|
// more reliably than one relative to the peak. The latter fails for WFM,
|
||||||
let belowCount = 0;
|
// whose multiplex spectrum has peaks, notches, and no narrow centre carrier.
|
||||||
for (let i = peakIdx; i > 1; i--) {
|
const threshold = noise + Math.max(3, Math.min(isWfm ? 6 : 10, snr * (isWfm ? 0.18 : 0.28)));
|
||||||
if (bins[i] < threshold) belowCount += 1;
|
const allowedGap = Math.max(isWfm ? 4 : 2, Math.ceil((isWfm ? 12_000 : stepBw) / hzPerBin));
|
||||||
else belowCount = 0;
|
|
||||||
if (belowCount >= 2) break;
|
function occupiedExtent(direction, limitBins) {
|
||||||
left = i;
|
let lastOccupied = centerIdx;
|
||||||
|
let gap = 0;
|
||||||
|
for (let n = 0; n <= limitBins; n++) {
|
||||||
|
const i = centerIdx + direction * n;
|
||||||
|
if (i <= 0 || i >= maxIdx) break;
|
||||||
|
if (smoothed[i] >= threshold) {
|
||||||
|
lastOccupied = i;
|
||||||
|
gap = 0;
|
||||||
|
} else if (++gap > allowedGap) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Math.abs(lastOccupied - centerIdx) * hzPerBin;
|
||||||
}
|
}
|
||||||
|
|
||||||
belowCount = 0;
|
let rawBw;
|
||||||
for (let i = peakIdx; i < maxIdx - 1; i++) {
|
if (oneSided !== 0) {
|
||||||
if (bins[i] < threshold) belowCount += 1;
|
rawBw = occupiedExtent(oneSided, maxSpanBins);
|
||||||
else belowCount = 0;
|
} else {
|
||||||
if (belowCount >= 2) break;
|
const leftHz = occupiedExtent(-1, searchHalfBins);
|
||||||
right = i;
|
const rightHz = occupiedExtent(1, searchHalfBins);
|
||||||
|
// A symmetric RF filter must contain the larger of the two sidebands.
|
||||||
|
rawBw = 2 * Math.max(leftHz, rightHz);
|
||||||
}
|
}
|
||||||
|
|
||||||
const shoulderPad = Math.max(1, Math.round((right - left) * 0.08));
|
// Add a transition-band margin. Weak WFM deliberately falls back to the
|
||||||
left = Math.max(0, left - shoulderPad);
|
// 60 kHz mode floor above: a narrower filter trades stereo/RDS content for
|
||||||
right = Math.min(maxIdx, right + shoulderPad);
|
// a useful improvement in intelligibility when the signal is very poor.
|
||||||
|
rawBw *= isWfm ? 1.08 : 1.12;
|
||||||
const hzPerBin = data.sample_rate / maxIdx;
|
if (isWfm) {
|
||||||
const rawBw = Math.max(hzPerBin, (right - left) * hzPerBin);
|
const aci = Math.max(0, Math.min(100, Number(interference.aci) || 0)) / 100;
|
||||||
const [, minBw, maxBw, stepBw] = mwDefaultsForMode(modeEl ? modeEl.value : "USB");
|
const cci = Math.max(0, Math.min(100, Number(interference.cci) || 0)) / 100;
|
||||||
|
// Adjacent-channel energy is outside the wanted modulation, so ACI can
|
||||||
|
// safely drive the cap all the way from the 300 kHz ceiling to 60 kHz.
|
||||||
|
const aciCap = maxBw - (maxBw - minBw) * aci;
|
||||||
|
// CCI overlaps the wanted station and cannot be removed by an RF filter.
|
||||||
|
// Only distrust the widest edge estimates, retaining at least 65% of the
|
||||||
|
// useful range between the weak-signal floor and nominal WFM bandwidth.
|
||||||
|
const cciFloor = minBw + (defaultBw - minBw) * 0.65;
|
||||||
|
const cciCap = maxBw - (maxBw - cciFloor) * cci;
|
||||||
|
rawBw = Math.min(rawBw, aciCap, cciCap);
|
||||||
|
}
|
||||||
const clamped = Math.max(minBw, Math.min(maxBw, rawBw));
|
const clamped = Math.max(minBw, Math.min(maxBw, rawBw));
|
||||||
return Math.max(stepBw, Math.round(clamped / stepBw) * stepBw);
|
return Math.max(stepBw, Math.round(clamped / stepBw) * stepBw);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyAutoBandwidth() {
|
async function applyAutoBandwidth() {
|
||||||
if (!lastSpectrumData || lastFreqHz == null) return;
|
if (!lastSpectrumData || lastFreqHz == null) return;
|
||||||
const estimated = estimateBandwidthAroundPeak(lastSpectrumData, lastFreqHz);
|
// WFM interference telemetry belongs to the primary DSP channel. Do not
|
||||||
|
// apply it to a virtual channel, where it would describe the wrong signal.
|
||||||
|
const onVirtual = typeof vchanIsOnVirtual === "function" && vchanIsOnVirtual();
|
||||||
|
const interference = onVirtual ? {} : { cci: lastWfmCci, aci: lastWfmAci };
|
||||||
|
const estimated = estimateOccupiedBandwidth(lastSpectrumData, lastFreqHz, interference);
|
||||||
if (!Number.isFinite(estimated) || estimated <= 0) {
|
if (!Number.isFinite(estimated) || estimated <= 0) {
|
||||||
syncBandwidthInput(currentBandwidthHz);
|
syncBandwidthInput(currentBandwidthHz);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user