{-# LINE 1 "Numeric/FFT/Vector/Unnormalized.hsc" #-}
{- |
Raw, unnormalized versions of the transforms in @fftw@.

Note that the forwards and backwards transforms of this module are not actually
inverses.  For example, @run idft (run dft v) /= v@ in general.

For more information on the individual transforms, see
<http://www.fftw.org/fftw3_doc/What-FFTW-Really-Computes.html>.
-}
module Numeric.FFT.Vector.Unnormalized(
                    -- * Creating and executing 'Plan's
                    run,
                    plan,
                    execute,
                    -- * Complex-to-complex transforms
                    dft,
                    idft,
                    -- * Real-to-complex transforms
                    dftR2C,
                    dftC2R,
                    -- * Real-to-real transforms
                    -- $dct_size
                    -- ** Discrete cosine transforms
                    dct1,
                    dct2,
                    dct3,
                    dct4,
                    -- ** Discrete sine transforms
                    dst1,
                    dst2,
                    dst3,
                    dst4,
                    ) where

import Numeric.FFT.Vector.Base
import Foreign
import Foreign.C
import Data.Complex



-- | Whether the complex fft is forwards or backwards.
type CDirection = CInt

-- | The type of the cosine or sine transform.
type CKind = (Word32)
{-# LINE 47 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

foreign import ccall unsafe fftw_plan_dft_1d
    :: CInt -> Ptr (Complex Double) -> Ptr (Complex Double) -> CDirection
        -> CFlags -> IO (Ptr CPlan)

foreign import ccall unsafe fftw_plan_dft_r2c_1d
    :: CInt -> Ptr Double -> Ptr (Complex Double) -> CFlags -> IO (Ptr CPlan)

foreign import ccall unsafe fftw_plan_dft_c2r_1d
    :: CInt -> Ptr (Complex Double) -> Ptr Double -> CFlags -> IO (Ptr CPlan)

foreign import ccall unsafe fftw_plan_r2r_1d
    :: CInt -> Ptr Double -> Ptr Double -> CKind -> CFlags -> IO (Ptr CPlan)

dft1D :: CDirection -> Transform (Complex Double) (Complex Double)
dft1D :: CDirection -> Transform (Complex Double) (Complex Double)
dft1D CDirection
d = Transform {
            inputSize :: Int -> Int
inputSize = Int -> Int
forall a. a -> a
id,
            outputSize :: Int -> Int
outputSize = Int -> Int
forall a. a -> a
id,
            creationSizeFromInput :: Int -> Int
creationSizeFromInput = Int -> Int
forall a. a -> a
id,
            makePlan :: CDirection
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> CFlags
-> IO (Ptr CPlan)
makePlan = \CDirection
n Ptr (Complex Double)
a Ptr (Complex Double)
b -> IO (Ptr CPlan) -> IO (Ptr CPlan)
forall a. IO a -> IO a
withPlanner (IO (Ptr CPlan) -> IO (Ptr CPlan))
-> (CFlags -> IO (Ptr CPlan)) -> CFlags -> IO (Ptr CPlan)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CDirection
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> CDirection
-> CFlags
-> IO (Ptr CPlan)
fftw_plan_dft_1d CDirection
n Ptr (Complex Double)
a Ptr (Complex Double)
b CDirection
d,
            normalization :: Int
-> Plan (Complex Double) (Complex Double)
-> Plan (Complex Double) (Complex Double)
normalization = (Plan (Complex Double) (Complex Double)
 -> Plan (Complex Double) (Complex Double))
-> Int
-> Plan (Complex Double) (Complex Double)
-> Plan (Complex Double) (Complex Double)
forall a b. a -> b -> a
const Plan (Complex Double) (Complex Double)
-> Plan (Complex Double) (Complex Double)
forall a. a -> a
id
            }

-- | A forward discrete Fourier transform.  The output and input sizes are the same (@n@).
--
-- @y_k = sum_(j=0)^(n-1) x_j e^(-2pi i j k/n)@
dft :: Transform (Complex Double) (Complex Double)
dft :: Transform (Complex Double) (Complex Double)
dft = CDirection -> Transform (Complex Double) (Complex Double)
dft1D (-CDirection
1)
{-# LINE 75 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A backward discrete Fourier transform.  The output and input sizes are the same (@n@).
--
-- @y_k = sum_(j=0)^(n-1) x_j e^(2pi i j k/n)@
idft :: Transform (Complex Double) (Complex Double)
idft :: Transform (Complex Double) (Complex Double)
idft = CDirection -> Transform (Complex Double) (Complex Double)
dft1D (CDirection
1)
{-# LINE 81 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A forward discrete Fourier transform with real data.  If the input size is @n@,
-- the output size will be @n \`div\` 2 + 1@.
dftR2C :: Transform Double (Complex Double)
dftR2C :: Transform Double (Complex Double)
dftR2C = Transform {
            inputSize :: Int -> Int
inputSize = Int -> Int
forall a. a -> a
id,
            outputSize :: Int -> Int
outputSize = \Int
n -> Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1,
            creationSizeFromInput :: Int -> Int
creationSizeFromInput = Int -> Int
forall a. a -> a
id,
            makePlan :: CDirection
-> Ptr Double -> Ptr (Complex Double) -> CFlags -> IO (Ptr CPlan)
makePlan = \CDirection
n Ptr Double
a Ptr (Complex Double)
b -> IO (Ptr CPlan) -> IO (Ptr CPlan)
forall a. IO a -> IO a
withPlanner (IO (Ptr CPlan) -> IO (Ptr CPlan))
-> (CFlags -> IO (Ptr CPlan)) -> CFlags -> IO (Ptr CPlan)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CDirection
-> Ptr Double -> Ptr (Complex Double) -> CFlags -> IO (Ptr CPlan)
fftw_plan_dft_r2c_1d CDirection
n Ptr Double
a Ptr (Complex Double)
b,
            normalization :: Int -> Plan Double (Complex Double) -> Plan Double (Complex Double)
normalization = (Plan Double (Complex Double) -> Plan Double (Complex Double))
-> Int
-> Plan Double (Complex Double)
-> Plan Double (Complex Double)
forall a b. a -> b -> a
const Plan Double (Complex Double) -> Plan Double (Complex Double)
forall a. a -> a
id
        }

-- | A backward discrete Fourier transform which produces real data.
--
-- This 'Transform' behaves differently than the others:
--
--  - Calling @plan dftC2R n@ creates a 'Plan' whose /output/ size is @n@, and whose
--    /input/ size is @n \`div\` 2 + 1@.
--
--  - If @length v == n@, then @length (run dftC2R v) == 2*(n-1)@.
dftC2R :: Transform (Complex Double) Double
dftC2R :: Transform (Complex Double) Double
dftC2R = Transform {
            inputSize :: Int -> Int
inputSize = \Int
n -> Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1,
            outputSize :: Int -> Int
outputSize = Int -> Int
forall a. a -> a
id,
            creationSizeFromInput :: Int -> Int
creationSizeFromInput = \Int
n -> Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1),
            makePlan :: CDirection
-> Ptr (Complex Double) -> Ptr Double -> CFlags -> IO (Ptr CPlan)
makePlan = \CDirection
n Ptr (Complex Double)
a Ptr Double
b -> IO (Ptr CPlan) -> IO (Ptr CPlan)
forall a. IO a -> IO a
withPlanner (IO (Ptr CPlan) -> IO (Ptr CPlan))
-> (CFlags -> IO (Ptr CPlan)) -> CFlags -> IO (Ptr CPlan)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CDirection
-> Ptr (Complex Double) -> Ptr Double -> CFlags -> IO (Ptr CPlan)
fftw_plan_dft_c2r_1d CDirection
n Ptr (Complex Double)
a Ptr Double
b,
            normalization :: Int -> Plan (Complex Double) Double -> Plan (Complex Double) Double
normalization = (Plan (Complex Double) Double -> Plan (Complex Double) Double)
-> Int
-> Plan (Complex Double) Double
-> Plan (Complex Double) Double
forall a b. a -> b -> a
const Plan (Complex Double) Double -> Plan (Complex Double) Double
forall a. a -> a
id
        }


r2rTransform :: CKind -> Transform Double Double
r2rTransform :: CKind -> Transform Double Double
r2rTransform CKind
kind = Transform {
                    inputSize :: Int -> Int
inputSize = Int -> Int
forall a. a -> a
id,
                    outputSize :: Int -> Int
outputSize = Int -> Int
forall a. a -> a
id,
                    creationSizeFromInput :: Int -> Int
creationSizeFromInput = Int -> Int
forall a. a -> a
id,
                    makePlan :: CDirection -> Ptr Double -> Ptr Double -> CFlags -> IO (Ptr CPlan)
makePlan = \CDirection
n Ptr Double
a Ptr Double
b -> IO (Ptr CPlan) -> IO (Ptr CPlan)
forall a. IO a -> IO a
withPlanner (IO (Ptr CPlan) -> IO (Ptr CPlan))
-> (CFlags -> IO (Ptr CPlan)) -> CFlags -> IO (Ptr CPlan)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CDirection
-> Ptr Double -> Ptr Double -> CKind -> CFlags -> IO (Ptr CPlan)
fftw_plan_r2r_1d CDirection
n Ptr Double
a Ptr Double
b CKind
kind,
                    normalization :: Int -> Plan Double Double -> Plan Double Double
normalization = (Plan Double Double -> Plan Double Double)
-> Int -> Plan Double Double -> Plan Double Double
forall a b. a -> b -> a
const Plan Double Double -> Plan Double Double
forall a. a -> a
id
                }

-- $dct_size
-- The real-even (DCT) and real-odd (DST) transforms.  The input and output sizes
-- are the same (@n@).

-- | A type-1 discrete cosine transform.
--
-- @y_k = x_0 + (-1)^k x_(n-1) + 2 sum_(j=1)^(n-2) x_j cos(pi j k\/(n-1))@
dct1 :: Transform Double Double
dct1 :: Transform Double Double
dct1 = CKind -> Transform Double Double
r2rTransform (CKind
3)
{-# LINE 129 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-2 discrete cosine transform.
--
-- @y_k = 2 sum_(j=0)^(n-1) x_j cos(pi(j+1\/2)k\/n)@
dct2 :: Transform Double Double
dct2 :: Transform Double Double
dct2 = CKind -> Transform Double Double
r2rTransform (CKind
5)
{-# LINE 135 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-3 discrete cosine transform.
--
-- @y_k = x_0 + 2 sum_(j=1)^(n-1) x_j cos(pi j(k+1\/2)\/n)@
dct3 :: Transform Double Double
dct3 :: Transform Double Double
dct3 = CKind -> Transform Double Double
r2rTransform (CKind
4)
{-# LINE 141 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-4 discrete cosine transform.
--
-- @y_k = 2 sum_(j=0)^(n-1) x_j cos(pi(j+1\/2)(k+1\/2)\/n)@
dct4 :: Transform Double Double
dct4 :: Transform Double Double
dct4 = CKind -> Transform Double Double
r2rTransform (CKind
6)
{-# LINE 147 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-1 discrete sine transform.
--
-- @y_k = 2 sum_(j=0)^(n-1) x_j sin(pi(j+1)(k+1)\/(n+1))@
dst1 :: Transform Double Double
dst1 :: Transform Double Double
dst1 = CKind -> Transform Double Double
r2rTransform (CKind
7)
{-# LINE 153 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-2 discrete sine transform.
--
-- @y_k = 2 sum_(j=0)^(n-1) x_j sin(pi(j+1\/2)(k+1)\/n)@
dst2 :: Transform Double Double
dst2 :: Transform Double Double
dst2 = CKind -> Transform Double Double
r2rTransform (CKind
9)
{-# LINE 159 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-3 discrete sine transform.
--
-- @y_k = (-1)^k x_(n-1) + 2 sum_(j=0)^(n-2) x_j sin(pi(j+1)(k+1\/2)/n)@
dst3 :: Transform Double Double
dst3 :: Transform Double Double
dst3 = CKind -> Transform Double Double
r2rTransform (CKind
8)
{-# LINE 165 "Numeric/FFT/Vector/Unnormalized.hsc" #-}

-- | A type-4 discrete sine transform.
--
-- @y_k = sum_(j=0)^(n-1) x_j sin(pi(j+1\/2)(k+1\/2)\/n)@
dst4 :: Transform Double Double
dst4 :: Transform Double Double
dst4 = CKind -> Transform Double Double
r2rTransform (CKind
10)
{-# LINE 171 "Numeric/FFT/Vector/Unnormalized.hsc" #-}