| Copyright | (c) ForSyDe Group KTH 2007-2008 |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | forsyde-dev@ict.kth.se |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell98 |
ForSyDe.Shallow.Utility.FilterLib
Contents
Description
This is the filter library for ForSyDe heterogeneous MoCs - CT-MoC, SR-MoC, and Untimed-MoC.
The filters at CT-MoC are based on the filters implemented at SR-MoC and Untimed-MoC, which means a signal in CT-MoC 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 CT-filter 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 Z-domain at SR/Untimed
MoC, and is also the kernel digital filter for the linear filter sLinearFilter in
S-domain at CT-MoC.
Synopsis
- firFilter :: Num a => [a] -> Signal a -> Signal a
- arFilterTrim :: (Num a, Fractional a) => [a] -> a -> Signal a -> Signal a
- armaFilterTrim :: (Num a, Fractional a) => [a] -> [a] -> Signal a -> Signal a
- data SolverMode
- sLinearFilter :: (Num a, Fractional a, Show a, Eq a) => SolverMode -> Rational -> [a] -> [a] -> Signal (SubsigCT a) -> Signal (SubsigCT a)
- zLinearFilter :: Fractional a => [a] -> [a] -> Signal a -> Signal a
- s2zCoef :: (Num a, Fractional a, Eq a) => Rational -> [a] -> [a] -> ([a], [a])
- h2ARMACoef :: (Num a, Fractional a) => ([a], [a]) -> ([a], [a])
FIR filter
AR and ARMA filter trim
Arguments
| :: (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_{n-k}+b*x_n}$.
Although it is an IIR filter, here we only get the same length of ouput
signal as the input signal.
Arguments
| :: (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_{n-k}+b*x_n} + sum_{i=0}^{N-1} b_i*x_{n-i}$. The ARMA filter can be defined as the composition of an FIR filter having the impulse reponse '[b_0,b_1,...,b_N-1]' 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
data SolverMode Source #
The solver mode.
Instances
| Eq SolverMode Source # | |
Defined in ForSyDe.Shallow.Utility.FilterLib | |
| Show SolverMode Source # | |
Defined in ForSyDe.Shallow.Utility.FilterLib Methods showsPrec :: Int -> SolverMode -> ShowS # show :: SolverMode -> String # showList :: [SolverMode] -> ShowS # | |
The general linear filter in S-domain
Arguments
| :: (Num a, Fractional a, Show a, Eq a) | |
| => SolverMode | Specify the solver mode |
| -> Rational | Fixed simulation interval |
| -> [a] | Coefficients of the polynomial numerator in s-domain |
| -> [a] | Coefficients of the polynomial denominator in s-domain |
| -> Signal (SubsigCT a) | Input CT-signal |
| -> Signal (SubsigCT a) | Output CT-signal |
The general linear filter in S-domain at CT-MoC. As the kernel
implementation is in Z-domain, the smapling rate should be specified.
It is used on the S-transformation with the following forms, with
coefficients for the descending powers of s and m < n.
b_0*s^m + b_1*s^m-1 + ... + b_m-1*s^1 + b_m*s^0
H(s) = ------------------------------------------------ (Eq 1)
a_0*s^n + a_1*s^n-1 + ... + a_n-1*s^1 + a_n*s^0If we multiply both the numerator and the denominator with s^-n, we get another equivelent canonical form
b_0*s^m-n + b_1*s^m-n-1 + ... + b_m-1*s^1-n + b_m*s^-n
H(s) = ----------------------------------------------------- (Eq 2)
a_0*s^0 + a_1*s^-1 + ... + a_n-1*s^1-n + a_n*s^-nTo 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 + 2There 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 Z-domain
zLinearFilter :: Fractional a => [a] -> [a] -> Signal a -> Signal a Source #
The general linear filter in Z-domain.
s2z domain coefficient tranformation
Arguments
| :: (Num a, Fractional a, Eq a) | |
| => Rational | Sampling rate in Z-domain |
| -> [a] | Coefficients of the polynomial numerator in s-domain |
| -> [a] | Coefficients of the polynomial denominator in s-domain |
| -> ([a], [a]) | Tuple of the numerator and denominator coefficients in Z-domain |
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 Z-domain to ARMA coefficient tranformation
Arguments
| :: (Num a, Fractional a) | |
| => ([a], [a]) | Coefficients in Z-domain |
| -> ([a], [a]) | Coefficients of the ARMA filter |
The Z-domain to ARMA coefficient tranformation. It is used on the Z-transfer function
b_0*z^m-n + b_1*z^m-n-1 + ... + b_m-1*z^1-n + b_m*z^-n
H(z) = ----------------------------------------------------- (Eq 4)
a_0*z^0 + a_1*z^-1 + ... + a_n-1*z^1-n + a_n*z^-nwhich is normalized as
b_0/a_0*z^m-n + b_1/a_0*z^m-n-1 + ... + b_m/a_0*z^-n
H(z) = ------------------------------------------------------- (Eq 5)
1 + a_1/a_0*z^-1 + ... + a_n-1/a_0*z^1-n + a_n/a_0*z^-nThe implementation coudl be
y(k) = b_0/a_0*x_k+m-n + b_1/a_0*x_k+m-n-1 + ... + b_m/a_0*x_k-n
(Eq 6)
- a_1/a_0*y_k-1 - ... - a_n/a_0*y_k-nThen, we could get the coefficients of the ARMA filter.