-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfft.py
More file actions
31 lines (21 loc) · 911 Bytes
/
fft.py
File metadata and controls
31 lines (21 loc) · 911 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
from scipy import fftpack
import numpy as np
import pylab as py
class fft:
def __init__(self):
pass
def _1DFFT(self, data, fs):
xdft = fftpack.fft(data) # take fft
xdft_posi_only = xdft[0:len(xdft)/2+1] # take only positive terms and DC offset (negative terms past n/2 + 1)
psdx = (1./(fs*len(data)))*pow(abs(xdft_posi_only), 2) # get magnitude
psdx[1:len(psdx)-1] = 2*psdx[1:len(psdx)-1] # in order to conserve total power, multiply the frequencies by two (as neg freqs disregarded)
freq = np.arange(float(len(psdx)))
freq *= float(fs)/float(len(data))
return freq, psdx
def do1DReadoutFFT(self, data, fs):
'''
reformat data into 2D
'''
data_1D = np.fliplr(data).ravel()
this_freq, this_psdx = self._1DFFT(data_1D, fs)
return this_freq, this_psdx