module Bode (bodeplot) where -- TODO: make proper bode plots. import Graphics.Gnuplot.Simple import Data.Complex -- Uses Gnuplot "set" command to set any options not directly -- supported by the wrapper. See also -- http://en.wikipedia.org/wiki/File:Bode_plot_template.pdf logAttrib = [ XLabel "Freqency (Hz)", -- LineStyle 1 [LineTitle "foobar"], Custom "xrange" ["[20:20000]"], Custom "grid" [], Custom "logscale" ["x", "10"], Custom "logscale" ["y", "10"]] -- Standard scale for audio plots. 4 decades at 5Hz -> 50kHz. logScale low high n = map e [0..n] where e i = low * (high / low) ** (i / n) bodeplot fn = plotFunc logAttrib audioScale (amplitude fn) where amplitude fn = \f -> magnitude $ fn (0 :+ 2 * pi * f) audioScale = logScale 20 20000 1000