-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadaptiveFilter.py
More file actions
64 lines (43 loc) · 884 Bytes
/
adaptiveFilter.py
File metadata and controls
64 lines (43 loc) · 884 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
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
64
# -*- coding: utf-8 -*-
##
## Author: Emil Svendsen
## Date: 27/11-2018
## Last edit: 27/11-2018
##
## Adaptive Filter
import scipy.signal as signal
import scipy.fftpack as fft
import numpy as np
import matplotlib.pyplot as plt
fs = 80
num_samples = 1000
df = (fs/2) / num_samples
f = np.arange(0, fs / 2, df)
n = np.arange(0, num_samples)
## Signal
s = np.sin(2* np.pi * f)
## White noise
mean = 0
std = 1
noise = np.random.normal(mean, std, size=num_samples)
## Signal plus noise
d = s + noise
## Filter wieghts
w = [0.5]
mu = 0.02
y = np.zeros(num_samples)
e = np.zeros(num_samples)
for i in n:
y[i] = w[0] * noise[i]
e[i] = d[i] - y[i]
w[0] = w[0] + 2* mu * (e[i] * noise[i])
#print(w[0])
plt.subplot(2,2,1)
plt.plot(s)
plt.subplot(2,2,2)
plt.plot(d)
plt.subplot(2,2,3)
plt.plot(y)
plt.subplot(2,2,4)
plt.plot(e)
plt.show()