~ubuntu-branches/ubuntu/trusty/haskell-hmatrix/trusty

« back to all changes in this revision

Viewing changes to lib/Numeric/GSL/Fourier.hs

  • Committer: Package Import Robot
  • Author(s): Joachim Breitner
  • Date: 2013-06-04 21:54:51 UTC
  • Revision ID: package-import@ubuntu.com-20130604215451-czlj384n2drupnon
Tags: upstream-0.14.1.0
ImportĀ upstreamĀ versionĀ 0.14.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# LANGUAGE ForeignFunctionInterface #-}
 
2
-----------------------------------------------------------------------------
 
3
{- |
 
4
Module      : Numeric.GSL.Fourier
 
5
Copyright   :  (c) Alberto Ruiz 2006
 
6
License     :  GPL-style
 
7
 
 
8
Maintainer  :  Alberto Ruiz (aruiz at um dot es)
 
9
Stability   :  provisional
 
10
Portability :  uses ffi
 
11
 
 
12
Fourier Transform.
 
13
 
 
14
<http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html#Fast-Fourier-Transforms>
 
15
 
 
16
-}
 
17
-----------------------------------------------------------------------------
 
18
module Numeric.GSL.Fourier (
 
19
    fft,
 
20
    ifft
 
21
) where
 
22
 
 
23
import Data.Packed.Internal
 
24
import Data.Complex
 
25
import Foreign.C.Types
 
26
import System.IO.Unsafe (unsafePerformIO)
 
27
 
 
28
genfft code v = unsafePerformIO $ do
 
29
    r <- createVector (dim v)
 
30
    app2 (c_fft code) vec v vec r "fft"
 
31
    return r
 
32
 
 
33
foreign import ccall unsafe "gsl-aux.h fft" c_fft ::  CInt -> TCVCV
 
34
 
 
35
 
 
36
{- | Fast 1D Fourier transform of a 'Vector' @(@'Complex' 'Double'@)@ using /gsl_fft_complex_forward/. It uses the same scaling conventions as GNU Octave.
 
37
 
 
38
@> fft ('fromList' [1,2,3,4])
 
39
vector (4) [10.0 :+ 0.0,(-2.0) :+ 2.0,(-2.0) :+ 0.0,(-2.0) :+ (-2.0)]@
 
40
 
 
41
-}
 
42
fft :: Vector (Complex Double) -> Vector (Complex Double)
 
43
fft = genfft 0
 
44
 
 
45
-- | The inverse of 'fft', using /gsl_fft_complex_inverse/.
 
46
ifft :: Vector (Complex Double) -> Vector (Complex Double)
 
47
ifft = genfft 1