urish / muse-js

Muse 2016 EEG Headset JavaScript Library (using Web Bluetooth)
https://medium.com/@urish/reactive-brain-waves-af07864bb7d4
MIT License
280 stars 78 forks source link

Simultaneous EEG / PPG and zipping samples #56

Open TijeOortwijnThales opened 2 years ago

TijeOortwijnThales commented 2 years ago

I run into some strange behaviour trying to plot EEG and PPG simultaneously. I'm using a Muse-S.

Below I added the basic code to reproduce the behaviour. Connect to the muse and then subscribe to both the zipped Observables.

try {         
          this.muse.enablePpg = true;
          await this.muse.connect();
          await this.muse.start();     
          await this.muse.deviceInfo();  
          zipSamples(this.muse.eegReadings).subscribe(console.log); 
          zipSamplesPpg(this.muse.ppgReadings).subscribe(console.log);     
         } catch (err) {
          window.alert(err.toString());
          this.connectionError.next('Connection failed: ' + err.toString());  
        } finally {
          this.connecting.next(false);
        }    

I hope the issue is clear, it's quite hard to describe. I suspect a bug in the zipSamplesPpg, but I can't seem to figure out how to fix it.

TijeOortwijnThales commented 2 years ago

I found out the timestamp isn't changing for PPG readings when I subscribe to both the eegReadings and the ppgReadings. The zipSamplesPPG never gets passed the first mergeMap call.

mergeMap((reading) => {        
        // NEVER GETS PASSED THIS CALL, reading.timestamp doesnt update properly
          if (reading.timestamp !== lastTimestamp) {
              lastTimestamp = reading.timestamp;   
              if (buffer.length) {                 
                  const result = from([[...buffer]]);
                  buffer.splice(0, buffer.length, reading);
                  return result;
              }
          }         
          buffer.push(reading);         
          return from([]);
      }),     
henrisuurorg commented 1 month ago

@TijeOortwijnThales did you ever find a solution to this?