]> Creatis software - CreaPhase.git/blob - octave_packages/tsa-4.2.4/flix.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / tsa-4.2.4 / flix.m
1 function Y=flix(D,x)
2 % floating point index - interpolates data in case of non-integer indices
3 %
4 % Y=flix(D,x)
5 %   FLIX returns Y=D(x) if x is an integer 
6 %   otherwise D(x) is interpolated from the neighbors D(ceil(x)) and D(floor(x)) 
7
8 % Applications: 
9 % (1)  discrete Dataseries can be upsampled to higher sampling rate   
10 % (2)  transformation of non-equidistant samples to equidistant samples
11 % (3)  [Q]=flix(sort(D),q*(length(D)+1)) calculates the q-quantile of data series D   
12 %
13 % FLIX(D,x) is the same as INTERP1(D,X,'linear'); Therefore, FLIX might
14 % become obsolete in future. 
15 %
16 % see also: HIST2RES, Y2RES, PLOTCDF, INTERP1
17
18 %       $Id: flix.m 5090 2008-06-05 08:12:04Z schloegl $
19 %       Copyright (C) by 2001-2005,2008 Alois Schloegl <a.schloegl@ieee.org>    
20 %       This is part of the TSA-toolbox see also: 
21 %          http://www.dpmi.tu-graz.ac.at/schloegl/matlab/tsa/
22 %          http://octave.sf.net/
23 %
24 %    This program is free software: you can redistribute it and/or modify
25 %    it under the terms of the GNU General Public License as published by
26 %    the Free Software Foundation, either version 3 of the License, or
27 %    (at your option) any later version.
28 %
29 %    This program is distributed in the hope that it will be useful,
30 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
31 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32 %    GNU General Public License for more details.
33 %
34 %    You should have received a copy of the GNU General Public License
35 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
36
37 D  = D(:);
38 Y  = x;
39
40 k1 = ((x >= 1) & (x <= size(D,1)));     
41 Y(~k1) = NaN;
42
43 k  = x - floor(x);      % distance to next sample        
44
45 ix = ~k & k1;           % find integer indices
46 Y(ix) = D(x(ix));       % put integer indices
47
48 ix = k & k1;            % find non-integer indices
49
50 Y(ix) = D(floor(x(ix))).*(1-k(ix)) + D(ceil(x(ix))).*k(ix);  
51