]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/nanfilter1uc.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / nanfilter1uc.m
1 function [x,z] = nanfilter1uc(uc,x,z);
2 % NANFILTER1UC is an adaptive filter for data with missing values encoded as NaN. 
3 %       
4 %      [Y,Z] = nanfilter1uc(uc,X [, Z]);  
5 %
6 % if X contains no missing data, NANFILTER behaves like FILTER(uc,[1,uc-1],X[,Z]).
7 %
8 % see also: FILTER, NANFILTER, SUMSKIPNAN
9
10 %       $Id$
11 %       Copyright (C) 2010,2011 by Alois Schloegl <alois.schloegl@gmail.com>    
12 %       This function is part of the NaN-toolbox available at 
13 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/ and 
14 %       http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/NaN/inst/
15
16 %    This program is free software; you can redistribute it and/or modify
17 %    it under the terms of the GNU General Public License as published by
18 %    the Free Software Foundation; either version 3 of the License, or
19 %    (at your option) any later version.
20 %
21 %    This program is distributed in the hope that it will be useful,
22 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
23 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 %    GNU General Public License for more details.
25 %
26 %    You should have received a copy of the GNU General Public License
27 %    along with this program; if not, write to the Free Software
28 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
29
30
31 na = 2; %length(A);
32 nb = 2; %length(B);
33 if any(size(x)==1)
34         nc = 1; 
35 else    
36         nc = size(x,2);
37 end; 
38
39 acN = zeros(1,nc);
40 if nargin<3,
41         z = zeros(1,nc);
42 end;
43 acc = NaN(1,nc);
44 for k = 1:size(x,1),
45         ix = isnan(x(k,:));
46         acN = acN.*ix+1;
47         UC1 = ((1-uc).^acN);
48         acc(~ix) = (1-UC1(~ix)) .* x(k,~ix) + z(~ix);  % / A{1};
49         ix = isnan(acc);
50         acc(ix) = x(k,ix); 
51         z   = (1-uc) * acc;
52         x(k,:) = acc;
53 end;
54