From 2ff5ba892764a64ec2f3fa2dcd90210410603449 Mon Sep 17 00:00:00 2001 From: AbdulShabazz <39221089+AbdulShabazz@users.noreply.github.com> Date: Sun, 12 May 2024 22:55:12 -0400 Subject: [PATCH] Update _.js Correct for DC offset. --- _.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/_.js b/_.js index 71326ee..dd0e376 100644 --- a/_.js +++ b/_.js @@ -2300,6 +2300,14 @@ function generateComplexSignal( console.info("Done."); } + + // re-Calculate the average amplitude, for correcting the DC offset + const avgAmplitude = channelDataLeft.reduce((sum, sample) => sum + sample, 0) / channelDataLeft.length; + + // Remove the DC offset by subtracting the average amplitude from each sample + for (let i = 0; i < channelDataLeft.length; i++) { + channelDataLeft[i] -= avgAmplitude; + } let channelDataRight = [...channelDataLeft];