High-pass filter that is applied to the signal by default in Nodejs ?
Hi there,
I am studying to measure EOG signal with Node.js and ganglion board.
I recently found that
high-pass filter is applied to the signal by default when I receive the signal from the ganglion.
I want to get no-filtered signal, but I don’t know where and how to fix my codes.
I guess, it may be the following code which I have to change, but can't sure.
wifi.on(OpenBCIConsts.OBCIEmitterSample, sampleFunc);
Could you give me some advice?
the part of the code to measure the signal is as follows:
testFlag = true;
const sampleFunc = (sample) => {
if(sample.valid){
if(flag){
if(averageV!=0.0){
originV = averageV/counter2;
originH = averageH/counter2;
}else{
originV = 0.0;
originH = 0.0;
}
dataArray.push(sample.channelData);
var v = 10*(sample.channelData[0] - sample.channelData[3]);
var h = 10*(sample.channelData[1] - sample.channelData[2]);
var hv = [h*40000+400-originH*40000, v*40000+400-originV*40000];
dataVH.push(hv);
if(drawMovement){
ctx.fillText('o',h*40000+400-originH*40000, v*40000+300-originV*40000);
}
}else{
var v = 10*(sample.channelData[0] - sample.channelData[3]);
var h = 10*(sample.channelData[1] - sample.channelData[2]);
averageV += v;
averageH += h;
counter2++;
}
}
//
try {
//console.log(JSON.stringify(sample));
if (sample.valid) {
counter++;
//dataArray.push(sample.channelData);
if (sampleRateCounterInterval === null) {
sampleRateCounterInterval = setInterval(() => {
droppedPacketArray.push(droppedPackets);
sampleRateArray.push(counter);
const dpSum = droppedPacketArray.reduce(sum, 0);
const srSum = sampleRateArray.reduce(sum, 0);
console.log(`SR: ${counter}`);
console.log(`Dropped ${droppedPackets} packets`);
console.log(`Dropped packet average: ${dpSum / droppedPacketArray.length}`);
console.log(`Sample rate average: ${srSum / sampleRateArray.length}`);
droppedPackets = 0;
counter = 0;
}, 1000);
}
let packetDiff = sample.sampleNumber - lastSampleNumber;
if (packetDiff < 0) packetDiff += MAX_SAMPLE_NUMBER;
if (packetDiff > 1) {
console.log(`dropped ${packetDiff} packets | cur sn: ${sample.sampleNumber} | last sn: ${lastSampleNumber}`);
droppedPackets += packetDiff;
}
lastSampleNumber = sample.sampleNumber;
// console.log(JSON.stringify(sample));
}
} catch (err) {
console.log(err);
}
//
};
wifi.on(OpenBCIConsts.OBCIEmitterImpedance, (impedance) => {
console.log(JSON.stringify(impedance));
});
wifi.on(OpenBCIConsts.OBCIEmitterSample, sampleFunc);
//wifi.on(OpenBCIConsts.OBCIEmitterRawDataPacket, console.log);
//I want to fix this part.
wifi.connect({
sampleRate: 1600,
streamStart: true,
ipAddress: deviceAddr
})
.then(() => {
MAX_SAMPLE_NUMBER = wifi.getNumberOfChannels() === 4 ? 200 : 255;
})
.catch((err) => {
console.log(err);
//process.exit(0);
});
Comments
Saron, hi.
How are you inferring that a high pass filter is being applied to the Ganglion + Wifi Shield data stream? What is your evidence for that? Is your 1600 Hz sample rate a prerequisite for what you want to do? Wifi defaults at 1600 for Ganglion, have you tried 800 Hz? Generally for EMG / EOG, 500 Hz and above is adequate.
It's true that when the Ganglion is running via the Bluetooth interface, that some high pass filtering naturally occurs, because of the substantial delta compression algorithms.
But (I may be wrong), when the Ganglion is streaming via Wifi, I believe the full unadulterated stream is available without any pre-compression being applied. With your Wifi stream, have you tried access to the 'raw' stream versus 'json'? I'm not sure what options are available with Javascript access.
Regards, William
thank you for your reply.

Your advice about 1600Hz is helpful for me.
About inferring that a high pass filter is applied, the result is different when I used Openbci-GUI and when my Node.js program.
My program signal shows very dripping off when receive the signal and return 0, In comparison Openbci-GUI's nonfilter.
So I infer like that. Here is my capture my code signal.
The graph above, does it not show significant mains noise (50 Hz?) This is your Node.js received stream? Mains noise is always NOT desirable.
It's possible the GUI is receiving the raw stream from Wifi Shield, via the Hub. Whereas your Node.js is processing the JSON stream.
Richard @retiutut, is there any high pass filtering applied to a Ganglion stream flowing through the Wifi Shield. In my comments above I guessed no. Saron is saying his Node.js stream from the shield appears to be high pass filtered. Yet the image he just posted looks like plain mains noise to me. Not sure he is providing valid comparison examples.
Regards, William
I highly doubt there is a filter in the NodeJS code, primarily because this is done in the GUI using Java code with RAW data coming from the NodeJS pipe. Doesn't make sense to apply a filter twice! Also, I have received raw data in Max using NodeJS drivers and this data does not have filters applied.
There is no issue here in regards to NodeJS repos. Unless someone can find the exact lines of code to prove otherwise.
Thank you for everyone.

I know that my code isn't include high-pass filtering code through your advices.
Your high intelligence is just amazing.
So, I change my question. How can I fix my code for change orange line to purple line in my picture?
My picture image is just that I changed signal that I already received. I want purple line signal in real time.
Your purple line looks like it is acting with a "thresholding" algorithm. Then once the threshold is reached, that value is maintained until the next threshold resets it. There is not a particular DSP algorithm that does this, you will have to code your own threshold scheme. Using your own criteria.