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

Subversion Repositories sciir

[/] [sciir/] [trunk/] [SystemC/] [tfii/] [IIR_TFII.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 I structure
4
 * Direct-Form II 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 orderFF 4
19
#define orderFB orderFF-1
20
 
21
template<class T>
22
SC_MODULE(IIR_TFII)
23
{
24
        /* Entity */
25
        sc_in<bool> CLR;                                                                // Asynchronous active high reset
26
        sc_in<bool> CLK;                                                                // Rising edge clock
27
        sc_in<T>        iIIR;                                                           // IIR input
28
        sc_out<T>       oIIR;                                                           // IIR ouput
29
 
30
        /* Internal Signals Declaration */
31
        sc_signal<T> oMultiplierFF[orderFF];                    // FF multipliers output
32
        sc_signal<T> oMultiplierFB[orderFF];                    // FB multipliers output
33
        sc_signal<T> oAdder[orderFF];                                   // Adders output
34
        sc_signal<T> oDelay[orderFB];                                   // Delays output
35
 
36
        /* Constructor Architecture */
37
        SC_HAS_PROCESS(IIR_TFII);
38
 
39
        IIR_TFII(sc_module_name name, T* _b, T* _a) :
40
                sc_module(name),                                                        // Arbitrary module name
41
                b(_b),                                                                          // Feed-Forward Coefficients
42
                a(_a)                                                                           // Feed-Back Coefficients
43
        {
44
                SC_METHOD(multipliers);
45
                        sensitive << iIIR << oAdder[0];
46
 
47
                SC_METHOD(adders);
48
                        for (int i = 0; i < orderFF; i++)
49
                        {
50
                                if (i < orderFB)
51
                                {
52
                                        sensitive << oMultiplierFF[i];
53
                                        sensitive << oMultiplierFB[i];
54
                                        sensitive << oDelay[i];
55
                                }
56
                                else
57
                                {
58
                                        sensitive << oMultiplierFF[i];
59
                                        sensitive << oMultiplierFB[i];
60
                                }
61
                        }
62
 
63
                SC_METHOD(delays);
64
                        sensitive << CLK.pos();
65
 
66
                SC_METHOD(output);
67
                        sensitive << CLK.pos();
68
        }
69
 
70
        void multipliers()
71
        {
72
                /* Feed-Forward */
73
                for (int i = 0; i < orderFF; i++)
74
                {
75
                        oMultiplierFF[i] = iIIR.read() * b[i];
76
                        cout << "FF MU [" << i << "]\t" << oMultiplierFF[i] << endl;
77
                }
78
 
79
                /* Feed-Back */
80
                for (int i = 0; i < orderFF; i++)
81
                {
82
                        if (i == 0)
83
                        {
84
                                oMultiplierFB[i] = 0;
85
                        }
86
                        else
87
                        {
88
                                oMultiplierFB[i] = oAdder[0] * a[i];
89
                        }
90
                }
91
        }
92
 
93
        void adders()
94
        {
95
                for (int i = 0; i < orderFF; i++)
96
                {
97
                        if (i < orderFB )
98
                        {
99
                                oAdder[i] = oMultiplierFF[i] + oMultiplierFB[i] + oDelay[i];
100
                        }
101
                        else
102
                        {
103
                                oAdder[i] = oMultiplierFF[i] + oMultiplierFB[i];
104
                        }
105
                }
106
        }
107
 
108
        void delays()
109
        {
110
                for (int i = 0; i < orderFB; i++)
111
                {
112
                        oDelay[i] = oAdder[i+1];
113
                }
114
        }
115
 
116
        void output()
117
        {
118
                oIIR.write(oAdder[0].read());
119
        }
120
 
121
        /* Deconstructor */
122
        ~IIR_TFII()
123
        {
124
        }
125
 
126
        T *a, *b;
127
};

powered by: WebSVN 2.1.0

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