Mercurial > octave-nkf
annotate scripts/signal/durbinlevinson.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | eb63fbe60fab |
children | 1740012184f9 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1998, 2000, 2002, 2005, 2006, 2007, 2009 |
7017 | 2 ## Friedrich Leisch |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
3191 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
3191 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3191 | 19 |
3449 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} durbinlevinson (@var{c}, @var{oldphi}, @var{oldv}) | |
22 ## Perform one step of the Durbin-Levinson algorithm. | |
3191 | 23 ## |
6547 | 24 ## The vector @var{c} specifies the autocovariances @code{[gamma_0, @dots{}, |
3449 | 25 ## gamma_t]} from lag 0 to @var{t}, @var{oldphi} specifies the |
26 ## coefficients based on @var{c}(@var{t}-1) and @var{oldv} specifies the | |
27 ## corresponding error. | |
3191 | 28 ## |
3449 | 29 ## If @var{oldphi} and @var{oldv} are omitted, all steps from 1 to |
30 ## @var{t} of the algorithm are performed. | |
31 ## @end deftypefn | |
3426 | 32 |
3457 | 33 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at> |
34 ## Description: Perform one step of the Durbin-Levinson algorithm | |
3426 | 35 |
3191 | 36 function [newphi, newv] = durbinlevinson (c, oldphi, oldv) |
3426 | 37 |
3457 | 38 if (! ((nargin == 1) || (nargin == 3))) |
6046 | 39 print_usage (); |
3191 | 40 endif |
3426 | 41 |
3457 | 42 if (columns (c) > 1) |
8507 | 43 c = c'; |
3191 | 44 endif |
45 | |
46 newphi = 0; | |
47 newv = 0; | |
3426 | 48 |
3191 | 49 if (nargin == 3) |
3426 | 50 |
3191 | 51 t = length (oldphi) + 1; |
3426 | 52 |
3191 | 53 if (length (c) < t+1) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
54 error ("durbinlevinson: c too small"); |
3191 | 55 endif |
3426 | 56 |
3191 | 57 if (oldv == 0) |
58 error ("durbinlevinson: oldv = 0"); | |
59 endif | |
3426 | 60 |
3457 | 61 if (rows (oldphi) > 1) |
3191 | 62 oldphi = oldphi'; |
63 endif | |
3426 | 64 |
3191 | 65 newphi = zeros (1, t); |
3457 | 66 newphi(1) = (c(t+1) - oldphi * c(2:t)) / oldv; |
3191 | 67 for i = 2 : t |
68 newphi(i) = oldphi(i-1) - newphi(1) * oldphi(t-i+1); | |
69 endfor | |
3457 | 70 newv = (1 - newphi(1)^2) * oldv; |
3426 | 71 |
3191 | 72 elseif(nargin == 1) |
3426 | 73 |
3191 | 74 tt = length (c)-1; |
75 oldphi = c(2) / c(1); | |
3457 | 76 oldv = (1 - oldphi^2) * c(1); |
3426 | 77 |
3191 | 78 for t = 2 : tt |
3426 | 79 |
3191 | 80 newphi = zeros (1, t); |
3457 | 81 newphi(1) = (c(t+1) - oldphi * c(2:t)) / oldv; |
3191 | 82 for i = 2 : t |
3426 | 83 newphi(i) = oldphi(i-1) - newphi(1) * oldphi(t-i+1); |
3191 | 84 endfor |
3457 | 85 newv = (1 - newphi(1)^2) * oldv; |
3426 | 86 |
3191 | 87 oldv = newv; |
88 oldphi = newphi; | |
3426 | 89 |
3191 | 90 endfor |
3426 | 91 |
3191 | 92 endif |
93 | |
94 endfunction |