Repository navigation
Expand file tree
/
Copy pathdigital_processing.py
More file actions
64 lines (45 loc) · 1.54 KB
/
Copy pathdigital_processing.py
File metadata and controls
64 lines (45 loc) · 1.54 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
import pyyawt
def notch_filter(x, samplerate, plot=False):
x = x - np.mean(x)
high_cutoff_notch = 59 / (samplerate / 2)
low_cutoff_notch = 61 / (samplerate / 2)
[b, a] = signal.butter(4, [high_cutoff_notch, low_cutoff_notch], btype='stop')
x_filt = signal.filtfilt(b, a, x.T)
if plot:
t = np.arange(0, len(x) / samplerate, 1 / samplerate)
plt.plot(t, x)
plt.plot(t, x_filt.T, 'k')
plt.autoscale(tight=True)
plt.xlabel('Time')
plt.ylabel('Amplitude (mV)')
plt.show()
return x_filt
def bp_filter(x, low_f, high_f, samplerate, plot=False):
# x = x - np.mean(x)
low_cutoff_bp = low_f / (samplerate / 2)
high_cutoff_bp = high_f / (samplerate / 2)
[b, a] = signal.butter(5, [low_cutoff_bp, high_cutoff_bp], btype='bandpass')
x_filt = signal.filtfilt(b, a, x)
if plot:
t = np.arange(0, len(x) / samplerate, 1 / samplerate)
plt.plot(t, x)
plt.plot(t, x_filt, 'k')
plt.autoscale(tight=True)
plt.xlabel('Time')
plt.ylabel('Amplitude (mV)')
plt.show()
return x_filt
def plot_signal(x, samplerate, chname):
t = np.arange(0, len(x) / samplerate, 1 / samplerate)
plt.plot(t, x)
plt.autoscale(tight=True)
plt.xlabel('Time')
plt.ylabel('Amplitude (mV)')
plt.title(chname)
plt.show()
def denoisewavelet(x1, level=5):
xd, cxd, lxd = pyyawt.wden(x1, 'minimaxi', 's', 'mln', level, 'db5')
return xd