Commits

Aleksey Khudyakov committed c39874e

Fix both DCT and IDCT

Implementation follow FFTW3 convention which multiply definition
from wikipedia by two

Comments (0)

Files changed (2)

Statistics/Transform.hs

   where
     interleaved = G.backpermute xs $ G.enumFromThenTo 0 2 (len-2) G.++
                                      G.enumFromThenTo (len-1) (len-3) 1
-    weights = G.cons 1 . G.generate (len-1) $ \x ->
+    weights = G.cons 2 . G.generate (len-1) $ \x ->
               2 * exp ((0:+(-1))*fi (x+1)*pi/(2*n))
       where n = fi len
     len = G.length xs
     interleave z | even z    = vals `G.unsafeIndex` halve z
                  | otherwise = vals `G.unsafeIndex` (len - halve z - 1)
     vals = G.map realPart . ifft $ G.zipWith (*) weights xs
-    weights = G.generate len $ \x -> n * exp ((0:+1)*fi x*pi/(2*n))
+    weights 
+      = G.cons n
+      $ G.generate (len - 1) $ \x -> 2 * n * exp ((0:+1) * fi (x+1) * pi/(2*n))
       where n = fi len
     len = G.length xs
 

tests/Tests/Transform.hs

         , testProperty "ifft . fft = id"  (t_fftInverse $ ifft . fft)
         , testProperty "fft . ifft = id"  (t_fftInverse $ fft . ifft)
         , testProperty "idct . dct = id [up to scale]"
-            (t_fftInverse (\v -> U.map (/ fromIntegral (U.length v)) $ idct $ dct v))
+            (t_fftInverse (\v -> U.map (/ (2 * fromIntegral (U.length v))) $ idct $ dct v))
         , testProperty "dct . idct = id [up to scale]"
-            (t_fftInverse (\v -> U.map (/ fromIntegral (U.length v)) $ idct $ dct v))
+            (t_fftInverse (\v -> U.map (/ (2 * fromIntegral (U.length v))) $ idct $ dct v))
           -- Exact small size DCT
           -- 2
         , testDCT [1,0] $ map (*2) [1, cos (pi/4)   ]