Skip to content

Instantly share code, notes, and snippets.

@ethereal-engineer
Last active August 29, 2015 14:12
Show Gist options
  • Save ethereal-engineer/d06725aa18558bff6be6 to your computer and use it in GitHub Desktop.
Save ethereal-engineer/d06725aa18558bff6be6 to your computer and use it in GitHub Desktop.
-- Out of interest: square wave (a first attempt)
baseSquareMultiplier = 4 / pi
squareWaveComponent f t k = sin (2 * pi * ((2 * k) - 1) * f * t) / ((2 * k) - 1)
functionSum :: (Num a) => (a -> a) -> [a] -> a
functionSum _ [] = 0
functionSum f (x:xs) = (f x) + (functionSum f xs)
squareWaveSum h f t = baseSquareMultiplier * (functionSum (squareWaveComponent f t) h)
squareWavePlot h f times = zip times (map (squareWaveSum h f) times)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment