-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample01.py
More file actions
40 lines (30 loc) · 920 Bytes
/
example01.py
File metadata and controls
40 lines (30 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
import matplotlib.pyplot as plt
from processingnodes.nodes import IIRFilterNode
# use a sampling frequency of 250Hz and a sinusoid of 15Hz
fs = 250
f_sine = 15
# generate the time series data
timestamps = np.arange(fs) / fs
noisy_signal = np.sin(2*np.pi*f_sine*timestamps) + (-1 + 2 * np.random.random(size=timestamps.size))
# create an IIR filter node with a bandpass from 13 to 17 Hz
node = IIRFilterNode(
in_channel_labels=["Ch1"],
sfreq=fs,
order=3,
btype="bandpass",
ftype="butter",
fpass=[13, 17],
fstop=[10, 20]
)
# apply the filter
filtered_sine, _ = node.process(noisy_signal)
# plot results
fig, axes = plt.subplots(2, 1, sharex="all", figsize=[10,4])
axes[0].plot(timestamps, noisy_signal)
axes[1].plot(timestamps, filtered_sine)
axes[0].set_title("raw signal")
axes[1].set_title("filtered signal")
plt.xlabel("time [s]")
plt.tight_layout()
plt.show()