plotToCsv :: Real a => String -> [a] -> IO ()
plotToCsv name graph = 
    writeFile (name ++ ".csv") $ 
        unlines $ map (\(x, y) -> concat [show x, ",", show y]) $ 
                      points $ map realToDouble graph
  where
    
    -- Generate (x,y) points from a signal
    points :: [Double] -> [(Double, Double)] 
    points samples = zip
                -- x coodinates  
                (map (\x -> fromIntegral x * 
                                (fromIntegral samplingTime / 
                                (fromIntegral $ length samples))
                     )  [0..]) 
                 -- y coordinates
                 samples

    realToDouble :: (Real a) => a -> Double
    realToDouble = fromRational . toRational
plotToCsv :: Real a => String -> [a] -> IO ()
plotToCsv name graph = 
    writeFile (name ++ ".csv") $ 
        unlines $ map (\(x, y) -> concat [show x, ",", show y]) $ 
                      points $ map realToDouble graph
  where
    
    -- Generate (x,y) points from a signal
    points :: [Double] -> [(Double, Double)] 
    points samples = zip
                -- x coodinates  
                (map (\x -> fromIntegral x * 
                                (fromIntegral samplingTime / 
                                (fromIntegral $ length samples))
                     )  [0..]) 
                 -- y coordinates
                 samples

    realToDouble :: (Real a) => a -> Double
    realToDouble = fromRational . toRational
plotToCsv name graph = 
    writeFile (name ++ ".csv") $ 
        unlines $ map (\(x, y) -> concat [show x, ",", show y]) $ 
                      points $ map realToDouble graph
  where
    
    -- Generate (x,y) points from a signal
    points :: [Double] -> [(Double, Double)] 
    points samples = zip
                -- x coodinates  
                (map (\x -> fromIntegral x * 
                                (fromIntegral samplingTime / 
                                (fromIntegral $ length samples))
                     )  [0..]) 
                 -- y coordinates
                 samples

    realToDouble :: (Real a) => a -> Double
    realToDouble = fromRational . toRational