forsyde-shallow-3.4.0.0: ForSyDe's Haskell-embedded Domain Specific Language.

Copyright(c) ForSyDe Group KTH 2007-2008
LicenseBSD-style (see the file LICENSE)
Maintainerforsyde-dev@ict.kth.se
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

ForSyDe.Shallow.MoC.CT

Contents

Description

This is the ForSyDe library for continuous time MoC (CT-MoC). It is still experimental. Right now there are only constructors combCT, scaleCT, addCT, multCT and absCT.

The main idea is to represent continuous time signals as functions Real --> a with a being a numerical type. This allows us to represent a continuous time signal without loss of information because no sampling or ADC is required. The sampling occurs only when a signal is evaluated, for instance when it is plotted.

Thus, a signal is represented as a sequence of functions and intervals. For instance a signal

s = <(sin,[0,100])>

represents a sinus signal in the interval between 0 and 100. The signal

s2 = <(f1(x)=2x, [0,2]), (f2(x)=3+x,[2,4])>

defines a signal that is defined by function f1 in the interval [0,2] and by function f2 in the interval [2,4].

A process transforms the incoming functions into outgoing functions. The approach is described in more detail in the ANDRES deliverable D1.1a. Here we only briefly comment the main functions and constructors.

Synopsis

The signal data type

data SubsigCT a Source #

The type of a sub-signal of a continuous signal. It consisits of the function and the interval on which the function is defined. The continuous time signal is then defined as a sequence of SubsigCT elements: Signal SubsigCT

Constructors

SubsigCT (Rational -> a, (Rational, Rational)) 
Instances
(Num a, Show a) => Show (SubsigCT a) Source # 
Instance details

Defined in ForSyDe.Shallow.MoC.CT

Methods

showsPrec :: Int -> SubsigCT a -> ShowS #

show :: SubsigCT a -> String #

showList :: [SubsigCT a] -> ShowS #

ctSignal :: [(Rational -> a, (Rational, Rational))] -> Signal (SubsigCT a) Source #

The function ctSignal creates a CT signal from a list of subsignals that are given by a function, an a time range.

*ForSyDe.Shallow.MoC.CT> ctsig1 = ctSignal [(liftCT sin, (0, 3.14)), (\t -> 1, (3.14, 6.28))]
*ForSyDe.Shallow.MoC.CT> :t ctsig1
ctsig1 :: Floating a => Signal (SubsigCT a)-- ctsig1 = ctSignal [(liftCT sin, (0, 3.14)), (\t -> 1, (3.14, 6.28))]

liftCT :: Fractional a => (a -> b) -> Rational -> b Source #

The function liftCT creates a CT-compliant function (using the Rationals as domain) from a normal mathematical function that uses a fractional (Double) as domain

timeStep :: Rational Source #

This constant gives the default time step for sampling and plotting. Its value is 10ns.

Primary process constructors

mapCT :: (a -> b) -> Signal (SubsigCT a) -> Signal (SubsigCT b) Source #

zipWithCT :: (a -> b -> c) -> Signal (SubsigCT a) -> Signal (SubsigCT b) -> Signal (SubsigCT c) Source #

combCT :: (a -> b) -> Signal (SubsigCT a) -> Signal (SubsigCT b) Source #

comb2CT :: (a -> b -> c) -> Signal (SubsigCT a) -> Signal (SubsigCT b) -> Signal (SubsigCT c) Source #

Derived process constructors

These constructors instantiate very useful processes. They could be defined in terms of the basic constructors but are typically defined in a more direct way for the sake of efficieny.

scaleCT Source #

Arguments

:: (Num a, Show a) 
=> a

The scaling factor

-> Signal (SubsigCT a)

The input signal

-> Signal (SubsigCT a)

The output signal of the process

scaleCT amplifies an input by a constant factor:

addCT Source #

Arguments

:: (Num a, Show a) 
=> Signal (SubsigCT a)

The first input signal

-> Signal (SubsigCT a)

The second input signal

-> Signal (SubsigCT a)

The output signal

addCT adds two input signals together.

multCT Source #

Arguments

:: (Num a, Show a) 
=> Signal (SubsigCT a)

The first input signal

-> Signal (SubsigCT a)

The second input signal

-> Signal (SubsigCT a)

The output signal

multCT multiplies two input signals together.

absCT Source #

Arguments

:: (Num a, Ord a, Show a) 
=> Signal (SubsigCT a)

The input signal

-> Signal (SubsigCT a)

The output signal

absCT takes the absolute value of a signal.

Convenient functions and processes

Several helper functions are available to obtain parts of a signal, the duration, the start time of a signal, and to generate a sine wave and constant signals.

sineWave Source #

Arguments

:: (Floating a, Show a) 
=> Rational

The frequency

-> (Rational, Rational)

The interval of the signal

-> Signal (SubsigCT a)

The generated signal

sineWave generates a sinus signal with the given frequency defined over a given period. The function is defined as f(x)=sin(2*pi*freq*x).

AD and DA converters

data DACMode Source #

For the digital-analog conversion we have two different possibilities which is determined by this data type DACMode.

Constructors

DAlinear

linear interpolation

DAhold

the last digital value is frozen

Instances
Eq DACMode Source # 
Instance details

Defined in ForSyDe.Shallow.MoC.CT

Methods

(==) :: DACMode -> DACMode -> Bool #

(/=) :: DACMode -> DACMode -> Bool #

Show DACMode Source # 
Instance details

Defined in ForSyDe.Shallow.MoC.CT

a2dConverter Source #

Arguments

:: (Num a, Show a) 
=> Rational

Sampling Period

-> Signal (SubsigCT a)

Input signal (continuous time)

-> Signal a

Output signal (untimed)

The process a2dConverter converts a continuous time signal to an untimed or synchronous signal. The first parameter gives the sampling period of the converter.

Note, that the process a2dConverter is an ideal component, i.e. there are no losses due to a limited resolution due to a fixed number of bits.

d2aConverter Source #

Arguments

:: (Fractional a, Show a) 
=> DACMode

Mode of conversion

-> Rational

Duration of input signal

-> Signal a

Input signal (untimed MoC)

-> Signal (SubsigCT a)

Output signal (continuous time MoC)

d2aConverter converts an untimes or synchronous signal into a continuous time signal. The process d2aConverter converts a signal of the digital domain into a continuous time signal. There are two modes, DAlinear, which makes a smooth transition between adjacent digital values and DAhold, where the analog value directly follows the digital value. This means that in DAhold-mode a staircase function remains a staircase function, while in DAlinear the staircase function would resemble at least partially a saw tooth-curve.

The resolution of the converter is given by the parameter timeStep.

Note, that the process d2aConverter is an ideal component, i.e. there are no losses due to a limited resolution due to a fixed number of bits.

Some helper functions

applyF1 :: (Num a, Num b, Show a, Show b) => ((Rational -> a) -> Rational -> b) -> Signal (SubsigCT a) -> Signal (SubsigCT b) Source #

applyF1 applies a function on a sub-signal, which means the function of the subsignal is transformed to another function:

applyF2 :: (Num a, Num b, Num c, Show a, Show b, Show c) => ((Rational -> a) -> (Rational -> b) -> Rational -> c) -> Signal (SubsigCT a) -> Signal (SubsigCT b) -> Signal (SubsigCT c) Source #

applyF2 works just like applyF1 but operates on two incoming signals.

applyG1 :: (Num b, Show b) => (a -> (Rational -> b) -> a) -> a -> Signal (SubsigCT b) -> a Source #

applyG1 is used to apply a next-state function. A very interesting question is, what should be an argument to the next-state function: the incoming function, defining the value of the input signal? or the incoming function and the incoming interval? or the value of the incoming signal at a particular point, e.g. at the left most point of the interval? To give the next-state function the interval itself as argument, would mean that the process becomes time variant process, i.e. its behaviour is dependent on the absolute time values. This is not a good thing to have! Another possibility may be to give a sub-signal that is relative to the current evaluation, i.e. the left most point is always 0. Would that make sense?

cutEq :: (Num a, Num b, Show a, Show b) => Signal (SubsigCT a) -> Signal (SubsigCT b) -> (Signal (SubsigCT a), Signal (SubsigCT b)) Source #

cutEq partitions the two signals such that the partitioning are identical in both result signals, but only up to the duration of the shorter of the two signals:

Sampling, printing and plotting

Several functions are available to display a signal in textual or graphics form. All displaying of signals is based on sampling and evaluation the signal at regular sampling points.

showParts does not evaluate the signal; it only shows how it is partitioned. Hence, it returns a sequence of intervals.

plot, plotCT and plotCT' can plot a signal or a list of signals in a graph. They use gnuplot for doing the actual work. They are in the IO monad because they write to the file system.

plot is defined in terms of plotCT but it uses the default sampling period timeStep and it can plot only one signal in a plot.

plotCT can plot a list of signals in the same plot. plotCT is defined in terms of plotCT' but uses default label names for the plot.

vcdGen writes the values of signals in Value Change Dump (VCD) format to a file. There are public domain wave viewers which understand this format and can display the signals.

plot Source #

Arguments

:: (Num a, Show a) 
=> Signal (SubsigCT a)

The signal to be plotted.

-> IO String

A reporting message.

plot plots one signal in a graph with the default sampling period of 1/200 of the duration of the signal.

plotCT Source #

Arguments

:: (Num a, Show a) 
=> Rational

The sampling period

-> [Signal (SubsigCT a)]

The list of signals to be ploted in the same graph

-> IO String

A messeage reporting what has been done.

plotCT plots a list of signals in the same graph. The sampling period has to be given as argument. In the graph default label names are used to identify the signals.

plotCT' Source #

Arguments

:: (Num a, Show a) 
=> Rational

Sampling period

-> [(Signal (SubsigCT a), String)]

A list of (signal,label) pairs. The signals are plotted and denoted by the corresponding labels in the plot.

-> IO String

A simple message to report completion

plotCT' is the work horse for plotting and the functions plot and plotCT use it with specialising arguments.

plotCT' plots all the signals in the list in one graph. If a label is given for a signal, this label appears in the graph. If the label string is "", a default label like "sig-1" is used.

In addition to displaying the graph on the screen, the following files are created in directory ./fig:

ct-moc-graph.eps
an eps file of the complete graph
ct-moc-graph.pdf
A pdf file of the complete graph
ct-moc-graph-latex.eps
included by ct-moc-graph-latex.tex
ct-moc-graph-latex.tex
This is the tex file that should be included by your latex document. It in turn includes the file ct-moc-graph-latex.eps. These two files have to be used together; the .eps file contains only the graphics, while the .tex file contains the labels and text.

showParts Source #

Arguments

:: (Num a, Show a) 
=> Signal (SubsigCT a)

The partitioned signal

-> [(Double, Double)]

The sequence of intervals

showParts allows to see how a signal is partitioned into sub-signals. It returns the sequence of intervals.

vcdGen Source #

Arguments

:: (Num a, Show a) 
=> Rational

Sampling period; defines for what time stamps the values are written.

-> [(Signal (SubsigCT a), String)]

A list of (signal,label) pairs. The signal values written and denoted by the corresponding labels.

-> IO String

A simple message to report completion

vcdGen dumps the values of a list of signal in VCD (Value Change Dump) format (IEEE Std 1364-2001), which is part of the Verilog standard (http://en.wikipedia.org/wiki/Value_change_dump). There are public domain tools to view VCD files. For instance, GTKWave (http://home.nc.rr.com/gtkwave/) is a popular viewer available for Windows and Linux.

The values are written to the file .figct-moc.vcd. If the file exists, it is overwritten. If the directory does not exist, it is created.