FFT
- Package
- purescript-fft-js
- Repository
- jeslie0/purescript-fft-js
Functions to compute the Fast Fourier Transform of an array.
This module wraps the functionality of https://github.com/indutny/fft.js/ and makes it usable in PureScript, with a sprinkling of type safety.
There are examples of how to use this module in the tests directory. Essentially, you need to make a new FFT object, then pass it to the required functions.
fft.js provides different functions to take the Fourier Transform of both real and complex arrays. To separate these functions, we introduce the newtype wrappers ComplexArray and RealArray, to add semantic information to the type signature of the function.
A complex valued array is simply an interwoven array of the real and imaginary parts. It looks like: [re0, im0, re1, im1, ...].
#ComplexArray Source
newtype ComplexArrayNewtype wrapper for complex arrays. A complex array is equivalent to Array Number, where the values are of the form [re, im, re, im, ...].
Constructors
Instances
#makeFFT Source
makeFFT :: Int -> FFTConstruct a new FFT object. The input is the length of the array that will have a Fourier Transform taking of. It must be a power of 2, and be greater than 1. The size is the number of numbers used in the array. For a real valued array, this is just the length. For a complex array, this is the length of the array / 2.
#fromComplexArray Source
fromComplexArray :: ComplexArray -> RealArrayCreate an array consisting of the real parts of the complex numbers provided in the given array.
#createComplexArray Source
createComplexArray :: FFT -> ComplexArrayCreate a zero filled complex array.
#toComplexArray Source
toComplexArray :: FFT -> RealArray -> ComplexArrayCreate a complex array from a given real array.
#transform Source
transform :: FFT -> ComplexArray -> ComplexArrayCompute the Fast Fourier Transform of the given complex valued array.
#realTransform Source
realTransform :: FFT -> RealArray -> ComplexArrayCompute the Fast Fourier Transform of the given real valued array. This is faster than creating a complex array from a real one and taking the Fourier Transformation.
#inverseTransform Source
inverseTransform :: FFT -> ComplexArray -> ComplexArrayCompute the inverse Fourier transform of the given complex valued array.
#STComplexArray Source
newtype STComplexArray :: Region -> Typenewtype STComplexArray s
ST Newtype wrapper for complex arrays. A complex array is equivalent to STArray s Number, where the values are of the form [re, im, re, im, ...].
Constructors
#STRealArray Source
newtype STRealArray :: Region -> Typenewtype STRealArray s
Newtype wrapper for real arrays.
Constructors
STRealArray (STArray s Number)
#fromComplexArrayST Source
fromComplexArrayST :: forall s. FFT -> ComplexArray -> STRealArray s -> ST s UnitUpdate an array with the real parts of the complex numbers provided in the given array.
#toComplexArrayST Source
toComplexArrayST :: forall s. FFT -> RealArray -> STComplexArray s -> ST s UnitTurn the given mutable array into a complex valued mutable array, formed from the real valued array provided. Note - the mutable array must have size double that of the real valued array.
#transformST Source
transformST :: forall s. FFT -> ComplexArray -> STComplexArray s -> ST s UnitUpdate the given mutable array with the Fourier transform of the given complex valued array.
#realTransformST Source
realTransformST :: forall s. FFT -> RealArray -> STRealArray s -> ST s UnitUpdate the given mutable array with the fourier transform of the given real valued array.
#inverseTransformST Source
inverseTransformST :: forall s. FFT -> ComplexArray -> STComplexArray s -> ST s UnitUpdate the given mutable array with the Inverse Fourier transform of the given complex valued array.
#completeSpectrum Source
completeSpectrum :: forall s. FFT -> STComplexArray s -> ST s UnitAccording to the issue: https://github.com/indutny/fft.js/issues/10, the realTransform only fills the left half of the array with data. This function is then used to complete that. However, I find that the realTransform function gives the correct result and that I don't ever need to use this function.
Re-exports from FFT.Internal.Array
- Modules
- FFT
- FFT.
Complex - FFT.
Internal. Array - FFT.
Real