sfft

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: MPL-2.0 Imports: 4 Imported by: 4

Documentation

Overview

Package sfft provides a set of method to simplify calculations of 2D and 3D FFTs. It is solely based on the 1D FFT method provided by Gonum.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Center2

func Center2(data Mutable2)

Center2 puts the origin a(i.e. zero frequency) t the center of the image of a 2D transform

func Center3

func Center3(data *Mat3)

Center3 brings the center (i.e. zero frequency) of a 3D transform to the center of the 3D array

func CmplxEqualApprox

func CmplxEqualApprox(a complex128, b complex128, tol float64) bool

CmplxEqualApprox checks if a and b is equal. a and b is considered equal if their real and imaginary parts are equal within tol

func ToComplex

func ToComplex(data []float64) []complex128

ToComplex returns a complex representation of a real slice. The real part of the returned array is equal to the passed array, and the imaginary part is set to zero

Types

type CMat3

type CMat3 struct {
	Data []complex128
	// contains filtered or unexported fields
}

CMat3 is a type that represents a 3D array. If the size is (nr, nc, nd) the relation between 3D index (i, j, k) and the flatted Data array is: (i, j, k) -> k*nr*nc + i*nc + j

func NewCMat3

func NewCMat3(nr, nc, nd int, data []complex128) *CMat3

NewCMat3 returns a new CMat3 instance. nr is the number of rows, nc is the number of columns nd is the number of nr x nc "sheets". The data argument can either be an array of length nr*nc*nd or nil. If it is nil the 3D array will be initialized with zeros, otherwise the passed array is used as initial values

func (*CMat3) At

func (m *CMat3) At(i, j, k int) complex128

At return the value at position (i, j, k)

func (*CMat3) Dims

func (m *CMat3) Dims() (int, int, int)

Dims returns the dimensions of the 3D array

func (*CMat3) Set

func (m *CMat3) Set(i, j, k int, v complex128)

Set sets the value at position (i, j, k)

type FFT1

type FFT1 struct {
	// contains filtered or unexported fields
}

FFT1 is a data type for 1D FFTs

func NewFFT1

func NewFFT1(size int) *FFT1

NewFFT1 creates a new type for FFT1. Size is the length of the array that will be Fourier Transformed

func (*FFT1) FFT

func (f *FFT1) FFT(data []float64) []complex128

FFT performs forward FFT. The length of the data array has to match the size passed when the type was initialized

func (*FFT1) Freq

func (f *FFT1) Freq(i int) float64

Freq return the frequency corresponding to the coefficient at index i. The spacing is assumed to be 1.0

func (*FFT1) IFFT

func (f *FFT1) IFFT(coeff []complex128) []float64

IFFT performs inverse FFT. The length of the passed slice has to be equal to the one returned by FFT (e.g. size/2+1, where size is the value passed on initialization to NewFFT1)

type FFT2

type FFT2 struct {
	// contains filtered or unexported fields
}

FFT2 is a data type for two dimensional Fourier Transforms

func NewFFT2

func NewFFT2(nr, nc int) *FFT2

NewFFT2 return a new FFT2. nr is the number of rows, and nc is the number of columns

func (*FFT2) ColTransform added in v1.0.1

func (f *FFT2) ColTransform(data []complex128, op GonumFT) []complex128

ColTransform performs in-place transform over columns

func (*FFT2) FFT

func (f *FFT2) FFT(data []complex128) []complex128

FFT performs forward FFT. Data is assumed to be flattened row-major (e.g. A(i, j) = data[i*nc + j] where A is the 2D matrix). Therefore, the length of the data array has to be nr*nc, where nr and nc is the values used on initialization in NewFFT2

func (*FFT2) Freq

func (f *FFT2) Freq(i int) []float64

Freq return the 2D frequency corresponding to index i in the array returned by FFT. The spacing is assumed to be 1.0

func (*FFT2) IFFT

func (f *FFT2) IFFT(coeff []complex128) []complex128

IFFT performs inverse Fourier Transform. The length of the passed slice has to match the one returned by FFT (e.g. nr*nc, where nr and nc are the values passed to NewFFT2)

func (*FFT2) RowTransform added in v1.0.1

func (f *FFT2) RowTransform(data []complex128, op GonumFT) []complex128

RowTransform performs inplace transform per row

type FFT2Par added in v1.0.1

type FFT2Par struct {
	Transformers []*FFT2
}

FFT2Par is a parallel version of the FFT2

func NewFFT2Par added in v1.0.1

func NewFFT2Par(nr, nc, nWork int) *FFT2Par

NewFFT2Par returns a new instance of the parallel FFT2. nr is the number of rows nc is the number of columns and nWork is the number of workers used to perform the FFTs. Note that both the number of rows and the number of columns has to be divisible by the number of workers

func (*FFT2Par) FFT added in v1.0.1

func (f *FFT2Par) FFT(data []complex128) []complex128

FFT performs forward FFT

func (*FFT2Par) Freq added in v1.0.1

func (f *FFT2Par) Freq(i int) []float64

Freq returns the frequency corresponding to index i in the array returned by FFT

func (*FFT2Par) IFFT added in v1.0.1

func (f *FFT2Par) IFFT(data []complex128) []complex128

IFFT performs backward FFT

type FFT3

type FFT3 struct {
	// contains filtered or unexported fields
}

FFT3 is a structure for performing 3D FFTs

func NewFFT3

func NewFFT3(nr, nc, nd int) *FFT3

NewFFT3 returns a new 3D Fourier transform object. nr is the number of rows, nc is the number of columns and nd is the number of nr x nc "sheets"

func (*FFT3) ColTransform added in v1.0.1

func (f *FFT3) ColTransform(data []complex128, op GonumFT) []complex128

ColTransform performs FFT over columns

func (*FFT3) DepthTransform added in v1.0.1

func (f *FFT3) DepthTransform(data []complex128, op GonumFT) []complex128

DepthTransform performs FFT over the "depth" of a 3D matrix

func (*FFT3) FFT

func (f *FFT3) FFT(data []complex128) []complex128

FFT performs forward fourier transform. The length of the passed array has to be equal to nr*nc*nd, where nr, nc and nd are the values passed to NewFFT3

func (*FFT3) Freq

func (f *FFT3) Freq(i int) []float64

Freq returns the frequency correpsondex to index i in the array returned by FFT

func (*FFT3) IFFT

func (f *FFT3) IFFT(data []complex128) []complex128

IFFT performs the inverse fourier transform. The length of the passed array has to match the one returned by FFT (e.g. nr*nc*nd)

func (*FFT3) RowTransform added in v1.0.1

func (f *FFT3) RowTransform(data []complex128, op GonumFT) []complex128

RowTransform performs FFT over rows

type FFT3Par added in v1.0.1

type FFT3Par struct {
	Transforms []*FFT3
}

FFT3Par is type used to perform three dimensional FFTs with multiple workers

func NewFFT3Par added in v1.0.1

func NewFFT3Par(nr, nc, nd, nWorkers int) *FFT3Par

NewFFT3Par returns a new instance of FFT3Par. nr is the number of rows, nc is the number of columns, nd is the number of "planes" and nWorkers is the number of workers. Note that both the number of rows and the number of columns has to be divisible by the number of workers

func (*FFT3Par) FFT added in v1.0.1

func (f *FFT3Par) FFT(data []complex128) []complex128

FFT performs forward fourier transform

func (*FFT3Par) Freq added in v1.0.1

func (f *FFT3Par) Freq(i int) []float64

Freq returns the frequency corresponding to the i-th item in the array returned by FFT

func (*FFT3Par) IFFT added in v1.0.1

func (f *FFT3Par) IFFT(data []complex128) []complex128

IFFT performs backward fourier transform

type GonumFT

type GonumFT func(dst []complex128, data []complex128) []complex128

GonumFT is a type definition of Gonum's Coefficients and Sequence

type Mat3

type Mat3 struct {
	Data []float64
	// contains filtered or unexported fields
}

Mat3 is a structure represents a 3D array with floats. It is the real variant of CMat3. When the size of the 3D array is (nr, nc, nd) the mapping from 3D indices to the flattened Data array is (i, j, k) -> k*nr*nc + i*nc + j

func NewMat3

func NewMat3(nr, nc, nd int, data []float64) *Mat3

NewMat3 returns a new instance of the Mat3 struct. nr is the number of rows, nc is the number of columns and nd is the number of nr x nc "sheets". data can either be an array of length nr*nc*nd or nil. If it is nil, the underlying data is initialized to zero, otherwise the passed data array is used

func (*Mat3) AsComplex

func (m *Mat3) AsComplex() *CMat3

AsComplex converts the matrix into a complex matrix with imaginary part set to zero

func (*Mat3) AsUint8

func (m *Mat3) AsUint8() []uint8

AsUint8 return the underlying slice as uint8. The data is scaled such that the largest value equals 255 and the smallest value equals 0

func (*Mat3) At

func (m *Mat3) At(i, j, k int) float64

At returns the value at position i

func (*Mat3) Dims

func (m *Mat3) Dims() (int, int, int)

Dims return the size of the matrix

func (*Mat3) Set

func (m *Mat3) Set(i, j, k int, v float64)

Set sets the a value at position i, j, k

type Mutable2

type Mutable2 interface {
	// At returns the (i, j) element
	At(i, j int) complex128

	// Set sets a new value for the element at (i, j)
	Set(i, j int, v complex128)

	// Dims return the size of the data
	Dims() (int, int)
}

Mutable2 is a generic interface for a type where elements can be accessed via the At method and altered via the Set method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL