-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requirements updates, Chords baud rate update, ffteeg- moving window implementation #32
base: main
Are you sure you want to change the base?
Conversation
…ing 230400 first, then 115200 if not provided.
…mples and removing the previous 50 samples before calculating FFT.
WalkthroughThis pull request introduces several enhancements to the EEG data processing and visualization ecosystem. The changes span multiple files, including updates to project dependencies, modifications to hardware connection logic in Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Nitpick comments (6)
test/beetle.py (3)
34-35
: Document filter parameters and consider making them configurable.The notch and bandpass filter parameters are hardcoded. Consider:
- Adding comments explaining the filter choices (e.g., why 50Hz notch, 0.5-48Hz bandpass).
- Making these parameters configurable through command-line arguments or a config file.
72-78
: Refactor global variable usage in update_beetle_position.The function uses a global variable which makes it harder to test and maintain. Consider passing the beetle position as a parameter.
-def update_beetle_position(focus_level, is_focus_stable): - global beetle_y +def update_beetle_position(current_y, focus_level, is_focus_stable, image_height): if is_focus_stable: - beetle_y = max(10 + beetle_image.get_height() // 2, beetle_y - focus_speed_upward) + new_y = max(10 + image_height // 2, current_y - focus_speed_upward) else: - beetle_y = min(580 - beetle_image.get_height() // 2, beetle_y + focus_speed_downward) + new_y = min(580 - image_height // 2, current_y + focus_speed_downward) + return new_y
96-97
: Document and improve buffer management logic.The 20% buffer release is a magic number and the implementation could be more efficient.
- release_count = int(len(buffer) * 0.2) # Remove oldest 20% - buffer = buffer[release_count:] # Trim buffer + # Release 20% of the buffer to prevent memory growth while maintaining + # enough history for smooth analysis + BUFFER_RELEASE_RATIO = 0.2 + release_count = int(len(buffer) * BUFFER_RELEASE_RATIO) + buffer = buffer[release_count:]ffteeg.py (2)
77-78
: Document the rationale for buffer sizes.The code uses fixed buffer sizes of 500 samples for both
eeg_data
andmoving_window
without explaining the choice.Add documentation:
- self.eeg_data = deque(maxlen=500) # Initialize moving window with 500 samples - self.moving_window = deque(maxlen=500) # 500 samples for FFT and power calculation (sliding window) + # Buffer size of 500 samples provides 1 second of data at 500Hz sampling rate, + # balancing between temporal resolution and computational efficiency + self.eeg_data = deque(maxlen=500) + # Separate moving window for FFT analysis with the same size to maintain + # consistent frequency resolution + self.moving_window = deque(maxlen=500)
118-120
: Consider using scipy.signal.windows for window functions.The code uses numpy's Hanning window, but scipy.signal.windows provides more window options and better documentation.
+from scipy.signal import windows - window = np.hanning(len(self.moving_window)) + window = windows.hann(len(self.moving_window)) buffer_windowed = np.array(self.moving_window) * windowchords.py (1)
58-58
: Document hardware specifications for new boards.New boards "GENUINO-UNO" and "BLACK-PILL" were added without documentation about their specifications or requirements.
Add documentation:
"UNO-CLONE": {"sampling_rate": 250, "Num_channels": 6}, # Baud Rate 115200 - "GENUINO-UNO": {"sampling_rate": 250, "Num_channels": 6}, + "GENUINO-UNO": {"sampling_rate": 250, "Num_channels": 6}, # Compatible with Arduino UNO R3 "UNO-R4": {"sampling_rate": 500, "Num_channels": 6}, "RPI-PICO-RP2040": {"sampling_rate": 500, "Num_channels": 3}, "NANO-CLONE": {"sampling_rate": 250, "Num_channels": 8}, # Baud Rate 115200 - "BLACK-PILL": {"sampling_rate": 500, "Num_channels": 10}, + "BLACK-PILL": {"sampling_rate": 500, "Num_channels": 10}, # STM32F4x1 based boardAlso applies to: 62-62
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
test/beetle.jpg
is excluded by!**/*.jpg
📒 Files selected for processing (5)
app_requirements.txt
(1 hunks)chords.py
(5 hunks)ffteeg.py
(5 hunks)test/ball.py
(0 hunks)test/beetle.py
(1 hunks)
💤 Files with no reviewable changes (1)
- test/ball.py
✅ Files skipped from review due to trivial changes (1)
- app_requirements.txt
🧰 Additional context used
🪛 Ruff (0.8.2)
test/beetle.py
2-2: pylsl
imported but unused
Remove unused import: pylsl
(F401)
62-62: Local variable delta_power
is assigned to but never used
Remove assignment to unused variable delta_power
(F841)
chords.py
348-348: Local variable baudrate
is assigned to but never used
Remove assignment to unused variable baudrate
(F841)
🔇 Additional comments (1)
test/beetle.py (1)
45-46
: Verify the beetle image path and add error handling.The image loading code assumes
beetle.jpg
exists in the current directory without any error handling.Add error handling:
-beetle_image = pygame.image.load('beetle.jpg') -beetle_image = pygame.transform.scale(beetle_image, (80, 80)) +try: + beetle_image = pygame.image.load('beetle.jpg') + beetle_image = pygame.transform.scale(beetle_image, (80, 80)) +except pygame.error as e: + print(f"Error loading beetle image: {e}") + pygame.quit() + exit()✅ Verification successful
The image path is correct, but error handling is recommended
The image file
beetle.jpg
exists in the correct location (same directory astest/beetle.py
). While the current path reference works, adding error handling as suggested in the review is still good practice to handle potential runtime issues like accidental file deletion or permission problems.🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash # Find beetle.jpg in the repository fd 'beetle.jpg' # Search for references to beetle.jpg in the code rg "beetle\.jpg" -l # List the directory structure around test/beetle.py to understand relative paths ls -R test/Length of output: 124
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
README.md (2)
54-54
: Fix grammatical issues in the baudrate description.-- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication. By default the script will first attempt to use 230400, and if that fails, it will automatically fallback to 115200. +- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication. By default, the script will first attempt to use 230400, and if that fails, it will automatically fall back to 115200.🧰 Tools
🪛 LanguageTool
[uncategorized] ~54-~54: Loose punctuation mark.
Context: ...o use (e.g., COM5, /dev/ttyUSB0). --b
,--baudrate
: Set the baud r...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~54-~54: Did you mean: “By default,”?
Context: ...the baud rate for serial communication. By default the script will first attempt to use 23...(BY_DEFAULT_COMMA)
[grammar] ~54-~54: The word “fallback” is a noun. The verb is spelled with a space.
Context: ...nd if that fails, it will automatically fallback to 115200. ---csv
: Enable CSV loggin...(NOUN_VERB_CONFUSION)
81-81
: Fix formatting inconsistency.-- `python heartbeat_ecg.py`:Enable a GUI with real-time ECG and heart rate. +- `python heartbeat_ecg.py`: Enable a GUI with real-time ECG and heart rate.🧰 Tools
🪛 LanguageTool
[uncategorized] ~81-~81: Loose punctuation mark.
Context: ... HEART RATE -python heartbeat_ecg.py
:Enable a GUI with real-time ECG and hear...(UNLIKELY_OPENING_PUNCTUATION)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md
(3 hunks)chords.py
(4 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[uncategorized] ~54-~54: Loose punctuation mark.
Context: ...o use (e.g., COM5, /dev/ttyUSB0). - -b
, --baudrate
: Set the baud r...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~54-~54: Did you mean: “By default,”?
Context: ...the baud rate for serial communication. By default the script will first attempt to use 23...
(BY_DEFAULT_COMMA)
[grammar] ~54-~54: The word “fallback” is a noun. The verb is spelled with a space.
Context: ...nd if that fails, it will automatically fallback to 115200. - --csv
: Enable CSV loggin...
(NOUN_VERB_CONFUSION)
[uncategorized] ~81-~81: Loose punctuation mark.
Context: ... HEART RATE - python heartbeat_ecg.py
:Enable a GUI with real-time ECG and hear...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~97-~97: Loose punctuation mark.
Context: ... ### Keystroke - python keystroke.py
: On running, a pop-up opens for connecti...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~126-~126: Loose punctuation mark.
Context: ... analysis on EEG data. - heartbeat_ecg
: Analyze ECG data and extract heartbeat ...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~127-~127: Loose punctuation mark.
Context: ...a and extract heartbeat metrics. - eog
: Process and detect blinks in EOG signal...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~128-~128: Loose punctuation mark.
Context: ...t blinks in EOG signals. - emgenvelope
: Analyze EMG signals for muscle activity...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~129-~129: Loose punctuation mark.
Context: ...ty or gesture recognition. - keystroke
: Monitor and analyze keystroke dynamics....
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~130-~130: Loose punctuation mark.
Context: ...and analyze keystroke dynamics. - game
: Launch an EEG game for 2 players(Tug of...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~131-~131: Loose punctuation mark.
Context: ...r 2 players(Tug of War). - csv_plotter
: Plot data from a CSV file. - gui
: Lau...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~132-~132: Loose punctuation mark.
Context: ...ter: Plot data from a CSV file. -
gui`: Launch the GUI for real time signal vis...
(UNLIKELY_OPENING_PUNCTUATION)
🔇 Additional comments (5)
README.md (1)
95-132
: LGTM! Well-structured documentation.The new sections provide clear and comprehensive instructions for running applications together.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~97-~97: Loose punctuation mark.
Context: ... ### Keystroke -python keystroke.py
: On running, a pop-up opens for connecti...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~126-~126: Loose punctuation mark.
Context: ... analysis on EEG data. -heartbeat_ecg
: Analyze ECG data and extract heartbeat ...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~127-~127: Loose punctuation mark.
Context: ...a and extract heartbeat metrics. -eog
: Process and detect blinks in EOG signal...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~128-~128: Loose punctuation mark.
Context: ...t blinks in EOG signals. -emgenvelope
: Analyze EMG signals for muscle activity...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~129-~129: Loose punctuation mark.
Context: ...ty or gesture recognition. -keystroke
: Monitor and analyze keystroke dynamics....(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~130-~130: Loose punctuation mark.
Context: ...and analyze keystroke dynamics. -game
: Launch an EEG game for 2 players(Tug of...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~131-~131: Loose punctuation mark.
Context: ...r 2 players(Tug of War). -csv_plotter
: Plot data from a CSV file. -gui
: Lau...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~132-~132: Loose punctuation mark.
Context: ...ter: Plot data from a CSV file. -
gui`: Launch the GUI for real time signal vis...(UNLIKELY_OPENING_PUNCTUATION)
chords.py (4)
57-66
: LGTM! Good hardware support expansion.The new board entries are well-structured and provide consistent configuration for sampling rates and channel counts.
89-95
: Improve error handling in connect_hardware.The UnicodeDecodeError handling could be more informative and include retry logic.
- while response not in supported_boards and retry_counter < retry_limit: - ser.write(b'WHORU\n') # Check board type - try: - response = ser.readline().strip().decode() # Attempt to decode the response - except UnicodeDecodeError as e: - print(f"Decode error: {e}. Ignoring this response.") - response = None + while response not in supported_boards and retry_counter < retry_limit: + ser.write(b'WHORU\n') # Check board type + try: + response = ser.readline().strip().decode() + except UnicodeDecodeError as e: + print(f"Decode error on attempt {retry_counter + 1}/{retry_limit}: {e}") + time.sleep(0.1) # Add delay between retries + response = None
113-122
: LGTM! Good implementation of flexible baud rate handling.The changes improve hardware detection by:
- Making baudrate parameter optional
- Implementing fallback logic as documented
- Providing clear progress messages
334-334
: LGTM! Consistent with flexible baud rate handling.The removal of the default value aligns with the new implementation in detect_hardware.
… positive frequency components, reducing computation time and memory usage for real-time EEG processing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
README.md (3)
54-54
: Fix grammar in baudrate description.The description has minor grammatical issues that should be addressed for clarity.
-- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication. By default the script will first attempt to use 230400, and if that fails, it will automatically fallback to 115200. +- `-b`, `--baudrate` <baudrate>: Set the baud rate for serial communication. By default, the script will first attempt to use 230400, and if that fails, it will automatically fall back to 115200.🧰 Tools
🪛 LanguageTool
[uncategorized] ~54-~54: Loose punctuation mark.
Context: ...o use (e.g., COM5, /dev/ttyUSB0). --b
,--baudrate
: Set the baud r...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~54-~54: Did you mean: “By default,”?
Context: ...the baud rate for serial communication. By default the script will first attempt to use 23...(BY_DEFAULT_COMMA)
[grammar] ~54-~54: The word “fallback” is a noun. The verb is spelled with a space.
Context: ...nd if that fails, it will automatically fallback to 115200. ---csv
: Enable CSV loggin...(NOUN_VERB_CONFUSION)
81-81
: LGTM! Minor formatting fix needed.The script name correction follows Python naming conventions. Just add a space after the colon.
-- `python heartbeat_ecg.py`:Enable a GUI with real-time ECG and heart rate. +- `python heartbeat_ecg.py`: Enable a GUI with real-time ECG and heart rate.🧰 Tools
🪛 LanguageTool
[uncategorized] ~81-~81: Loose punctuation mark.
Context: ... HEART RATE -python heartbeat_ecg.py
:Enable a GUI with real-time ECG and hear...(UNLIKELY_OPENING_PUNCTUATION)
99-126
: Consider adding web interface details.The new section provides good instructions but could benefit from additional information about:
- The web interface URL/port
- Browser compatibility
- Screenshots or example usage
Also, consider adding a troubleshooting section specific to the web interface.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~120-~120: Loose punctuation mark.
Context: ...ave power calculation. -heartbeat_ecg
: Analyze ECG data and extract heartbeat ...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~121-~121: Loose punctuation mark.
Context: ...a and extract heartbeat metrics. -eog
: Real-time EOG monitoring with blink det...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~122-~122: Loose punctuation mark.
Context: ...ng with blink detection. -emgenvelope
: Real-time EMG monitor with filtering an...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~123-~123: Loose punctuation mark.
Context: ...iltering and RMS envelope. -keystroke
: GUI for EOG-based blink detection trigg...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~124-~124: Loose punctuation mark.
Context: ...tection triggering a keystroke. -game
: Launch an EEG game for 2 players (Tug o...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~125-~125: Loose punctuation mark.
Context: ... 2 players (Tug of War). -csv_plotter
: Plot data from a CSV file. -gui
: Lau...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~126-~126: Loose punctuation mark.
Context: ...ter: Plot data from a CSV file. -
gui`: Launch the GUI for real time signal vis...(UNLIKELY_OPENING_PUNCTUATION)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md
(3 hunks)chords.py
(4 hunks)ffteeg.py
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- ffteeg.py
- chords.py
🧰 Additional context used
🪛 LanguageTool
README.md
[uncategorized] ~54-~54: Loose punctuation mark.
Context: ...o use (e.g., COM5, /dev/ttyUSB0). - -b
, --baudrate
: Set the baud r...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~54-~54: Did you mean: “By default,”?
Context: ...the baud rate for serial communication. By default the script will first attempt to use 23...
(BY_DEFAULT_COMMA)
[grammar] ~54-~54: The word “fallback” is a noun. The verb is spelled with a space.
Context: ...nd if that fails, it will automatically fallback to 115200. - --csv
: Enable CSV loggin...
(NOUN_VERB_CONFUSION)
[uncategorized] ~81-~81: Loose punctuation mark.
Context: ... HEART RATE - python heartbeat_ecg.py
:Enable a GUI with real-time ECG and hear...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~97-~97: Loose punctuation mark.
Context: ... ### Keystroke - python keystroke.py
: On running, a pop-up opens for connecti...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~120-~120: Loose punctuation mark.
Context: ...ave power calculation. - heartbeat_ecg
: Analyze ECG data and extract heartbeat ...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~121-~121: Loose punctuation mark.
Context: ...a and extract heartbeat metrics. - eog
: Real-time EOG monitoring with blink det...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~122-~122: Loose punctuation mark.
Context: ...ng with blink detection. - emgenvelope
: Real-time EMG monitor with filtering an...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~123-~123: Loose punctuation mark.
Context: ...iltering and RMS envelope. - keystroke
: GUI for EOG-based blink detection trigg...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~124-~124: Loose punctuation mark.
Context: ...tection triggering a keystroke. - game
: Launch an EEG game for 2 players (Tug o...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~125-~125: Loose punctuation mark.
Context: ... 2 players (Tug of War). - csv_plotter
: Plot data from a CSV file. - gui
: Lau...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~126-~126: Loose punctuation mark.
Context: ...ter: Plot data from a CSV file. -
gui`: Launch the GUI for real time signal vis...
(UNLIKELY_OPENING_PUNCTUATION)
🔇 Additional comments (1)
README.md (1)
95-97
: Verify dependencies for the keystroke application.The new keystroke application likely requires additional dependencies for simulating keystrokes. Please ensure these are documented in
app_requirements.txt
.✅ Verification successful
Dependencies for keystroke application are properly documented ✅
The required dependencies (
keyboard
andPyAutoGUI
) are correctly listed inapp_requirements.txt
, and the implementation inkeystroke.py
uses these libraries as expected.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if keyboard simulation libraries are listed in requirements rg -i "keyboard|pyautogui|pynput" app_requirements.txt # Check if the keystroke.py file imports any keyboard simulation libraries rg -i "import.*keyboard|import.*pyautogui|import.*pynput" keystroke.pyLength of output: 181
🧰 Tools
🪛 LanguageTool
[uncategorized] ~97-~97: Loose punctuation mark.
Context: ... ### Keystroke -python keystroke.py
: On running, a pop-up opens for connecti...(UNLIKELY_OPENING_PUNCTUATION)
Summary by CodeRabbit
Release Notes
New Features
Dependencies
Improvements
Removed
User Interface