Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
c9affb6d
Commit
c9affb6d
authored
Jan 25, 2020
by
s.gretchko
Browse files
Added fft/ifft wrapper (cont'd)
parent
a873c151
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Utilities/FFT.py
View file @
c9affb6d
...
@@ -29,3 +29,120 @@ def FFT(f):
...
@@ -29,3 +29,120 @@ def FFT(f):
return
np
.
fft
.
fftshift
(
F
);
return
np
.
fft
.
fftshift
(
F
);
def
fft
(
a
):
"""
fft(a)
Compute the one-dimensional discrete Fourier transform of a the way Matlab
does. When a is a vector, the Fourier transform of the vector is
returned. When a is a matrix, each column vector of a is
transformed individually, and a new matrix containing the transformed
column vectors of a is returned.
Parameters
----------
a : array_like
1-D or 2-D input array (can be complex)
Returns
-------
result : ndarray
1-D or 2-D array of similar shape and type
containing the discrete fourier transform of a
See Also
--------
ifft
Notes
-----
Using the Numpy function fft on a matrix does not
produce results similar to what Matlab does.
This helper function uses the Numpy functions to produce
a resut that agrees with what Matlab does.
"""
return
transformVectors
(
a
,
np
.
fft
.
fft
)
def
ifft
(
a
):
"""
ifft(a)
Compute the one-dimensional inverse discrete Fourier transform the
way Matlab does. When a is a vector, the inverse Fourier transform
of the vector is returned. When a is a matrix, each column vector
of a is transformed individually, and a new matrix containing the
transformed column vectors of a is returned.
Parameters
----------
a : array_like
1-D or 2-D input array (can be complex)
Returns
-------
out : ndarray
1-D or 2-D array of similar shape and type
containing the inverse discrete fourier transform of a
See Also
--------
fft
Notes
-----
Using the Numpy function ifft on a matrix does not
produce results similar to what Matlab does.
This helper function uses the Numpy functions to produce
a resut that agrees with what Matlab does.
"""
return
transformVectors
(
a
,
np
.
fft
.
ifft
)
def
transformVectors
(
a
,
transform
):
"""
transformVectors(a, transform)
Transform a according to the given transform function.
When a is a vector, it applies the transform function to a
and returns the result. When a is a matrix, each column vector
of a is transformed individually using the given transform function,
and a new matrix containing the transformed column vectors
of a is returned.
Parameters
----------
a : array_like
1-D or 2-D input array
transform : callable function
This function takes a 1-D array as argument and returns
a 1-D array of same size. This function is applied to a if
it is a vector or to the column vectors of a if a is a matrix.
Returns
-------
out : ndarray
1-D or 2-D array of similar shape and type
containing the transformed data
See Also
--------
fft, ifft
Notes
-----
This function is used by fft(a) and ifft(a).
"""
if
a
.
ndim
==
1
:
# a is a vector
out
=
transform
(
a
)
else
:
# assume a is a matrix (2d array)
shape
=
a
.
shape
colCount
=
shape
[
1
]
#result = np.empty_like(a)
out
=
np
.
zeros_like
(
a
)
# for each column vector in a
for
i
in
range
(
0
,
colCount
):
col
=
a
[:,
i
]
fft_col
=
transform
(
col
)
out
[:,
i
]
=
fft_col
return
out
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment