OpenCores
URL https://opencores.org/ocsvn/sciir/sciir/trunk

Subversion Repositories sciir

[/] [sciir/] [trunk/] [SystemC/] [tfi/] [IIR_TFI.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ahmed.shah
/*
2
 * This is a semi-behavioral/structural description for digital IIR filter
3
 * Direct-Form II structure
4
 * Direct-Form I Transposed structure using Matlab notation
5
 *
6
 *                       \Sigma_{i=0}^{N} b[i]z^{-1}
7
 * H(z) = ---------------------------------
8
 *                      1 - \Sigma_{i=1}^{N} a[i]z^{-1}
9
 *
10
 * H(z):        transfer function
11
 * b:           feed-forward coefficients
12
 * a:           feed-back coefficients
13
 * N:           filter order
14
 *
15
 * U. Meyer-Baese, "Digital signal processing with field programmable gate arrays", Springer Verlag, 2004
16
 */
17
 
18
#define order 3
19
#define orderFF order+1
20
#define orderFB orderFF-1
21
 
22
template<class T>
23
SC_MODULE(IIR_TFI)
24
{
25
        /* Entity */
26
        sc_in<bool> CLR;                                                                // Asynchronous active high reset
27
        sc_in<bool> CLK;                                                                // Rising edge clock
28
        sc_in<T>        iIIR;                                                           // IIR input
29
        sc_out<T>       oIIR;                                                           // IIR ouput
30
 
31
        /* Internal Signals Declaration */
32
        sc_signal<T> oMultiplierFF[orderFF];                    // FF multipliers output
33
        sc_signal<T> oAdderFF[orderFF];                                 // FF adders output
34
        sc_signal<T> oDelayFF[orderFF];                                 // FF delays output
35
        sc_signal<T> oMultiplierFB[orderFB];                    // FB multipliers output
36
        sc_signal<T> oAdderFB[orderFB];                                 // FB adders output
37
        sc_signal<T> oDelayFB[orderFB];                                 // FB delays output
38
        sc_signal<T> tIIR;                                                              // Temporary intput
39
 
40
        /* Constructor Architecture */
41
        SC_HAS_PROCESS(IIR_TFI);
42
 
43
        IIR_TFI(sc_module_name name, T* _b, T* _a)  :
44
                sc_module(name),                                                        // Arbitrary module name
45
                b(_b),                                                                          // Feed-Forward Coefficients
46
                a(_a)                                                                           // Feed-Back Coefficients
47
        {
48
                SC_METHOD(multipliers);
49
                        sensitive << tIIR;
50
 
51
                SC_METHOD(adders);
52
                        for (int i = 0; i < orderFF; i++)
53
                        {
54
                                sensitive << oMultiplierFF[i];
55
                                sensitive << oDelayFF[i];
56
                        }
57
 
58
                SC_METHOD(delays);
59
                        sensitive << CLK.pos();
60
 
61
                SC_METHOD(input);
62
                        sensitive << iIIR << oDelayFB[orderFB-1];
63
        }
64
 
65
        void multipliers()
66
        {
67
                /* Feed-Forward */
68
                for (int i = 0; i < orderFF; i++)
69
                {
70
                        oMultiplierFF[i] = tIIR * b[i];
71
                }
72
 
73
                /* Feed-Back */
74
                for (int i = 0; i < orderFB; i++)
75
                {
76
                        oMultiplierFB[i] = tIIR * a[orderFB-1-i];
77
                }
78
        }
79
 
80
        void adders()
81
        {
82
                /* Feed-Forward */
83
                for (int i = 0; i < orderFF; i++)
84
                {
85
                        if (i < (orderFF-1))
86
                        {
87
                                oAdderFF[i] = oMultiplierFF[i] + oDelayFF[i];
88
                        }
89
                        else
90
                        {
91
                                oAdderFF[i] = oMultiplierFF[i];
92
                        }
93
                }
94
 
95
                /* Feed-Back */
96
                for (int i = 0; i < orderFB; i++)
97
                {
98
                        if (i == 0)
99
                        {
100
                                oAdderFB[i] = oMultiplierFB[i];
101
                        }
102
                        else
103
                        {
104
                                oAdderFB[i] = oMultiplierFB[i] + oDelayFB[i-1];
105
                        }
106
                }
107
        }
108
 
109
        void delays()
110
        {
111
                /* Feed-Forward */
112
                for (int i = 0; i < orderFF-1; i++)
113
                {
114
                        oDelayFF[i] = oAdderFF[i+1];
115
                }
116
 
117
                /* Feed-Back */
118
                for (int i = 0; i < orderFB; i++)
119
                {
120
                        oDelayFB[i] = oAdderFB[i];
121
                }
122
        }
123
 
124
        void input()
125
        {
126
                tIIR.write(iIIR.read() + oDelayFB[orderFB-1]);
127
        }
128
 
129
        /* Deconstructor */
130
        ~IIR_TFI()
131
        {
132
        }
133
 
134
        T *b, *a;
135
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.