-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourier.py
60 lines (43 loc) · 1.24 KB
/
fourier.py
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
import matplotlib.pyplot as plt
import numpy as np
DT = 0.001
MAX_FREQ = 1 / DT
T0 = 0
TF = 1
FREQUENCY_1 = 20
PERIOD_1 = 1 / FREQUENCY_1
FREQUENCY_2 = 50
PERIOD_2 = 1 / FREQUENCY_2
FREQUENCY_3 = 200
PERIOD_3 = 1 / FREQUENCY_3
AMPLITUDE_NOISE_1 = 1
AMPLITUDE_NOISE_2 = 0.1
temps = np.arange(T0, TF, DT)
n = len(temps)
freqs = np.linspace(0, 1/DT, n)
noise_1 = np.random.random(size=(len(temps))) * AMPLITUDE_NOISE_1 * 2 - AMPLITUDE_NOISE_1
noise_2 = np.random.random(size=(len(temps))) * AMPLITUDE_NOISE_2 * 2 - AMPLITUDE_NOISE_2
y1 = np.sin(2 * np.pi * FREQUENCY_1 * temps)
y2 = np.sin(2 * np.pi * FREQUENCY_2 * temps)
y3 = np.sin(2 * np.pi * FREQUENCY_3 * temps)
y_clean = y1 + y2 + y3
y_noisy = y1 + y2 + y3 + noise_1 + noise_2
# plt.plot(t,y_clean, label='clean')
# plt.plot(t,y_noisy, label='noisy')
# plt.show()
fhat = np.fft.fft(y_noisy, n=10)
print(fhat)
print(fhat[0])
print(np.conj(fhat[0]))
PSD = fhat * np.conj(fhat) / n
# plt.plot(freqs, PSD)
# plt.xlim([0,freqs[int(n / 2)]])
# plt.show()
def rot_matrix(a, degrees=45):
# Maximum 45
rows = a.shape[0]
a_copy = np.copy(a)
for row in range(rows):
shift = int(row * np.tan(np.radians(degrees)))
a_copy[row,:] = np.roll(a_copy[row,:], shift)
return a_copy