POV-Ray : Newsgroups : povray.off-topic : Code division multiplexing : Code division multiplexing Server Time
29 Sep 2024 11:21:45 EDT (-0400)
  Code division multiplexing  
From: Invisible
Date: 22 Apr 2009 11:26:47
Message: <49ef3737$1@news.povray.org>
I don't know why it works... but it does.

 >module CDM where
 >
 >encode :: [Int] -> [Int] -> [Int]
 >encode cs xs = do
 >  x <- xs
 >  c <- cs
 >  let y = if x == 1 then 1 else -1
 >  return (c*y)
 >
 >decode :: [Int] -> [Int] -> [Int]
 >decode cs [] = []
 >decode cs xs =
 >  let
 >    (xs0,xs1) = splitAt (length cs) xs
 >    y = sum (zipWith (*) cs xs0)
 >  in ((y `min` 1) `max` 0) : decode cs xs1

OK, so let's encode something:

   *CDM> encode [1,-1] [1, 0, 1]
   [1,-1,-1,1,1,-1]

   *CMD> decode [1,-1] [1,-1,-1,1,1,-1]
   [1,0,1]

Well that's nice. But now check this out:

   *CDM> let x1 = encode [1,1,1,1] [1,1,0,1]
   *CDM> let x2 = encode [1,-1,1,-1] [1,0,1,1]
   *CDM> let x3 = encode [1,1,-1,-1] [0,0,1,1]
   *CDM> let x4 = encode [1,-1,-1,1] [1,1,1,0]
   *CDM> x1
   [1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,1,1,1]
   *CDM> x2
   [1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,1,-1,1,-1]
   *CDM> x3
   [-1,-1,1,1,-1,-1,1,1,1,1,-1,-1,1,1,-1,-1]
   *CDM> x4
   [1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,-1,1,1,-1]
   *CDM> let y = foldl1 (zipWith (+)) [x1,x2,x3,x4]
   *CDM> y
   [2,-2,2,2,0,0,0,4,2,-2,-2,-2,2,2,2,-2]
   *CDM> decode [1,1,1,1] y
   [1,1,0,1]
   *CDM> decode [1,-1,1,-1] y
   [1,0,1,1]
   *CDM> decode [1,1,-1,-1] y
   [0,0,1,1]
   *CDM> decode [1,-1,-1,1] y
   [1,1,1,0]

Magic!


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.