Skip to content

Commit 38ddc04

Browse files
authored
Merge pull request #14 from PayalLakra/bio_amptool
Adding notebooks,gui,game,ecg and update chords file
2 parents 4d22806 + d877455 commit 38ddc04

File tree

7 files changed

+655
-132
lines changed

7 files changed

+655
-132
lines changed

Notebooks/ECG.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115915,7 +115915,7 @@
115915115915
],
115916115916
"metadata": {
115917115917
"kernelspec": {
115918-
"display_name": "Python 3 (ipykernel)",
115918+
"display_name": "venv",
115919115919
"language": "python",
115920115920
"name": "python3"
115921115921
},
@@ -115929,7 +115929,7 @@
115929115929
"name": "python",
115930115930
"nbconvert_exporter": "python",
115931115931
"pygments_lexer": "ipython3",
115932-
"version": "3.11.7"
115932+
"version": "3.10.10"
115933115933
}
115934115934
},
115935115935
"nbformat": 4,

README.md

Lines changed: 71 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,93 +28,115 @@ Chords Python script is designed to interface with an Arduino-based bioamplifier
2828
## Installation
2929

3030
1. Ensure you have Python 3.x installed.
31-
2. Install the required Python libraries:
31+
2. Create Virtual Environment
32+
```bash
33+
python -m venv venv #Create Virtual Environment
34+
.\venv\Scripts\activate #to activate environment
35+
```
36+
3. Install the required Python libraries:
3237
```bash
3338
pip install -r requirements.txt
3439
```
3540

3641
## Usage
3742

3843
To use the script, run it from the command line with various options:
39-
40-
First Create Virtual Environment
41-
42-
```bash
43-
python -m venv venv #Create Virtual Environment
44-
.\venv\Scripts\activate #to activate environment
45-
```
46-
Then,
47-
4844
```bash
49-
python bioamp_tool.py [options]
45+
python chords.py [options]
5046
```
51-
5247
### Options
5348

5449
- `-p`, `--port` <port>: Specify the serial port to use (e.g., COM5, /dev/ttyUSB0).
55-
- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication (default is 115200).
50+
- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication (default is 230400).
5651
- `--csv`: Enable CSV logging. Data will be saved to a timestamped file.
5752
- `--lsl`: Enable LSL streaming. Sends data to an LSL outlet.
5853
- `-v`, `--verbose`: Enable verbose output with detailed statistics and error reporting.
59-
- `--gui`: Enable the real-time data plotting GUI.
6054
- `-t` : Enable the timer to run program for a set time in seconds.
6155

62-
## Script Functions
56+
### Data Logging
6357

64-
`auto_detect_arduino(baudrate, timeout=1)`
58+
- **CSV Output**: The script saves the processed data in a CSV file with a timestamped name.
59+
- The CSV file contains the following columns:
60+
- `Counter`: The sample counter from the Arduino.
61+
- `Channel1` to `Channel6`: The data values from each channel.
6562

66-
Detects an Arduino connected via serial port. Returns the port name if detected.
63+
- **Log Intervals**: The script logs data counts every second and provides a summary every 10 minutes, including the sampling rate and drift in seconds per hour.
6764

68-
`read_arduino_data(ser, csv_writer=None)`
65+
### LSL Streaming
6966

70-
Reads and processes data from the Arduino. Writes data to CSV and/or LSL stream if enabled.
67+
- **Stream Name**: `BioAmpDataStream`
68+
- **Stream Type**: `EXG`
69+
- **Channel Count**: `6`
70+
- **Sampling Rate**: `UNO-R3 : 250 Hz` , `UNO-R4 : 500 Hz`
71+
- **Data Format**: `float32`
7172

72-
`start_timer()`
7373

74-
Initializes timers for 1-second and 10-minute intervals.
74+
### Script Functions
7575

76-
`log_one_second_data(verbose=False)`
76+
`auto_detect_arduino(baudrate, timeout=1)`: Detects an Arduino connected via serial port. Returns the port name if detected.
7777

78-
Logs and resets data for the 1-second interval.
78+
`read_arduino_data(ser, csv_writer=None)`: Reads and processes data from the Arduino. Writes data to CSV and/or LSL stream if enabled.
7979

80-
`log_ten_minute_data(verbose=False)`
80+
`start_timer()`: Initializes timers for 1-second and 10-minute intervals.
8181
82-
Logs data and statistics for the 10-minute interval.
82+
`log_one_second_data(verbose=False)`: Logs and resets data for the 1-second interval.
8383
84-
`parse_data(port, baudrate, lsl_flag=False, csv_flag=False, gui_flag=False, verbose=False)`
84+
`log_ten_minute_data(verbose=False)`: Logs data and statistics for the 10-minute interval.
8585
86-
Parses data from Arduino and manages logging, streaming, and GUI updates.
86+
`parse_data(port,baudrate,lsl_flag=False,csv_flag=False,verbose=False)`: Parses data from Arduino and manages logging, streaming, and GUI updates.
8787
88-
`init_gui()`
88+
`cleanup()`: Handles all the cleanup tasks.
8989
90-
Initializes and displays the GUI with six real-time plots, one for each bio-signal channel.
90+
`main()`: Handles command-line argument parsing and initiates data processing.
9191
92-
`cleanup()`
92+
## Applications
9393
94-
Handles all the cleanup tasks.
94+
> [!IMPORTANT]
95+
Before using the below Applications make sure you are in Application folder.
9596
96-
`main()`
97+
### GUI
9798
98-
Handles command-line argument parsing and initiates data processing.
99+
- `python gui.py`: Enable the real-time data plotting GUI.
99100
100-
## Data Logging
101+
#### Script Functions
101102
102-
- **CSV Output**: The script saves the processed data in a CSV file with a timestamped name.
103-
- The CSV file contains the following columns:
104-
- `Counter`: The sample counter from the Arduino.
105-
- `Channel1` to `Channel6`: The data values from each channel.
103+
`init_gui()`: Initializes and displays the GUI with six real-time plots, one for each bio-signal channel.
106104
107-
- **Log Intervals**: The script logs data counts every second and provides a summary every 10 minutes, including the sampling rate and drift in seconds per hour.
105+
`update_plots()`: Updates the plot data by pulling new samples from the LSL stream and shifting the existing buffer.
108106
109-
## LSL Streaming
107+
### FORCE BALL GAME
110108
111-
- **Stream Name**: `BioAmpDataStream`
112-
- **Stream Type**: `EXG`
113-
- **Channel Count**: `6`
114-
- **Sampling Rate**: `UNO-R3 : 250 Hz` , `UNO-R4 : 500 Hz`
115-
- **Data Format**: `float32`
109+
- `python game.py`: Enable a GUI to play game using EEG Signal.
110+
111+
#### Script Functions
112+
113+
`bandpower(data, sf, band, window_sec=None, relative=False)`: Calculates the band power of EEG data in a specified frequency band using the Welch method.
114+
115+
`eeg_data_thread(eeg_queue)`: Continuously retrieves EEG data from an LSL stream and computes power ratios for Player A and Player B.
116+
117+
`reset_game()`: Resets the game state and initializes the ball and player forces.
116118
117-
If GUI is not enabled, you can use an LSL viewer (e.g., BrainVision LSL Viewer) to visualize the streamed data in real-time.
119+
`update_ball_position(force_player1, force_player2)`: Updates the ball's position based on the net force exerted by both players.
120+
121+
`check_win_condition()`: Determines if either player has won based on the ball's position.
122+
123+
### Heart Rate
124+
125+
- `python heartbeat.ecg.py`:Enable a GUI with real-time ECG and heart rate
126+
127+
#### Script Functions
128+
129+
`butter_filter(cutoff, fs, order=4, btype='low')`: Designs a Butterworth filter to remove unwanted frequencies from the ECG signal.
130+
131+
`apply_filter(data, b, a)`: Applies the designed Butterworth filter to the ECG data for noise reduction.
132+
133+
`detect_heartbeats(ecg_data, sampling_rate)`: Detects heartbeats in the ECG signal using peak detection.
134+
135+
`run(self)`: Collects ECG data from the LSL stream, applies filtering, and emits the filtered data for real-time plotting.
136+
137+
`update_plot(self, ecg_data)`: Updates the plot with the latest ECG data and detects heartbeats to display on the GUI.
138+
139+
`update_heart_rate(self)`: Calculates and updates the heart rate based on detected R-peaks in the ECG signal.
118140
119141
## Troubleshooting
120142
@@ -126,4 +148,6 @@ If GUI is not enabled, you can use an LSL viewer (e.g., BrainVision LSL Viewer)
126148
127149
We are thankful to our awesome contributors, the list below is alphabetically sorted.
128150
129-
- [Payal Lakra](https://github.com/payallakra)
151+
- [Payal Lakra](https://github.com/payallakra)
152+
153+
The audio file used in `game.py` is sourced from [Pixabay](https://pixabay.com/sound-effects/brass-fanfare-with-timpani-and-windchimes-reverberated-146260/)

0 commit comments

Comments
 (0)