@@ -13,13 +13,25 @@ def __init__(self):
13
13
self .setWindowTitle ("Real-Time EMG Monitor with EMG Envelope" )
14
14
self .setGeometry (100 , 100 , 800 , 600 )
15
15
16
- self .plot_widget = PlotWidget (self )
17
- self .plot_widget .setBackground ('w' )
18
- self .plot_widget .showGrid (x = True , y = True )
19
-
16
+ # Create layout
20
17
layout = QVBoxLayout ()
21
- layout .addWidget (self .plot_widget )
22
18
19
+ # Create plot widgets for raw EMG and EMG envelope
20
+ self .raw_emg_plot = PlotWidget (self )
21
+ self .raw_emg_plot .setBackground ('w' )
22
+ self .raw_emg_plot .showGrid (x = True , y = True )
23
+ self .raw_emg_plot .setTitle ("Raw EMG Signal" )
24
+
25
+ self .envelope_plot = PlotWidget (self )
26
+ self .envelope_plot .setBackground ('w' )
27
+ self .envelope_plot .showGrid (x = True , y = True )
28
+ self .envelope_plot .setTitle ("EMG Envelope" )
29
+
30
+ # Add plots to layout
31
+ layout .addWidget (self .raw_emg_plot )
32
+ layout .addWidget (self .envelope_plot )
33
+
34
+ # Central widget
23
35
central_widget = QWidget ()
24
36
central_widget .setLayout (layout )
25
37
self .setCentralWidget (central_widget )
@@ -47,17 +59,20 @@ def __init__(self):
47
59
self .rms_window_size = int (0.1 * self .sampling_rate )
48
60
49
61
# Set fixed axis ranges
50
- self .plot_widget .setXRange (0 , 10 , padding = 0 )
62
+ self .raw_emg_plot .setXRange (0 , 10 , padding = 0 )
63
+ self .envelope_plot .setXRange (0 , 10 , padding = 0 )
51
64
52
- # Set y-axis limits based on sampling rate
65
+ # Set y-axis limits based on sampling rate for raw EMG
53
66
if self .sampling_rate == 250 :
54
- self .plot_widget .setYRange (400 ,600 ,padding = 0 ) # for R3 & ensuring no extra spaces at end
67
+ self .raw_emg_plot .setYRange (- ((2 ** 10 )/ 2 ), ((2 ** 10 )/ 2 ), padding = 0 ) # for R3
68
+ self .envelope_plot .setYRange (0 , ((2 ** 10 )/ 2 ), padding = 0 ) # for R3
55
69
elif self .sampling_rate == 500 :
56
- self .plot_widget .setYRange (400 , 10000 ,padding = 0 ) # for R4 & ensuring no extra spaces at end
70
+ self .raw_emg_plot .setYRange (- ((2 ** 14 )/ 2 ), ((2 ** 14 )/ 2 ), padding = 0 ) # for R4
71
+ self .envelope_plot .setYRange (0 , ((2 ** 14 )/ 2 ), padding = 0 ) # for R4
57
72
58
73
# Plot curves for EMG data and envelope
59
- self .emg_curve = self .plot_widget .plot (self .time_data , self .emg_data , pen = pg .mkPen ('b' , width = 1 ))
60
- self .envelope_curve = self .plot_widget .plot (self .time_data , self .emg_data , pen = pg .mkPen ('r' , width = 2 ))
74
+ self .emg_curve = self .raw_emg_plot .plot (self .time_data , self .emg_data , pen = pg .mkPen ('b' , width = 1 ))
75
+ self .envelope_curve = self .envelope_plot .plot (self .time_data , self .emg_data , pen = pg .mkPen ('r' , width = 2 ))
61
76
62
77
# Timer for plot update
63
78
self .timer = pg .QtCore .QTimer ()
@@ -79,11 +94,9 @@ def update_plot(self):
79
94
80
95
# Filter the EMG data
81
96
filtered_emg = filtfilt (self .b , self .a , self .emg_data )
82
- # print(filtered_emg)
83
97
84
98
# Take absolute value before calculating RMS envelope
85
99
abs_filtered_emg = np .abs (filtered_emg )
86
- # print(abs_filtered_emg)
87
100
88
101
# Calculate the RMS envelope
89
102
rms_envelope = self .calculate_moving_rms (abs_filtered_emg , self .rms_window_size )
0 commit comments