You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-47Lines changed: 71 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,93 +28,115 @@ Chords Python script is designed to interface with an Arduino-based bioamplifier
28
28
## Installation
29
29
30
30
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:
32
37
```bash
33
38
pip install -r requirements.txt
34
39
```
35
40
36
41
## Usage
37
42
38
43
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
-
48
44
```bash
49
-
python bioamp_tool.py [options]
45
+
python chords.py [options]
50
46
```
51
-
52
47
### Options
53
48
54
49
- `-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).
56
51
- `--csv`: Enable CSV logging. Data will be saved to a timestamped file.
57
52
- `--lsl`: Enable LSL streaming. Sends data to an LSL outlet.
58
53
- `-v`, `--verbose`: Enable verbose output with detailed statistics and error reporting.
59
-
- `--gui`: Enable the real-time data plotting GUI.
60
54
- `-t`: Enable the timer to run program fora set timein seconds.
61
55
62
-
## Script Functions
56
+
### Data Logging
63
57
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.
65
62
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.
67
64
68
-
`read_arduino_data(ser, csv_writer=None)`
65
+
### LSL Streaming
69
66
70
-
Reads and processes data from the Arduino. Writes data to CSV and/or LSL stream if enabled.
`log_ten_minute_data(verbose=False)`: Logs data and statistics for the 10-minute interval.
85
85
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.
87
87
88
-
`init_gui()`
88
+
`cleanup()`: Handles all the cleanup tasks.
89
89
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.
91
91
92
-
`cleanup()`
92
+
## Applications
93
93
94
-
Handles all the cleanup tasks.
94
+
> [!IMPORTANT]
95
+
Before using the below Applications make sure you are in Application folder.
95
96
96
-
`main()`
97
+
### GUI
97
98
98
-
Handles command-line argument parsing and initiates data processing.
99
+
- `python gui.py`: Enable the real-time data plotting GUI.
99
100
100
-
## Data Logging
101
+
#### Script Functions
101
102
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.
106
104
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.
- `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.
116
118
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.
118
140
119
141
## Troubleshooting
120
142
@@ -126,4 +148,6 @@ If GUI is not enabled, you can use an LSL viewer (e.g., BrainVision LSL Viewer)
126
148
127
149
We are thankful to our awesome contributors, the list below is alphabetically sorted.
128
150
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