Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/filter.cc @ 12700:9843b3b055e0 stable
Fix bug with initial conditions in filter (Bug #32741).
* filter.cc: Re-orient SI to column vector only when both SI and X are vectors.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 04 Jun 2011 07:15:42 -0700 |
parents | d02798e9eeae |
children | 7c8b50cd4fb4 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 // Based on Tony Richardson's filter.m. | |
24 // | |
5428 | 25 // Originally translated to C++ by KH (Kurt.Hornik@wu-wien.ac.at) |
2928 | 26 // with help from Fritz Leisch and Andreas Weingessel on Oct 20, 1994. |
27 // | |
28 // Rewritten to use templates to handle both real and complex cases by | |
29 // jwe, Wed Nov 1 19:15:29 1995. | |
30 | |
31 #ifdef HAVE_CONFIG_H | |
32 #include <config.h> | |
33 #endif | |
34 | |
4153 | 35 #include "quit.h" |
36 | |
2928 | 37 #include "defun-dld.h" |
38 #include "error.h" | |
39 #include "oct-obj.h" | |
40 | |
3109 | 41 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
42 extern MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
43 filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim); |
2928 | 44 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
45 extern MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
46 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
47 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
48 extern MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
49 filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
50 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
51 extern MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
52 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim); |
3107 | 53 #endif |
2928 | 54 |
55 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
56 MArray<T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
57 filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, MArray<T>& si, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
58 int dim = 0) |
2928 | 59 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
60 MArray<T> y; |
2928 | 61 |
5275 | 62 octave_idx_type a_len = a.length (); |
63 octave_idx_type b_len = b.length (); | |
2928 | 64 |
5275 | 65 octave_idx_type ab_len = a_len > b_len ? a_len : b_len; |
2928 | 66 |
12637
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
67 // FIXME: The two lines below should be unecessary because |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
68 // this template is called with a and b as column vectors |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
69 // already. However the a.resize line is currently (2011/04/26) |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
70 // necessary to stop bug #33164. |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
71 b.resize (dim_vector (ab_len, 1), 0.0); |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
72 if (a_len > 1) |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
73 a.resize (dim_vector (ab_len, 1), 0.0); |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
74 |
2928 | 75 T norm = a (0); |
76 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
77 if (norm == static_cast<T>(0.0)) |
2928 | 78 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
79 error ("filter: the first element of A must be non-zero"); |
2928 | 80 return y; |
81 } | |
82 | |
4844 | 83 dim_vector x_dims = x.dims (); |
5056 | 84 if (dim < 0 || dim > x_dims.length ()) |
4844 | 85 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
86 error ("filter: DIM must be a valid dimension"); |
4844 | 87 return y; |
88 } | |
89 | |
5275 | 90 octave_idx_type x_len = x_dims(dim); |
4844 | 91 |
92 dim_vector si_dims = si.dims (); | |
5275 | 93 octave_idx_type si_len = si_dims(0); |
4844 | 94 |
95 if (si_len != ab_len - 1) | |
96 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
97 error ("filter: first dimension of SI must be of length max (length (a), length (b)) - 1"); |
4844 | 98 return y; |
99 } | |
100 | |
5059 | 101 if (si_dims.length () != x_dims.length ()) |
4844 | 102 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
103 error ("filter: dimensionality of SI and X must agree"); |
4844 | 104 return y; |
105 } | |
106 | |
5275 | 107 octave_idx_type si_dim = 0; |
108 for (octave_idx_type i = 0; i < x_dims.length (); i++) | |
4844 | 109 { |
110 if (i == dim) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
111 continue; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
112 |
5055 | 113 if (x_dims(i) == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
114 continue; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
115 |
5059 | 116 if (si_dims(++si_dim) != x_dims(i)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
117 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
118 error ("filter: dimensionality of SI and X must agree"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
119 return y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
120 } |
4844 | 121 } |
2928 | 122 |
10241
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
123 if (x_len == 0) |
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
124 return x; |
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
125 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 if (norm != static_cast<T>(1.0)) |
4844 | 127 { |
128 a = a / norm; | |
129 b = b / norm; | |
130 } | |
2928 | 131 |
5056 | 132 if (a_len <= 1 && si_len <= 0) |
4844 | 133 return b(0) * x; |
134 | |
135 y.resize (x_dims, 0.0); | |
136 | |
137 int x_stride = 1; | |
138 for (int i = 0; i < dim; i++) | |
139 x_stride *= x_dims(i); | |
2928 | 140 |
5275 | 141 octave_idx_type x_num = x_dims.numel () / x_len; |
142 for (octave_idx_type num = 0; num < x_num; num++) | |
4844 | 143 { |
5275 | 144 octave_idx_type x_offset; |
4844 | 145 if (x_stride == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
146 x_offset = num * x_len; |
4844 | 147 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
148 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
149 octave_idx_type x_offset2 = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
150 x_offset = num; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
151 while (x_offset >= x_stride) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
152 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
153 x_offset -= x_stride; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
154 x_offset2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
155 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
156 x_offset += x_offset2 * x_stride * x_len; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
157 } |
5275 | 158 octave_idx_type si_offset = num * si_len; |
2928 | 159 |
4844 | 160 if (a_len > 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
161 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
162 T *py = y.fortran_vec (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
163 T *psi = si.fortran_vec (); |
5114 | 164 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
165 const T *pa = a.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
166 const T *pb = b.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
167 const T *px = x.data (); |
5114 | 168 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
169 psi += si_offset; |
5114 | 170 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
171 for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
172 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
173 py[idx] = psi[0] + pb[0] * px[idx]; |
5114 | 174 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
175 if (si_len > 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
176 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
177 for (octave_idx_type j = 0; j < si_len - 1; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
178 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
179 OCTAVE_QUIT; |
5114 | 180 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
181 psi[j] = psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
182 } |
5114 | 183 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
184 psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
185 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
186 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
187 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
188 OCTAVE_QUIT; |
5114 | 189 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
190 psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
191 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
192 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
193 } |
5114 | 194 else if (si_len > 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
195 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
196 T *py = y.fortran_vec (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
197 T *psi = si.fortran_vec (); |
5114 | 198 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
199 const T *pb = b.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
200 const T *px = x.data (); |
5114 | 201 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
202 psi += si_offset; |
5114 | 203 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
204 for (octave_idx_type i = 0, idx = x_offset; i < x_len; i++, idx += x_stride) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
205 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
206 py[idx] = psi[0] + pb[0] * px[idx]; |
4844 | 207 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
208 if (si_len > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
209 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
210 for (octave_idx_type j = 0; j < si_len - 1; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
211 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
212 OCTAVE_QUIT; |
4153 | 213 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
214 psi[j] = psi[j+1] + pb[j+1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
215 } |
4844 | 216 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
217 psi[si_len-1] = pb[si_len] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
218 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
219 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
220 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
221 OCTAVE_QUIT; |
4844 | 222 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
223 psi[0] = pb[1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
224 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
225 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
226 } |
2928 | 227 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
228 |
2928 | 229 return y; |
230 } | |
231 | |
3109 | 232 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
233 extern MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
234 filter (MArray<double>&, MArray<double>&, MArray<double>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
235 MArray<double>&, int dim); |
2928 | 236 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
237 extern MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
238 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
239 MArray<Complex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
240 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
241 extern MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
242 filter (MArray<float>&, MArray<float>&, MArray<float>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
243 MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
244 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
245 extern MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
246 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
247 MArray<FloatComplex>&, int dim); |
3107 | 248 #endif |
2928 | 249 |
250 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
251 MArray<T> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
252 filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, int dim = -1) |
2928 | 253 { |
5059 | 254 dim_vector x_dims = x.dims(); |
4844 | 255 |
256 if (dim < 0) | |
257 { | |
258 // Find first non-singleton dimension | |
5059 | 259 while (dim < x_dims.length () && x_dims(dim) <= 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
260 dim++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
261 |
4844 | 262 // All dimensions singleton, pick first dimension |
263 if (dim == x_dims.length ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
264 dim = 0; |
4844 | 265 } |
266 else | |
267 if (dim < 0 || dim > x_dims.length ()) | |
268 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
269 error ("filter: DIM must be a valid dimension"); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
270 return MArray<T> (); |
4844 | 271 } |
272 | |
5275 | 273 octave_idx_type a_len = a.length (); |
274 octave_idx_type b_len = b.length (); | |
2928 | 275 |
5275 | 276 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
4844 | 277 dim_vector si_dims = x.dims (); |
278 for (int i = dim; i > 0; i--) | |
5059 | 279 si_dims(i) = si_dims(i-1); |
280 si_dims(0) = si_len; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
281 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
282 MArray<T> si (si_dims, T (0.0)); |
2928 | 283 |
4844 | 284 return filter (b, a, x, si, dim); |
2928 | 285 } |
286 | |
3097 | 287 DEFUN_DLD (filter, args, nargout, |
3367 | 288 "-*- texinfo -*-\n\ |
10840 | 289 @deftypefn {Loadable Function} {y =} filter (@var{b}, @var{a}, @var{x})\n\ |
3367 | 290 @deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si})\n\ |
4844 | 291 @deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, [], @var{dim})\n\ |
292 @deftypefnx {Loadable Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si}, @var{dim})\n\ | |
3367 | 293 Return the solution to the following linear, time-invariant difference\n\ |
294 equation:\n\ | |
295 @tex\n\ | |
296 $$\n\ | |
297 \\sum_{k=0}^N a_{k+1} y_{n-k} = \\sum_{k=0}^M b_{k+1} x_{n-k}, \\qquad\n\ | |
298 1 \\le n \\le P\n\ | |
299 $$\n\ | |
300 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
301 @ifnottex\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
302 @c Set example in small font to prevent overfull line\n\ |
2928 | 303 \n\ |
3367 | 304 @smallexample\n\ |
10840 | 305 @group\n\ |
3367 | 306 N M\n\ |
307 SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k) for 1<=n<=length(x)\n\ | |
308 k=0 k=0\n\ | |
10840 | 309 @end group\n\ |
3367 | 310 @end smallexample\n\ |
10840 | 311 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
312 @end ifnottex\n\ |
2928 | 313 \n\ |
3367 | 314 @noindent\n\ |
315 where\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
316 @ifnottex\n\ |
3367 | 317 N=length(a)-1 and M=length(b)-1.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
318 @end ifnottex\n\ |
3367 | 319 @tex\n\ |
320 $a \\in \\Re^{N-1}$, $b \\in \\Re^{M-1}$, and $x \\in \\Re^P$.\n\ | |
321 @end tex\n\ | |
4844 | 322 over the first non-singleton dimension of @var{x} or over @var{dim} if\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
323 supplied. An equivalent form of this equation is:\n\ |
3367 | 324 @tex\n\ |
325 $$\n\ | |
326 y_n = -\\sum_{k=1}^N c_{k+1} y_{n-k} + \\sum_{k=0}^M d_{k+1} x_{n-k}, \\qquad\n\ | |
327 1 \\le n \\le P\n\ | |
328 $$\n\ | |
329 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
330 @ifnottex\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
331 @c Set example in small font to prevent overfull line\n\ |
2928 | 332 \n\ |
3367 | 333 @smallexample\n\ |
10840 | 334 @group\n\ |
3367 | 335 N M\n\ |
336 y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k) for 1<=n<=length(x)\n\ | |
337 k=1 k=0\n\ | |
10840 | 338 @end group\n\ |
3367 | 339 @end smallexample\n\ |
10840 | 340 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
341 @end ifnottex\n\ |
3367 | 342 \n\ |
343 @noindent\n\ | |
344 where\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
345 @ifnottex\n\ |
3367 | 346 c = a/a(1) and d = b/a(1).\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
347 @end ifnottex\n\ |
3367 | 348 @tex\n\ |
349 $c = a/a_1$ and $d = b/a_1$.\n\ | |
350 @end tex\n\ | |
351 \n\ | |
352 If the fourth argument @var{si} is provided, it is taken as the\n\ | |
353 initial state of the system and the final state is returned as\n\ | |
354 @var{sf}. The state vector is a column vector whose length is\n\ | |
355 equal to the length of the longest coefficient vector minus one.\n\ | |
356 If @var{si} is not supplied, the initial state vector is set to all\n\ | |
2928 | 357 zeros.\n\ |
358 \n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
359 In terms of the Z Transform, y is the result of passing the discrete-\n\ |
3367 | 360 time signal x through a system characterized by the following rational\n\ |
361 system function:\n\ | |
362 @tex\n\ | |
363 $$\n\ | |
364 H(z) = {\\displaystyle\\sum_{k=0}^M d_{k+1} z^{-k}\n\ | |
365 \\over 1 + \\displaystyle\\sum_{k+1}^N c_{k+1} z^{-k}}\n\ | |
366 $$\n\ | |
367 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
368 @ifnottex\n\ |
3367 | 369 \n\ |
370 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
371 @group\n\ |
3367 | 372 M\n\ |
373 SUM d(k+1) z^(-k)\n\ | |
374 k=0\n\ | |
375 H(z) = ----------------------\n\ | |
376 N\n\ | |
6476 | 377 1 + SUM c(k+1) z^(-k)\n\ |
3367 | 378 k=1\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
379 @end group\n\ |
3367 | 380 @end example\n\ |
10840 | 381 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
382 @end ifnottex\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
383 @seealso{filter2, fftfilt, freqz}\n\ |
3367 | 384 @end deftypefn") |
2928 | 385 { |
386 octave_value_list retval; | |
387 | |
388 int nargin = args.length (); | |
389 | |
4844 | 390 if (nargin < 3 || nargin > 5) |
2928 | 391 { |
5823 | 392 print_usage (); |
2928 | 393 return retval; |
394 } | |
395 | |
4844 | 396 const char *errmsg = "filter: arguments a and b must be vectors"; |
397 | |
398 int dim; | |
399 dim_vector x_dims = args(2).dims (); | |
2928 | 400 |
4844 | 401 if (nargin == 5) |
402 { | |
403 dim = args(4).nint_value() - 1; | |
404 if (dim < 0 || dim >= x_dims.length ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
405 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
406 error ("filter: DIM must be a valid dimension"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
407 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
408 } |
4844 | 409 } |
410 else | |
411 { | |
412 // Find first non-singleton dimension | |
413 dim = 0; | |
5059 | 414 while (dim < x_dims.length () && x_dims(dim) <= 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
415 dim++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
416 |
4844 | 417 // All dimensions singleton, pick first dimension |
418 if (dim == x_dims.length ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
419 dim = 0; |
4844 | 420 } |
2928 | 421 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
422 bool isfloat = (args(0).is_single_type () |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
423 || args(1).is_single_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
424 || args(2).is_single_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
425 || (nargin >= 4 && args(3).is_single_type ())); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
426 |
2928 | 427 if (args(0).is_complex_type () |
428 || args(1).is_complex_type () | |
429 || args(2).is_complex_type () | |
4844 | 430 || (nargin >= 4 && args(3).is_complex_type ())) |
2928 | 431 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
432 if (isfloat) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
433 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
434 FloatComplexColumnVector b (args(0).float_complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
435 FloatComplexColumnVector a (args(1).float_complex_vector_value ()); |
3088 | 436 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
437 FloatComplexNDArray x (args(2).float_complex_array_value ()); |
3088 | 438 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
439 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
440 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
441 FloatComplexNDArray si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
442 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
443 if (nargin == 3 || args(3).is_empty ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
444 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
445 octave_idx_type a_len = a.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
446 octave_idx_type b_len = b.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
447 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
448 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
449 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
450 dim_vector si_dims = x.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
451 for (int i = dim; i > 0; i--) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
452 si_dims(i) = si_dims(i-1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
453 si_dims(0) = si_len; |
3088 | 454 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
455 si.resize (si_dims, 0.0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
456 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
457 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
458 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
459 si = args(3).float_complex_array_value (); |
2928 | 460 |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
461 if (si.is_vector () && x.is_vector ()) |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
462 si = si.reshape (dim_vector (si.numel (), 1)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
463 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
464 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
465 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
466 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
467 FloatComplexNDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
468 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
469 if (nargout == 2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
470 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
471 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
472 retval(0) = y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
473 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
474 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
475 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
476 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
477 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
478 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
479 } |
2928 | 480 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
481 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
482 ComplexColumnVector b (args(0).complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
483 ComplexColumnVector a (args(1).complex_vector_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
484 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
485 ComplexNDArray x (args(2).complex_array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
486 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
487 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
488 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
489 ComplexNDArray si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
490 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
491 if (nargin == 3 || args(3).is_empty ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
492 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
493 octave_idx_type a_len = a.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
494 octave_idx_type b_len = b.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
495 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
496 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
497 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
498 dim_vector si_dims = x.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
499 for (int i = dim; i > 0; i--) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
500 si_dims(i) = si_dims(i-1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
501 si_dims(0) = si_len; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
502 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
503 si.resize (si_dims, 0.0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
504 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
505 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
506 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
507 si = args(3).complex_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
508 |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
509 if (si.is_vector () && x.is_vector ()) |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
510 si = si.reshape (dim_vector (si.numel (), 1)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
511 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
512 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
513 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
514 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
515 ComplexNDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
516 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
517 if (nargout == 2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
518 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
519 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
520 retval(0) = y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
521 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
522 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
523 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
524 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
525 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
526 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
527 } |
2928 | 528 } |
529 else | |
530 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
531 if (isfloat) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
532 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
533 FloatColumnVector b (args(0).float_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
534 FloatColumnVector a (args(1).float_vector_value ()); |
3088 | 535 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
536 FloatNDArray x (args(2).float_array_value ()); |
3088 | 537 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
538 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
539 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
540 FloatNDArray si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
541 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
542 if (nargin == 3 || args(3).is_empty ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
543 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
544 octave_idx_type a_len = a.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
545 octave_idx_type b_len = b.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
546 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
547 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
548 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
549 dim_vector si_dims = x.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
550 for (int i = dim; i > 0; i--) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
551 si_dims(i) = si_dims(i-1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
552 si_dims(0) = si_len; |
3088 | 553 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
554 si.resize (si_dims, 0.0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
555 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
556 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
557 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
558 si = args(3).float_array_value (); |
2928 | 559 |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
560 if (si.is_vector () && x.is_vector ()) |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
561 si = si.reshape (dim_vector (si.numel (), 1)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
562 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
563 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
564 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
565 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
566 FloatNDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
567 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
568 if (nargout == 2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
569 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
570 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
571 retval(0) = y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
572 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
573 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
574 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
575 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
576 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
577 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
578 } |
2928 | 579 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
580 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
581 ColumnVector b (args(0).vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
582 ColumnVector a (args(1).vector_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
583 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
584 NDArray x (args(2).array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
585 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
586 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
587 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
588 NDArray si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
589 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
590 if (nargin == 3 || args(3).is_empty ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
591 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
592 octave_idx_type a_len = a.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
593 octave_idx_type b_len = b.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
594 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
595 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
596 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
597 dim_vector si_dims = x.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
598 for (int i = dim; i > 0; i--) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
599 si_dims(i) = si_dims(i-1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
600 si_dims(0) = si_len; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
601 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
602 si.resize (si_dims, 0.0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
603 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
604 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
605 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
606 si = args(3).array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
607 |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
608 if (si.is_vector () && x.is_vector ()) |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
609 si = si.reshape (dim_vector (si.numel (), 1)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
610 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
611 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
612 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
613 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
614 NDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
615 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
616 if (nargout == 2) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
617 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
618 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
619 retval(0) = y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
620 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
621 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
622 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
623 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
624 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
625 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
626 } |
2928 | 627 } |
628 | |
629 return retval; | |
630 } | |
631 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
632 template MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
633 filter (MArray<double>&, MArray<double>&, MArray<double>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
634 MArray<double>&, int dim); |
2928 | 635 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
636 template MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
637 filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim); |
2928 | 638 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
639 template MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
640 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
641 MArray<Complex>&, int dim); |
2928 | 642 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
643 template MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
644 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim); |
2928 | 645 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
646 template MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
647 filter (MArray<float>&, MArray<float>&, MArray<float>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
648 MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
649 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
650 template MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
651 filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
652 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
653 template MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
654 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
655 MArray<FloatComplex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
656 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
657 template MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
658 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
659 |
2928 | 660 /* |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
661 %!shared a, b, x, r |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
662 %!test |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
663 %! a = [1 1]; |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
664 %! b = [1 1]; |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
665 %! x = zeros (1,10); x(1) = 1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
666 %! assert(filter(b, [1], x ), [1 1 0 0 0 0 0 0 0 0]); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
667 %! assert(filter(b, [1], x.'), [1 1 0 0 0 0 0 0 0 0].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
668 %! assert(filter(b.', [1], x ), [1 1 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
669 %! assert(filter(b.', [1], x.'), [1 1 0 0 0 0 0 0 0 0].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
670 %! assert(filter([1], a, x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
671 %! assert(filter([1], a, x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
672 %! assert(filter([1], a.', x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
673 %! assert(filter([1], a.', x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
674 %! assert(filter(b, a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
675 %! assert(filter(b.', a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
676 %! assert(filter(b, a.', x ), [1 0 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
677 %! assert(filter(b.', a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
678 %! assert(filter(b, a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
679 %! assert(filter(b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
680 %! assert(filter(b, a.', x.'), [1 0 0 0 0 0 0 0 0 0].'); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
681 %! assert(filter(b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].'); |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
682 %! |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
683 %!test |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
684 %! r = sqrt(1/2)*(1+i); |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
685 %! a = a*r; |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
686 %! b = b*r; |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
687 %! assert(filter(b, [1], x ), r*[1 1 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
688 %! assert(filter(b, [1], r*x ), r*r*[1 1 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
689 %! assert(filter(b, [1], x.' ), r*[1 1 0 0 0 0 0 0 0 0].' ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
690 %! assert(filter(b, a, x ), [1 0 0 0 0 0 0 0 0 0] ); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
691 %! assert(filter(b, a, r*x ), r*[1 0 0 0 0 0 0 0 0 0] ); |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
692 %! |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
693 %!shared a, b, x, y, so |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
694 %!test |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
695 %! a = [1,1]; b = [1,1]; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
696 %! x = zeros (1,10); x(1) = 1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
697 %! [y, so] = filter (b, [1], x, [-1]); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
698 %! assert(y, [0 1 0 0 0 0 0 0 0 0]); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
699 %! assert(so,0); |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
700 %! |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
701 %!test |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
702 %! x = zeros (10,3); x(1,1)=-1; x(1,2)=1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
703 %! y0 = zeros (10,3); y0(1:2,1)=-1; y0(1:2,2)=1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
704 %! y = filter (b, [1], x); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
705 %! assert(y,y0); |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
706 %! |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
707 %!test |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
708 %! a = [1,1]; b=[1,1]; |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
709 %! x = zeros (4,4,2); x(1,1:4,1) = +1; x(1,1:4,2) = -1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
710 %! y0 = zeros (4,4,2); y0(1:2,1:4,1) = +1; y0(1:2,1:4,2) = -1; |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
711 %! y = filter (b, [1], x); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
712 %! assert(y, y0); |
10247
edfceeab945a
Add test case for empty argument in filter()
Thomas Weber <thomas.weber.mail@gmail.com>
parents:
10241
diff
changeset
|
713 %! |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
714 %!assert(filter (1, ones(10,1)/10, []), []); |
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
715 %!assert(filter (1, ones(10,1)/10, zeros(0,10)), zeros(0,10)); |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
716 %!assert(filter (1, ones(10,1)/10, single (1:5)), repmat (single (10), 1, 5)); |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
717 %% Test using initial conditions |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
718 %!assert(filter([1, 1, 1], [1, 1], [1 2], [1, 1]), [2 2]); |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
719 %!assert(filter([1, 1, 1], [1, 1], [1 2], [1, 1]'), [2 2]); |
12566
3b0eb443c519
Fix orientation of initial conditions vector for filter (bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
720 %!assert(filter([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18]); |
12700
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
721 %!error (filter([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]')); |
9843b3b055e0
Fix bug with initial conditions in filter (Bug #32741).
Rik <octave@nomad.inbox5.com>
parents:
12637
diff
changeset
|
722 %!assert(filter([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2), [2 6; 3 13; 5 21]); |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
723 %% Should put some tests of the "DIM" parameter in here. |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
724 |
10155
d0ce5e973937
DLD-FUNCTIONS/*.cc: delete Emacs local-variables settings
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
725 */ |