ml4ai / tomcat

ToMCAT: Theory of Mind-based Cognitive Architecture for Teams
https://ml4ai.github.io/tomcat/
MIT License
21 stars 7 forks source link

Signal Synchronization and Project Refactoring #558

Closed paulosaurusrex closed 8 months ago

paulosaurusrex commented 9 months ago

This PR covers a major refactoring in the code to make it more robust to testing and deployment, by introducing separation between development and production environments and adding make commands for easy execution of different processes.

See the README.md file for more details.

Moreover, it introduces signal synchronization script to populate tables with fNIRS, EEG, GSR and EKG signals synchronized with a main clock. The following tables were introduced:

To synchronize the signals, we define a main clock with desired frequency (e.g., 200Hz) starting 1 minute before the start of the first task (rest state) and ending about 1 minute after the end of the last task (Minecraft). We generate data with a clock frequency of 200Hz but the sync script allows us to generate synchronized signals with other frequencies if needed. The tables are the same as above, as the frequency is a column part of their composite primary key.

The pipeline for synchronization is as follows:

  1. Define main clock (start point, end point and ticks according to the desired frequency)
  2. Filter raw signals. Because of our previous analysis and conclusion that the signals are equally spaced in time, we can apply the frequency filters to the raw signals directly.
  3. Upsample signals to 10x the desired frequency. So, for a desired frequency of 200Hz, raw EEG signals originally sampled at 500 Hz are upsampled 4 times. fNIRS (10 Hz original frequency), 200 times.
  4. Interpolate with the main clock. This is equivalent to downsampling the signals to the desired frequency but in such a way that the samples match the main clock.

Below is an example of raw vs sync fNIRS signal during rest_state task. Screenshot 2024-01-08 at 9 54 28 AM

Finally, I added raw fNIRS signals (760 and 850 wavelengths) to the database in case people want to transform those in HbO and HbR by themselves.

paulosaurusrex commented 9 months ago

@adarshp, please check if the datasette-related commands are working properly. I moved the scripts to the bin folder and added calls to them to the Makefile. Let me know if you run into any issues. I added an explanation to the README.md file. Feel free to imporve them if necessary.

Also, let me know the appropriate place to document the sync process.

paulosaurusrex commented 9 months ago

Hold on to this PR for now. Talking to Diheng, I discovered our EKG and GSR pre-processing is not right. I will fix it in this PR before merging with master.