1
- """Example program to demonstrate how to read a multi-channel time-series
2
- from LSL in a chunk-by-chunk manner (which is more efficient).
3
-
4
- Please restart this script if you change one of the data types.
5
- Also, the # Chan should match the data type (Examples: 1 for Focus, 3 for Accel)
6
-
7
- """
8
-
9
- from pylsl import StreamInlet , resolve_stream
10
- import time
11
-
12
- numStreams = 3
13
- duration_seconds = 20
14
- # first resolve an EEG stream on the lab network
15
- print ("looking for an EEG stream..." )
16
- stream_1 = resolve_stream ('type' , 'EEG' )
17
- stream_2 = resolve_stream ('type' , 'AUX' )
18
- stream_3 = resolve_stream ('type' , 'FOCUS' )
19
-
20
- # create a new inlet to read from the stream
21
- inlet = StreamInlet (stream_1 [0 ])
22
- intlet_2 = StreamInlet (stream_2 [0 ])
23
- intlet_3 = StreamInlet (stream_3 [0 ])
24
-
25
- def testLSLSamplingRates ():
26
- print ( "Testing Sampling Rates for {} seconds" .format (duration_seconds ) )
27
- start = time .time ()
28
- num_samples_1 = 0
29
- num_samples_2 = 0
30
- num_samples_3 = 0
31
- while time .time () < start + duration_seconds :
32
- # get a new sample (you can also omit the timestamp part if you're not
33
- # interested in it)
34
- for i in range (numStreams ):
35
- if i == 0 :
36
- chunk , timestamps = inlet .pull_chunk ()
37
- if timestamps :
38
- for sample in chunk :
39
- if sample :
40
- num_samples_1 += 1
41
- #print(sample)
42
- elif i == 1 :
43
- chunk , timestamps_2 = intlet_2 .pull_chunk ()
44
- if timestamps_2 :
45
- for sample in chunk :
46
- num_samples_2 += 1
47
- #print(sample)
48
- elif i == 2 :
49
- chunk , timestamps_3 = intlet_3 .pull_chunk ()
50
- if timestamps_3 :
51
- for sample in chunk :
52
- num_samples_3 += 1
53
- #print(sample)
54
- #print("Stream", i + 1, " == ", chunk)
55
- print ( "Stream 1 Sampling Rate == " , num_samples_1 / duration_seconds , " | Type : EEG" )
56
- print ( "Stream 2 Sampling Rate == " , num_samples_2 / duration_seconds , " | Type : AUX" )
57
- print ( "Stream 3 Sampling Rate == " , num_samples_3 / duration_seconds , " | Type : FOCUS" )
58
-
59
-
1
+ """Example program to demonstrate how to read a multi-channel time-series
2
+ from LSL in a chunk-by-chunk manner (which is more efficient).
3
+
4
+ Please restart this script if you change one of the data types.
5
+ Also, the # Chan should match the data type (Examples: 1 for Focus, 3 for Accel)
6
+
7
+ """
8
+
9
+ from pylsl import StreamInlet , resolve_stream
10
+ import time
11
+
12
+ numStreams = 3
13
+ duration_seconds = 10
14
+ # first resolve an EEG stream on the lab network
15
+ print ("looking for an EEG stream..." )
16
+ stream_1 = resolve_stream ('type' , 'EEG' )
17
+ stream_2 = resolve_stream ('type' , 'AUX' )
18
+ stream_3 = resolve_stream ('type' , 'FOCUS' )
19
+
20
+ # create a new inlet to read from the stream
21
+ inlet = StreamInlet (stream_1 [0 ])
22
+ inlet_2 = StreamInlet (stream_2 [0 ])
23
+ inlet_3 = StreamInlet (stream_3 [0 ])
24
+
25
+ def testLSLSamplingRates ():
26
+ print ( "Testing Sampling Rates for {} seconds" .format (duration_seconds ) )
27
+ start = time .time ()
28
+ num_samples_1 = 0
29
+ num_samples_2 = 0
30
+ num_samples_3 = 0
31
+ while time .time () < start + duration_seconds :
32
+ # get a new sample (you can also omit the timestamp part if you're not
33
+ # interested in it)
34
+ for i in range (numStreams ):
35
+ if i == 0 :
36
+ chunk , timestamps = inlet .pull_chunk ()
37
+ if timestamps :
38
+ for sample in chunk :
39
+ if sample :
40
+ num_samples_1 += 1
41
+ #print(sample)
42
+ elif i == 1 :
43
+ chunk , timestamps_2 = inlet_2 .pull_chunk ()
44
+ if timestamps_2 :
45
+ for sample in chunk :
46
+ num_samples_2 += 1
47
+ #print(sample)
48
+ elif i == 2 :
49
+ chunk , timestamps_3 = inlet_3 .pull_chunk ()
50
+ if timestamps_3 :
51
+ for sample in chunk :
52
+ num_samples_3 += 1
53
+ #print(sample)
54
+ #print("Stream", i + 1, " == ", chunk)
55
+ print ( "Stream 1 Sampling Rate == " , num_samples_1 / duration_seconds , " | Type : EEG" )
56
+ print ( "Stream 2 Sampling Rate == " , num_samples_2 / duration_seconds , " | Type : AUX" )
57
+ print ( "Stream 3 Sampling Rate == " , num_samples_3 / duration_seconds , " | Type : FOCUS" )
58
+
59
+
60
60
testLSLSamplingRates ()
0 commit comments