The functions below create LinearOperator versions of fftn and the like, operating on vectorized versions of an input array.
Matrix free DFT operator in N-dimensions.
Performs the FFT on an N dimensional input that has been vectorized. The adjoint of this operator is the IFFT. The parameter s influences precisely the relation between the forward and adjoint: if the input is zero padded due to s, then the adjoint will crop back down to the shape size. Similarly, if s crops the input, then the adjoint will pad the output with zeros to match the shape size.
The results, even if the input is real, will be complex.
| Parameters: | shape : tuple
s : sequence of ints, optional
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
| Raises: | ValueError
ValueError
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import fft
>>> a = np.array([0, 1, 2, 3, 2, 1, 0])
>>> F = fft(a.shape)
>>> F(a)
array([ 9.00000000+0.j , -4.54891734-2.19064313j,
0.19202147+0.24078731j, -0.14310413-0.62698017j,
-0.14310413+0.62698017j, 0.19202147-0.24078731j,
-4.54891734+2.19064313j])
>>> np.real((F.T*F)(a))
array([ 2.95002118e-15, 1.00000000e+00, 2.00000000e+00,
3.00000000e+00, 2.00000000e+00, 1.00000000e+00,
-1.90323947e-15])
Shift the zero frequency to the center.
Flips the axes in an input to move the zero frequency. By default, all of the axes are flipped, moving the DC component to the center of the array. However, this can be modified by altering the axes input.
This operator is self adjoint. This means that it will likely be used with the ifftshift to sandwich an operator, such as ifftshift * operator * fftshift.
| Parameters: | shape : tuple
axes : int or shape tuple, optional
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import fft, fftshift
>>> a = np.array([0, 1, 2, 3, 2, 1, 0])
>>> F = fft(a.shape)
>>> F(a)
array([ 9.00000000+0.j , -4.54891734-2.19064313j,
0.19202147+0.24078731j, -0.14310413-0.62698017j,
-0.14310413+0.62698017j, 0.19202147-0.24078731j,
-4.54891734+2.19064313j])
>>> S = fftshift(a.shape)
>>> (S*F)(a)
array([-0.14310413+0.62698017j, 0.19202147-0.24078731j,
-4.54891734+2.19064313j, 9.00000000+0.j ,
-4.54891734-2.19064313j, 0.19202147+0.24078731j,
-0.14310413-0.62698017j])
Surrounds an operator with FFT operations.
Given an operator O, this function returns the following in the case of no shift (shift = ‘none’),
and the following when shift is any other value.
where
| Parameters: | O : LinearOperator
shape : tuple
s : sequence of ints, optional
shift : “none”, “all” or shape tuple
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import fftwrap
>>> from pyop import LinearOperator
>>> a = np.array([1, 1, 1, 1])
>>> I = LinearOperator((4, 4), lambda x: x, lambda x: x)
>>> F = fftwrap(I, (4,))
>>> F(a)
array([ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])
Matrix free inverse DFT operator in N-dimensions.
Performs the IFFT on an N dimensional input that has been vectorized. The adjoint of this operator is the FFT. The parameter s influences precisely the relation between the forward and adjoint: if the input is zero padded due to s, then the adjoint will crop back down to the shape size. Similarly, if s crops the input, then the adjoint will pad the output with zeros to match the shape size.
The results, even if the input is real, will be complex.
| Parameters: | shape : tuple
s : sequence of ints, optional
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
| Raises: | ValueError
ValueError
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import ifft
>>> a = np.array([0, 1, 2, 3, 2, 1, 0])
>>> F = ifft(a.shape)
>>> F(a)
array([ 1.28571429+0.j , -0.64984533+0.31294902j,
0.02743164-0.03439819j, -0.02044345+0.0895686j ,
-0.02044345-0.0895686j , 0.02743164+0.03439819j,
-0.64984533-0.31294902j])
>>> np.real((F.T*F)(a))
array([ 2.78943535e-15, 1.00000000e+00, 2.00000000e+00,
3.00000000e+00, 2.00000000e+00, 1.00000000e+00,
-2.05391260e-15])
Shift the zero frequency to the center.
Flips the axes in an input to move the zero frequency. By default, all of the axes are flipped, moving the DC component to the center of the array. However, this can be modified by altering the axes input.
This operator is self adjoint. This means that it will likely be used with the ifftshift to sandwich an operator, such as fftshift * operator * ifftshift.
| Parameters: | shape : tuple
axes : int or shape tuple, optional
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import ifft, ifftshift
>>> a = np.array([0, 1, 2, 3, 2, 1, 0])
>>> F = ifft(a.shape)
>>> F(a)
array([ 1.28571429+0.j , -0.64984533+0.31294902j,
0.02743164-0.03439819j, -0.02044345+0.0895686j ,
-0.02044345-0.0895686j , 0.02743164+0.03439819j,
-0.64984533-0.31294902j])
>>> S = ifftshift(a.shape)
>>> (S*F)(a)
array([-0.02044345+0.0895686j , -0.02044345-0.0895686j ,
0.02743164+0.03439819j, -0.64984533-0.31294902j,
1.28571429+0.j , -0.64984533+0.31294902j,
0.02743164-0.03439819j])
Surrounds an operator with IFFT operations.
Given an operator O, this function returns the following in the case of no shift (shift = ‘none’),
and the following when shift is any other value.
where
| Parameters: | O : LinearOperator
shape : tuple
s : sequence of ints, optional
shift : “none”, “all” or shape tuple
order = {‘C’, ‘F’}, optional
|
|---|---|
| Returns: | LinearOperator
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import ifftwrap
>>> from pyop import LinearOperator
>>> a = np.array([1, 1, 1, 1])
>>> I = LinearOperator((4, 4), lambda x: x, lambda x: x)
>>> F = ifftwrap(I, (4,))
>>> F(a)
array([ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])