- メインページ
- モジュール
- ネームスペース
- データ構造
- ファイル

- ファイル一覧
- グローバル

iir.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28
33
34 #ifndef __INCLUDE_FILTER_IIR_FILTER_H__
35 #define __INCLUDE_FILTER_IIR_FILTER_H__
36
37
38 #ifndef __INCLUDE_MIST_H__
39 #include "../mist.h"
40 #endif
41
42 #ifndef __INCLUDE_MIST_TYPE_TRAIT_H__
43 #include "../config/type_trait.h"
44 #endif
45
46 #include <cmath>
47 #include <functional>
48
49 // mist名前空間の始まり
50 _MIST_BEGIN
51
52
53 namespace __iir_filter__
54 {
55
56 template<class T, class Allocator>
57 void iir(
58 const array1<T, Allocator>& in,
59 array1<T, Allocator>& out,
60 int order,
61 const array1<T, Allocator>& a,
62 const array1<T, Allocator>& b)
63 {
64 array1<double> buf(order + 2, 0.0);
65
66 out.resize(in.size());
67
68 double output;
69 for(int n = 0; n < in.size(); n ++)
70 {
71 out[n] = output = b[0] * in[n] + buf[1];
72
73 for(int k = 1; k < order + 1; k ++)
74 {
75 buf[k] = (b[k] * in[n]) - (a[k] * output) + buf[k + 1];
76 }
77 }
78 }
79
80
81 template<class T, class Allocator>
82 void iir_cascade(
83 const array1<T, Allocator>& in,
84 array1<T, Allocator>& out,
85 int order,
86 int blocks,
87 const array2<T, Allocator>& a,
88 const array2<T, Allocator>& b)
89 {
90 array2<double> buf(blocks + 1, order + 2, 0.0);
91
92 out.resize(in.size());
93
94 double output;
95 for(int n = 0; n < in.size(); n ++)
96 {
97 buf(0, 0) = in[n];
98
99 for(int blk = 1; blk < blocks + 1; blk ++)
100 {
101 buf(blk, 0) = output = b(blk - 1, 0) * buf(blk - 1, 0) + buf(blk, 1);
102
103 for(int k = 1; k < order + 1; k ++)
104 {
105 buf(blk, k) = (b(blk - 1, k) * buf(blk - 1, 0)) - (a(blk - 1, k) * output) + buf(blk, k + 1);
106 }
107 }
108
109 out[n] = buf(blocks, 0);
110 }
111 }
112
113 }
114
115
116 // mist名前空間の終わり
117 _MIST_END
118
119 #endif // __INCLUDE_FILTER_IIR_FILTER_H__
120