]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/nanfft.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / nanfft.m
1 function [Y,N,N2] = nanfft(X,N,DIM);
2 % NANFFT calculates the Fourier-Transform of X for data with missing values. 
3 %  NANFFT is the same as FFT but X can contain missing values encoded with NaN.
4 %  NaN's are skipped, NaN do not result in a NaN output. 
5 %
6 %   Y = NANFFT(X)
7 %   Y = NANFFT(X,N)
8 %   Y = NANFFT(X,[],DIM)
9
10 %   [Y,N] = NANFFT(...)
11 %       returns the number of valid samples N
12 %
13 %
14 % WARNING: missing values can introduce aliasing - causing unintended results.
15 %    Moreover, the behavior of bandpass and highpass filters in case of missing values 
16 %    is not fully understood, and might contain some pitfalls.  
17 %
18 % see also: FFT, XCORR, NANCONV, NANFILTER
19
20 %       $Id$
21 %       Copyright (C) 2005,2011 by Alois Schloegl <alois.schloegl@gmail.com>            
22 %       This function is part of the NaN-toolbox available at 
23 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/ and 
24 %       http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/NaN/inst/
25
26 %    This program is free software; you can redistribute it and/or modify
27 %    it under the terms of the GNU General Public License as published by
28 %    the Free Software Foundation; either version 3 of the License, or
29 %    (at your option) any later version.
30 %
31 %    This program is distributed in the hope that it will be useful,
32 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
33 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34 %    GNU General Public License for more details.
35 %
36 %    You should have received a copy of the GNU General Public License
37 %    along with this program; if not, write to the Free Software
38 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
39
40 warning('NANFFT is experimental. For more details see HELP NANFFT');
41
42 NX = isnan(X);
43 X(NX) = 0; 
44
45 if nargin==1,
46         Y = fft(X);
47         N2 = sum(1-NX); % 
48         N = fft(NX);
49 elseif nargin==2,
50         Y = fft(X,N);
51         N2 = sum(1-NX); 
52         N = fft(NX);
53 elseif nargin==3,
54         Y = fft(X,N,DIM);
55         N2 = sum(1-NX,DIM); % 
56         N = fft(NX,N,DIM);
57 end;
58