def main(): in_stream = StreamArray('in_stream') out_stream = StreamArray('out_stream') drop_start = 800 drop_end = 800 output_size = 4000 fs = 50 b, a = butter_bandpass( lowcut=0.05, highcut=2.0, fs=fs, order=2) stream_bandpass_filter_windowing( in_stream, out_stream, filtfilt, drop_start, drop_end, output_size, b, a) t = np.linspace(0, 200, 10001) x = np.sin(2*np.pi*t) x2 = np.sin(2*np.pi*10*t) z = x + x2 fs = 50 in_stream.extend(z) gap = fs*8 for i in range(8): plt.plot(out_stream.recent[1000*i+drop_start:1000*i+drop_start + gap], 'r', x[1000*i:1000*i + gap], 'b') plt.show() plt.close() return
def main(): in_stream=StreamArray('in_stream') out_stream = demean_stream( in_stream=in_stream, window_size=4, step_size=4, num_windows=3) out_stream.name = 'demeaned stream' print_stream(in_stream) print_stream(out_stream) in_stream.extend(np.arange(24)) return
def main(): """For input: data=[2, 5, 8, 11, 14, 17, ...], initial_value=2, the expected output is: [ 2 4 6 8 10 12 ....] """ print lossy_integration( data=np.array([2, 5, 8, 11, 14, 17]), initial_value=0, FACTOR=0.5) in_stream = StreamArray('in_stream') out_stream = lossy_integrate_stream( in_stream, window_size=4, initial_value=0.0, FACTOR=0.5) out_stream.name = "integrated" print_stream(in_stream) print_stream(out_stream) in_stream.extend([2+3*i for i in range(12)])
def test(): # Create stream x and give it names 'x'. x = StreamArray('input') # v is the stream returned by stream_cumulative(x) and v = stream_cumulative(x) # avg is the stream returned by stream_average(x) avg = stream_average(x) # Give names to streams. This is helpful in reading output. v.set_name('cumulative sum of input') avg.set_name('average of input') check(v, [3.0, 8.0, 18.0, 20.0, 25.0, 36.0]) check(avg, [3.0, 4.0, 6.0, 5.0, 5.0, 6.0]) print print 'add values [3, 5, 10] to the tail of the input stream.' # Add values to the tail of stream x. x.extend([3, 5, 10]) # Print the N most recent values of streams x, v, w. x.print_recent() v.print_recent() avg.print_recent() print print 'add values [2, 5, 11] to the tail of the input stream.' # Add more values to the tail of stream x. x.extend([2, 5, 11]) # Print the N most recent values of streams x, v, w. x.print_recent() v.print_recent() avg.print_recent() check_empty()