# Python numpy.fft.fftfreq() Examples

The following are code examples for showing how to use numpy.fft.fftfreq(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
```def fourierExtrapolation(x, n_predict):
n = x.size
n_harm = 10                     # number of harmonics in model
t = np.arange(0, n)
p = np.polyfit(t, x, 1)         # find linear trend in x
x_notrend = x - p[0] * t        # detrended x
x_freqdom = fft.fft(x_notrend)  # detrended x in frequency domain
f = fft.fftfreq(n)              # frequencies
indexes = range(n)
# sort indexes by frequency, lower -> higher
indexes.sort(key = lambda i: np.absolute(f[i]))

t = np.arange(0, n + n_predict)
restored_sig = np.zeros(t.size)
for i in indexes[:1 + n_harm * 2]:
ampli = np.absolute(x_freqdom[i]) / n   # amplitude
phase = np.angle(x_freqdom[i])          # phase
restored_sig += ampli * np.cos(2 * np.pi * f[i] * t + phase)
return restored_sig + p[0] * t ```
Example 2
 Project: droppy   Author: BV-DR   File: TimeSignals.py    GNU General Public License v3.0 6 votes
```def derivFFT(df, n=1):
""" Deriv a signal trought FFT, warning, edge can be a bit noisy...
indexList : channel to derive
n : order of derivation
"""
deriv = []
for iSig in range(df.shape[1]):
fft = np.fft.fft(df.values[:, iSig])  # FFT
freq = np.fft.fftfreq(df.shape[0], dx(df))

from copy import deepcopy
fft0 = deepcopy(fft)
if n > 0:
fft0 *= (1j * 2 * pi * freq[:])**n  # Derivation in frequency domain
else:
fft0[-n:] *= (1j * 2 * pi * freq[-n:])**n
fft0[0:-n] = 0.

tts = np.real(np.fft.ifft(fft0))
tts -= tts[0]
deriv.append(tts)  # Inverse FFT

return pd.DataFrame(data=np.transpose(deriv), index=df.index, columns=["DerivFFT(" + x + ")" for x in df.columns]) ```
Example 3
 Project: syris   Author: ufo-kit   File: propagator.py    GNU Lesser General Public License v3.0 6 votes
```def compute_fourier_propagator(n, lam, z, ps, fresnel=True):
try:
ps[0]
except:
ps = (ps.magnitude, ps.magnitude) * ps.units

lam = lam.rescale(q.m).magnitude
z = z.rescale(q.m).magnitude
ps = ps.rescale(q.m).magnitude

freqs = fftfreq(n)
f = np.tile(freqs, [n, 1])
g = np.copy(f.transpose())
f /= ps[1]
g /= ps[0]

if fresnel:
result = np.exp(1j * 2 * np.pi / lam * z) * \
np.exp(-1j * np.pi * lam * z * (f ** 2 + g ** 2))
else:
result = np.exp(1j * 2 * np.pi / lam * z * np.sqrt(1 - (f * lam) ** 2 - (g * lam) ** 2))

return result ```
Example 4
 Project: mpiFFT4py   Author: spectralDNS   File: slab.py    GNU Lesser General Public License v3.0 6 votes
```def __init__(self, N, L, comm, precision,
communication="Alltoall",
planner_effort=defaultdict(lambda: "FFTW_MEASURE")):
R2C.__init__(self, N, L, comm, precision,
communication=communication,
planner_effort=planner_effort)
# Reuse all shapes from r2c transform R2C simply by resizing the final complex z-dimension:
self.Nf = N[2]
self.Nfp = int(self.padsize*self.N[2]) # Independent complex wavenumbers in z-direction for padded array

# Rename since there's no real space
self.original_shape = self.real_shape
self.transformed_shape = self.complex_shape
self.original_local_slice = self.real_local_slice
self.transformed_local_slice = self.complex_local_slice
self.ks = (fftfreq(N[2])*N[2]).astype(int) ```
Example 5
 Project: mpiFFT4py   Author: spectralDNS   File: line.py    GNU Lesser General Public License v3.0 6 votes
```def __init__(self, N, L, comm, precision, padsize=1.5, threads=1,
planner_effort=defaultdict(lambda : "FFTW_MEASURE")):
self.N = N         # The global size of the problem
self.L = L
assert len(L) == 2
assert len(N) == 2
self.comm = comm
self.float, self.complex, self.mpitype = float, complex, mpitype = datatypes(precision)
self.num_processes = comm.Get_size()
self.rank = comm.Get_rank()
self.planner_effort = planner_effort
# Each cpu gets ownership of Np indices
self.Np = N // self.num_processes
self.Nf = N[1]//2+1
self.Npf = self.Np[1]//2+1 if self.rank+1 == self.num_processes else self.Np[1]//2
self.ks = (fftfreq(N[0])*N[0]).astype(int)
self.dealias = zeros(0)
self.work_arrays = work_arrays() ```
Example 6
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 7
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 8
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 9
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_helper.py    GNU General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 10
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 11
 Project: MARRtino-2.0   Author: DaniAffCH   File: test_helper.py    GNU General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 12
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 13
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 14
```def spd(self, npos):
'''raw spectral density, returns Fourier transform

n is number of points in positive spectrum, the actual number of points
is twice as large. different from other spd methods with fft
'''
n = npos
w = fft.fftfreq(2*n) * 2 * np.pi
hw = self.fftarma(2*n)  #not sure, need to check normalization
#return (hw*hw.conj()).real[n//2-1:]  * 0.5 / np.pi #doesn't show in plot
return (hw*hw.conj()).real * 0.5 / np.pi, w ```
Example 15
```def spdshift(self, n):
'''power spectral density using fftshift

currently returns two-sided according to fft frequencies, use first half
'''
#size = s1+s2-1
#return np.abs(spd)[n//2-1:]
w = fft.fftfreq(n) * 2 * np.pi
wslice = slice(n//2-1, None, None)
#return (hw*hw.conj()).real[wslice], w[wslice]
return (hw*hw.conj()).real, w ```
Example 16
```def spddirect(self, n):
'''power spectral density using padding to length n done by fft

currently returns two-sided according to fft frequencies, use first half
'''
#size = s1+s2-1
#abs looks wrong
hw = fft.fft(self.ma, n) / fft.fft(self.ar, n)
w = fft.fftfreq(n) * 2 * np.pi
wslice = slice(None, n//2, None)
#return (np.abs(hw)**2)[wslice], w[wslice]
return (np.abs(hw)**2) * 0.5/np.pi, w ```
Example 17
 Project: SEELablet   Author: jithinbp   File: analyticsClass.py    GNU General Public License v3.0 5 votes
```def find_frequency(self, v, si):  # voltages, samplimg interval is seconds
from numpy import fft
NP = len(v)
v = v -v.mean()			# remove DC component
frq = fft.fftfreq(NP, si)[:NP/2]	# take only the +ive half of the frequncy array
amp = abs(fft.fft(v)[:NP/2])/NP		# and the fft result
index =  amp.argmax()				# search for the tallest peak, the fundamental
return frq[index] ```
Example 18
 Project: SEELablet   Author: jithinbp   File: analyticsClass.py    GNU General Public License v3.0 5 votes
```def amp_spectrum(self, v, si, nhar=8):
# voltages, samplimg interval is seconds, number of harmonics to retain
from numpy import fft
NP = len(v)
frq = fft.fftfreq(NP, si)[:NP/2]	# take only the +ive half of the frequncy array
amp = abs(fft.fft(v)[:NP/2])/NP		# and the fft result
index =  amp.argmax()				# search for the tallest peak, the fundamental
if index == 0:						# DC component is dominating
index =  amp[4:].argmax()		# skip frequencies close to zero
return frq[:index*nhar], amp[:index*nhar]	# restrict to 'nhar' harmonics ```
Example 19
 Project: SEELablet   Author: jithinbp   File: analyticsClass.py    GNU General Public License v3.0 5 votes
```def fft(self,ya, si):
'''
Returns positive half of the Fourier transform of the signal ya.
Sampling interval 'si', in milliseconds
'''
ns = len(ya)
if ns %2 == 1:  # odd values of np give exceptions
ns=ns-1 # make it even
ya=ya[:-1]
v = np.array(ya)
tr = abs(np.fft.fft(v))/ns
frq = np.fft.fftfreq(ns, si)
x = frq.reshape(2,ns/2)
y = tr.reshape(2,ns/2)
return x[0], y[0] ```
Example 20
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 21
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 22
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 23
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 24
 Project: BabyMonitor   Author: 0x1001   File: analyzer.py    GNU General Public License v2.0 5 votes
```def _fft(self, audio_data):
from numpy import fft

amp = fft.rfft(audio_data)
freq = fft.fftfreq(audio_data.shape[-1])[:len(amp)]

return freq, amp.real ```
Example 25
```def __init__(self, decomp, context, queue, grid_shape, dtype):
"""
:arg decomp: A :class:`pystella.DomainDecomposition`.

:arg context: A :class:`pyopencl.Context`.

:arg queue: A :class:`pyopencl.CommandQueue`.

:arg grid_shape: A 3-:class:`tuple` specifying the shape of position-space
arrays to be transformed.

:arg dtype: The datatype of real arrays to be transformed. The complex
datatype is chosen to have the same precision.
"""

self.decomp = decomp
self.grid_shape = grid_shape
self.dtype = dtype
cdtype = _c_dtype_mapping[dtype]
self.cdtype = cdtype

self.fx = cla.zeros(queue, grid_shape, dtype)
self.fk = cla.zeros(queue, self.shape(True), cdtype)
from gpyfft import FFT
self.forward = FFT(context, queue, self.fx, out_array=self.fk, real=True,
scale_forward=1, scale_backward=1)
self.backward = FFT(context, queue, self.fk, out_array=self.fx, real=True,
scale_forward=1, scale_backward=1)

from numpy.fft import fftfreq, rfftfreq
names = ('momenta_x', 'momenta_y', 'momenta_z')

slc = ((), (), (),)
k = [fftfreq(n, 1/n).astype(dtype) for n in grid_shape]
self.sub_k_c = {direction: cla.to_device(queue, k_i[s_i])
for direction, k_i, s_i in zip(names, k, slc)}

k[-1] = rfftfreq(grid_shape[-1], 1/grid_shape[-1]).astype(dtype)
self.sub_k = {direction: cla.to_device(queue, k_i[s_i])
for direction, k_i, s_i in zip(names, k, slc)} ```
Example 26
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 27
 Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 28
 Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 29
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 30
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 31
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 32
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 33
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 34
 Project: facethin   Author: ParkerGod   File: test_helper.py    GNU General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 35
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 36
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 37
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 38
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 39
 Project: syris   Author: ufo-kit   File: paganin.py    GNU Lesser General Public License v3.0 5 votes
```def compute_tie_kernel(n, pixel_size, distance, material, energy):
pixel_size = pixel_size.rescale(q.m).magnitude
distance = distance.rescale(q.m).magnitude
f_0 = fftfreq(n) / pixel_size
f = f_0 * 2 * np.pi
f_0, g_0 = np.meshgrid(f_0, f_0)
f, g = np.meshgrid(f, f)
ri = material.get_refractive_index(energy)
delta = ri.real
beta = ri.imag
mju = material.get_attenuation_coefficient(energy).rescale(1 / q.m).magnitude
fmt = '                            mju: {}'
print fmt.format(mju)
fmt = '                          delta: {}'
print fmt.format(delta)
fmt = '                           beta: {}'
print fmt.format(beta)
fmt = '    Regularization rate for UFO: {}'
print fmt.format(np.log10(delta / beta))

return mju / (distance * ri.real * (f ** 2 + g ** 2) + mju)
# Alternative forms
# lam = energy_to_wavelength(energy).rescale(q.m).magnitude
# tmp = 4 * np.pi * lam * beta
# alpha = beta / delta
# return alpha / (np.pi * lam * distance * (f_0 ** 2 + g_0 ** 2) + alpha)
# return tmp / (lam ** 2 * distance * delta * (f ** 2 + g ** 2) + tmp) ```
Example 40
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 41
 Project: linux-cross-gcc   Author: nmercier   File: test_helper.py    BSD 3-Clause "New" or "Revised" License 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 42
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 43
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 44
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 45
 Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 46
 Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 47
```def test_definition(self):
x = [0, 1, 2, 3, 4, -4, -3, -2, -1]
assert_array_almost_equal(9*fft.fftfreq(9), x)
assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x)
x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]
assert_array_almost_equal(10*fft.fftfreq(10), x)
assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) ```
Example 48
 Project: Splunking-Crime   Author: nccgroup   File: fftarma.py    GNU Affero General Public License v3.0 5 votes
```def spd(self, npos):
'''raw spectral density, returns Fourier transform

n is number of points in positive spectrum, the actual number of points
is twice as large. different from other spd methods with fft
'''
n = npos
w = fft.fftfreq(2*n) * 2 * np.pi
hw = self.fftarma(2*n)  #not sure, need to check normalization
#return (hw*hw.conj()).real[n//2-1:]  * 0.5 / np.pi #doesn't show in plot
return (hw*hw.conj()).real * 0.5 / np.pi, w ```
Example 49
 Project: Splunking-Crime   Author: nccgroup   File: fftarma.py    GNU Affero General Public License v3.0 5 votes
```def spdshift(self, n):
'''power spectral density using fftshift

currently returns two-sided according to fft frequencies, use first half
'''
#size = s1+s2-1
#return np.abs(spd)[n//2-1:]
w = fft.fftfreq(n) * 2 * np.pi
wslice = slice(n//2-1, None, None)
#return (hw*hw.conj()).real[wslice], w[wslice]
return (hw*hw.conj()).real, w ```
Example 50
 Project: Splunking-Crime   Author: nccgroup   File: fftarma.py    GNU Affero General Public License v3.0 5 votes
```def spddirect(self, n):
'''power spectral density using padding to length n done by fft

currently returns two-sided according to fft frequencies, use first half
'''
#size = s1+s2-1
#abs looks wrong
hw = fft.fft(self.ma, n) / fft.fft(self.ar, n)
w = fft.fftfreq(n) * 2 * np.pi
wslice = slice(None, n//2, None)
#return (np.abs(hw)**2)[wslice], w[wslice]
return (np.abs(hw)**2) * 0.5/np.pi, w ```