sum amplitude through entire segment rather than counting wins

This commit is contained in:
Lewis Moten
2024-05-04 18:49:45 -04:00
parent a079ac5d53
commit 1982b04023

View File

@@ -445,6 +445,8 @@ function collectSample() {
channel: i, channel: i,
lowHz: low, lowHz: low,
highHz: high, highHz: high,
lowAmp,
highAmp,
isMissing: !(isHigh || isLow), isMissing: !(isHigh || isLow),
isHigh: (isHigh && !isLow) || highAmp > lowAmp isHigh: (isHigh && !isLow) || highAmp > lowAmp
}; };
@@ -506,11 +508,11 @@ function evaluateBit(samples, segment, channel) {
return sample.time >= started + (segment * FREQUENCY_DURATION) && return sample.time >= started + (segment * FREQUENCY_DURATION) &&
sample.time < started + ((segment + 1) * FREQUENCY_DURATION) sample.time < started + ((segment + 1) * FREQUENCY_DURATION)
}).map(samples => samples.pairs[channel]) }).map(samples => samples.pairs[channel])
.reduce((bitSamples, { isHigh, isMissing }) => { .reduce((bitSamples, { lowAmp, highAmp }) => {
bitSamples.total++; bitSamples.high += highAmp;
if(isHigh) bitSamples.highCount++; bitSamples.low += lowAmp;
}, {highCount: 0, total: 0}); }, {high: 0, low: 0});
return bitSamples.highCount >= bitSamples.total / 2 ? 1 : 0; return bitSamples.high >= bitSamples.low ? 1 : 0;
} }
function processSegmentReceived() { function processSegmentReceived() {
@@ -533,18 +535,18 @@ function processSegmentReceived() {
// return; // return;
// } // }
const channels = new Array(channelCount).fill(0).map(() => ({isHigh: 0, isLow: 0, isMissing: 0})); const channels = new Array(channelCount).fill(0).map(() => ({highAmp: 0, lowAmp: 0, isMissing: 0}));
bits.forEach(({pairs}) => { bits.forEach(({pairs}) => {
pairs.forEach(({ isHigh, isMissing }, i) => {
if(isHigh) channels[i].isHigh ++; pairs.forEach(({ highAmp, lowAmp, isMissing }, i) => {
channels[i].highAmp += highAmp;
channels[i].lowAmp += lowAmp;
// else if(isMissing) channels[i].isMissing ++; // else if(isMissing) channels[i].isMissing ++;
else channels[i].isLow++;
}) })
}); });
const bitValues = channels.map(({isHigh, isLow, isMissing}) => { const bitValues = channels.map(({highAmp, lowAmp, isMissing}) => {
if(isMissing > isHigh + isLow) return '.'; return highAmp >= lowAmp ? 1 : 0;
return isHigh > isLow ? 1 : 0;
}); });
packetBits.push(...bitValues); packetBits.push(...bitValues);