
ForSyDe.Shallow.FilterLib  Portability  portable  Stability  experimental  Maintainer  forsydedev@ict.kth.se 





Description 
This is the filter library for ForSyDe heterogeneous MoCs  CTMoC, SRMoC,
and UntimedMoC.
The filters at CTMoC are based on the filters implemented at SRMoC and UntimedMoC,
which means a signal in CTMoC is always digitalized by a A/D converter, processed by
digital filters at SR or Untimed domain, and converted back into a CT domain signal by
a D/A converter. A CTfilter is composed of one A/D converter, one digital filter, and
one D/A converter.
The implementation of the filters at untimed and synchronous domains follows the
way in a paper /An introduction to Haskell with applications to digital signal processing,
David M. Goblirsch, in Proceedings of the 1994 ACM symposium on Applied computing./,
where the details of the FIR/IIR, AR, and ARMA filters are introduced. The ARMA filter
is the kernel part of our general linear filter zLinearFilter in Zdomain at SR/Untimed
MoC, and is also the kernel digital filter for the linear filter sLinearFilter in
Sdomain at CTMoC.


Synopsis 




FIR filter



:: Num a   => [a]  Coefficients of the FIR filter
 > Signal a  Input signal
 > Signal a  Output signal
 The FIR filter. Let '[x_n]' denote the input signal, '[y_n]' denote the ouput
signal, and '[h_n]' the impulse response of the filter. Suppose the length of
the impulse responses is M samples. The formula for '[y_n]' is
$sum_{k=0}^{M1} h_k*x_{nk}$.



AR and ARMA filter trim



:: (Num a, Fractional a)   => [a]  Coefficients of the AR filter.
 > a  The gain
 > Signal a  Input signal
 > Signal a  Output signal
 The autoregressive filter is the simplest IIR filter. It is characterized
by a list of numbers '[a_1,a_2,...,a_M]' called the autoregression
coefficients and a single number b called the gain. M is the order of
the filter. Let '[x_n]' denote the input signal, '[y_n]' denote the ouput
signal. The formula for '[y_n]' is $sum_{k=1}^M {a_k*y_{nk}+b*x_n}$.
Although it is an IIR filter, here we only get the same length of ouput
signal as the input signal.




:: (Num a, Fractional a)   => [a]  Coefficients of the FIR filter
 > [a]  Coefficients of the AR filter.
 > Signal a  Input signal
 > Signal a  Output signal
 The ARMA filter combines the FIR and AR filters. Let '[x_n]' denote the
input signal, '[y_n]' denote the ouput signal. The formula for '[y_n]' is
$sum_{k=1}^M {a_k*y_{nk}+b*x_n} + sum_{i=0}^{N1} b_i*x_{ni}$. The ARMA
filter can be defined as the composition of an FIR filter having the impulse
reponse '[b_0,b_1,...,b_N1]' and an AR filter having the regression
coefficients '[a_1,a_2,...,a_M]' and a gain of '1'. Although it is an IIR
filter, here we only get the same length of ouput signal as the input signal.



The solver mode



The solver mode.
 Constructors  S2Z  Tustin tranfer from sdomain to zdomain
 RK4  Runge Kutta 4 with fixed simulation steps

 Instances  


The general linear filter in Sdomain



:: (Num a, Fractional a)   => SolverMode  Specify the solver mode
 > Rational  Fixed simulation interval
 > [a]  Coefficients of the polynomial numerator in sdomain
 > [a]  Coefficients of the polynomial denominator in sdomain
 > Signal (SubsigCT a)  Input CTsignal
 > Signal (SubsigCT a)  Output CTsignal
 The general linear filter in Sdomain at CTMoC. As the kernel
implementation is in Zdomain, the smapling rate should be specified.
It is used on the Stransformation with the following forms, with
coefficients for the descending powers of s and m < n.
b_0*s^m + b_1*s^m1 + ... + b_m1*s^1 + b_m*s^0
H(s) =  (Eq 1)
a_0*s^n + a_1*s^n1 + ... + a_n1*s^1 + a_n*s^0
If we multiply both the numerator and the denominator with s^n, we get
another equivelent canonical form
b_0*s^mn + b_1*s^mn1 + ... + b_m1*s^1n + b_m*s^n
H(s) =  (Eq 2)
a_0*s^0 + a_1*s^1 + ... + a_n1*s^1n + a_n*s^n
To instantiate a filter, with sampling interval 'T ', we use
filter1 = sLinearFilter T [1] [2,1]
to get a filter with the transfer function
1
H(s) = 
2*s + 1
and
filter2 = sLinearFilter T [2,1] [1,2,2]
to get another filter with the transfer function
2*s +1
H(s) = 
s^2 + 2*s + 2
There are two solver modes, S2Z and RK4.
Caused by the precision problem, the time interval in CT uses Rational data
type and the digital data types in all the domains are Double.



The general linear filter in Zdomain



The general linear filter in Zdomain.


s2z domain coefficient tranformation



:: (Num a, Fractional a)   => Rational  Sampling rate in Zdomain
 > [a]  Coefficients of the polynomial numerator in sdomain
 > [a]  Coefficients of the polynomial denominator in sdomain
 > ([a], [a])  Tuple of the numerator and denominator
coefficients in Zdomain
 s2z domain coefficient tranformation with a specified sampling rate.
The Tustin transformation is used for the transfer, with
2(z  1)
s =  (Eq 3)
T(z + 1)
in which, T is the sampling interval.



The Zdomain to ARMA coefficient tranformation



:: (Num a, Fractional a)   => ([a], [a])  Coefficients in Zdomain
 > ([a], [a])  Coefficients of the ARMA filter
 The Zdomain to ARMA coefficient tranformation. It is used on the
Ztransfer function
b_0*z^mn + b_1*z^mn1 + ... + b_m1*z^1n + b_m*z^n
H(z) =  (Eq 4)
a_0*z^0 + a_1*z^1 + ... + a_n1*z^1n + a_n*z^n
which is normalized as
b_0/a_0*z^mn + b_1/a_0*z^mn1 + ... + b_m/a_0*z^n
H(z) =  (Eq 5)
1 + a_1/a_0*z^1 + ... + a_n1/a_0*z^1n + a_n/a_0*z^n
The implementation coudl be
y(k) = b_0/a_0*x_k+mn + b_1/a_0*x_k+mn1 + ... + b_m/a_0*x_kn
(Eq 6)
 a_1/a_0*y_k1  ...  a_n/a_0*y_kn
Then, we could get the coefficients of the ARMA filter.



Produced by Haddock version 2.1.0 