-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft.py
More file actions
41 lines (32 loc) · 756 Bytes
/
fft.py
File metadata and controls
41 lines (32 loc) · 756 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
#!/usr/bin/python
import numpy as np
#import scipy.fftpack
#import scipy as sp
import matplotlib.pyplot as plt
import math
import time
def howlong(f):
def tmp(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
print "time: %f" % (time.time()-t)
return res
return tmp
arrlen = 1024
x = []
y = []
z = []
@howlong
def operate():
global x, y, z
x = np.linspace(0, arrlen-1, arrlen)
#x = np.arange(0, 1024, dtype=np.float)
y = np.sin(x*(2*np.pi/arrlen)*500) + np.sin(x*(2*np.pi/arrlen)*250)
z = np.absolute(np.fft.fft(y, arrlen))
#np.allclose()
operate()
plt.plot(x, z)
plt.xlabel(r'$x$')
plt.ylabel(r'$f(x)$')
#plt.grid(1)
plt.show()