channel frequency resolution padding

This commit is contained in:
Lewis Moten
2024-05-06 04:14:54 -04:00
parent 154c125bfe
commit ab2ac347e0
2 changed files with 15 additions and 8 deletions

View File

@@ -67,6 +67,7 @@
FFT Size: 2^<input id="fft-size-power-text" type="number" min="5" max="15" value="90"><br> FFT Size: 2^<input id="fft-size-power-text" type="number" min="5" max="15" value="90"><br>
Frequency Resolution Multiplier: <input id="frequency-resolution-multiplier" type="number" min="1" max="20" Frequency Resolution Multiplier: <input id="frequency-resolution-multiplier" type="number" min="1" max="20"
value="2"><br> value="2"><br>
Channel Frequency Resolution Padding: <input id="channel-frequency-resolution-padding" type="number" min="0" max="20"><br>
Smoothing Time Constant: <input id="smoothing-time-constant-text" type="number" min="0.00" max="1.00" step="0.01" Smoothing Time Constant: <input id="smoothing-time-constant-text" type="number" min="0.00" max="1.00" step="0.01"
value="0.00"><br> value="0.00"><br>
<label> <label>

View File

@@ -10,21 +10,22 @@ var receivedDataTextarea;
var sentDataTextArea; var sentDataTextArea;
var receivedGraph; var receivedGraph;
var receivedData = []; var receivedData = [];
var MAX_DATA = 300; var MAX_AMPLITUDE = 300; // Higher than 255 to give us space
var pauseTimeoutId; var pauseTimeoutId;
var sampleIntervalIds = []; var sampleIntervalIds = [];
var TEXT_TO_SEND = "U"; var TEXT_TO_SEND = "U";
var RANDOM_COUNT = 128; var RANDOM_COUNT = 128;
var MAX_BITS_DISPLAYED_ON_GRAPH = 78; var MAX_BITS_DISPLAYED_ON_GRAPH = 79;
var SEGMENT_DURATION = 30; var SEGMENT_DURATION = 30;
var AMPLITUDE_THRESHOLD_PERCENT = .75; var AMPLITUDE_THRESHOLD_PERCENT = .75;
var AMPLITUDE_THRESHOLD = 160; var AMPLITUDE_THRESHOLD = 160;
var MINIMUM_FREQUENCY = 304; var MINIMUM_FREQUENCY = 323;
var MAXIMUM_FREQUENCY = 4800; var MAXIMUM_FREQUENCY = 9226;
var LAST_SEGMENT_PERCENT = 0.6; var LAST_SEGMENT_PERCENT = 0.6;
var FFT_SIZE_POWER = 10; var FFT_SIZE_POWER = 10;
var FREQUENCY_RESOLUTION_MULTIPLIER = 2; var FREQUENCY_RESOLUTION_MULTIPLIER = 2;
let CHANNEL_FREQUENCY_RESOLUTION_PADDING = 2;
var SMOOTHING_TIME_CONSTANT = 0; var SMOOTHING_TIME_CONSTANT = 0;
var HAMMING_ERROR_CORRECTION = true; var HAMMING_ERROR_CORRECTION = true;
@@ -91,6 +92,11 @@ function handleWindowLoad() {
FREQUENCY_RESOLUTION_MULTIPLIER = parseInt(event.target.value); FREQUENCY_RESOLUTION_MULTIPLIER = parseInt(event.target.value);
showSpeed(); showSpeed();
}) })
document.getElementById('channel-frequency-resolution-padding').value = CHANNEL_FREQUENCY_RESOLUTION_PADDING;
document.getElementById('channel-frequency-resolution-padding').addEventListener('input', event => {
CHANNEL_FREQUENCY_RESOLUTION_PADDING = parseInt(event.target.value);
showSpeed();
})
document.getElementById('bit-duration-text').addEventListener('input', (event) => { document.getElementById('bit-duration-text').addEventListener('input', (event) => {
SEGMENT_DURATION = parseInt(event.target.value); SEGMENT_DURATION = parseInt(event.target.value);
bitSampleCount = 0; bitSampleCount = 0;
@@ -310,7 +316,7 @@ function getChannels() {
const fftSize = 2 ** FFT_SIZE_POWER; const fftSize = 2 ** FFT_SIZE_POWER;
const frequencyResolution = sampleRate / fftSize; const frequencyResolution = sampleRate / fftSize;
const channels = []; const channels = [];
const pairStep = frequencyResolution * 2 * FREQUENCY_RESOLUTION_MULTIPLIER; const pairStep = frequencyResolution * (2 + CHANNEL_FREQUENCY_RESOLUTION_PADDING) * FREQUENCY_RESOLUTION_MULTIPLIER;
for(let hz = MINIMUM_FREQUENCY; hz < MAXIMUM_FREQUENCY; hz+= pairStep) { for(let hz = MINIMUM_FREQUENCY; hz < MAXIMUM_FREQUENCY; hz+= pairStep) {
const low = Math.floor(hz); const low = Math.floor(hz);
const high = Math.floor(hz + frequencyResolution * FREQUENCY_RESOLUTION_MULTIPLIER); const high = Math.floor(hz + frequencyResolution * FREQUENCY_RESOLUTION_MULTIPLIER);
@@ -952,7 +958,7 @@ function drawFrequencyLineGraph(ctx, channel, highLowIndex, color, lineWidth, da
if(x === -1) continue; if(x === -1) continue;
if(channel > pairs.length) continue; if(channel > pairs.length) continue;
const amplitude = pairs[channel][highLowIndex]; const amplitude = pairs[channel][highLowIndex];
const y = getPercentY(amplitude / MAX_DATA); const y = getPercentY(amplitude / MAX_AMPLITUDE);
if(i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); if(i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
} }
if(isSelected || isOver) { if(isSelected || isOver) {
@@ -980,7 +986,7 @@ function drawFrequencyDots(ctx, channel, highLowIndex, color) {
const x = getTimeX(time, newest); const x = getTimeX(time, newest);
if(x === -1) continue; if(x === -1) continue;
const amplitude = pairs[channel][highLowIndex]; const amplitude = pairs[channel][highLowIndex];
const y = getPercentY(amplitude / MAX_DATA); const y = getPercentY(amplitude / MAX_AMPLITUDE);
ctx.beginPath(); ctx.beginPath();
ctx.arc(x, y, radius, 0, fullCircle); ctx.arc(x, y, radius, 0, fullCircle);
@@ -1269,7 +1275,7 @@ function drawFrequencyData(forcedDraw) {
ctx.fillStyle = 'black'; ctx.fillStyle = 'black';
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);
const thresholdY = (1 - (AMPLITUDE_THRESHOLD/MAX_DATA)) * height; const thresholdY = (1 - (AMPLITUDE_THRESHOLD/MAX_AMPLITUDE)) * height;
ctx.strokeStyle = 'grey'; ctx.strokeStyle = 'grey';
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(0, thresholdY); ctx.moveTo(0, thresholdY);