Created
March 26, 2025 22:39
-
-
Save Ademking/140b9a77d0ad76769099e9b6b09f8999 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Path to the H5 dataset | |
h5_file_path = "./data/your_dataset.h5" | |
# Open the HDF5 file | |
with h5py.File(h5_file_path, "r") as f: | |
# Load datasets | |
ppg_data = f["PPG"][:] # PPG signals | |
bp_labels = f["label"][:] # BP labels (systolic, diastolic) | |
subject_idx = f["subject_idx"][:] # Subject IDs | |
# Extract first sample (first 875 points) | |
ppg_signal = ppg_data[0] # First PPG window (7s) | |
systolic_bp, diastolic_bp = bp_labels[0] # First BP label | |
# Time axis (assuming 125 Hz sampling rate → 7s window) | |
time_axis = np.linspace(0, 7, num=875) | |
# Plot PPG signal | |
plt.figure(figsize=(10, 4)) | |
plt.plot(time_axis, ppg_signal, label="PPG Signal", color="blue") | |
plt.axhline(y=systolic_bp, color='red', linestyle='--', label=f"Systolic BP: {systolic_bp}") | |
plt.axhline(y=diastolic_bp, color='green', linestyle='--', label=f"Diastolic BP: {diastolic_bp}") | |
# Labels and legend | |
plt.xlabel("Time (seconds)") | |
plt.ylabel("PPG Amplitude") | |
plt.title("PPG Signal with Blood Pressure Labels") | |
plt.legend() | |
plt.grid(True) | |
# Show plot | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment