]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/cpsd.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / cpsd.m
1 %% Copyright (C) 2006 Peter V. Lanspeary <pvl@mecheng.adelaide.edu.au>
2 %%
3 %% This program is free software; you can redistribute it and/or modify it under
4 %% the terms of the GNU General Public License as published by the Free Software
5 %% Foundation; either version 3 of the License, or (at your option) any later
6 %% version.
7 %%
8 %% This program is distributed in the hope that it will be useful, but WITHOUT
9 %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 %% details.
12 %%
13 %% You should have received a copy of the GNU General Public License along with
14 %% this program; if not, see <http://www.gnu.org/licenses/>.
15
16 %% Usage:
17 %%   [Pxx,freq] = cpsd(x,y,Nfft,Fs,window,overlap,range,plot_type,detrend)
18 %%
19 %%     Estimate cross power spectrum of data "x" and "y" by the Welch (1967)
20 %%     periodogram/FFT method.
21 %%     See "help pwelch" for description of arguments, hints and references
22
23 function [varargout] = cpsd(varargin)
24
25   %% Check fixed argument
26   if ( nargin<2 )
27     error( 'cpsd: Need at least 2 args. Use help cpsd.' );
28   end
29   nvarargin = length(varargin);
30   %% remove any pwelch RESULT args and add 'cross'
31   for iarg=1:nvarargin
32     arg = varargin{iarg};
33     if ( ~isempty(arg) && ischar(arg) && ( strcmp(arg,'power') || ...
34            strcmp(arg,'cross') || strcmp(arg,'trans') || ...
35            strcmp(arg,'coher') || strcmp(arg,'ypower') ))
36       varargin{iarg} = [];
37     end
38   end
39   varargin{nvarargin+1} = 'cross';
40   %%
41   if ( nargout==0 )
42     pwelch(varargin{:});
43   elseif ( nargout==1 )
44     Pxx = pwelch(varargin{:});
45     varargout{1} = Pxx;
46   elseif ( nargout>=2 )
47     [Pxx,f] = pwelch(varargin{:});
48     varargout{1} = Pxx;
49     varargout{2} = f;
50   end
51 end