]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/mscohere.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / mscohere.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]=mscohere(x,y,Nfft,Fs,window,overlap,range,plot_type,detrend)
18 %%
19 %%     Estimate (mean square) coherence of signals "x" and "y".
20 %%     Use the Welch (1967) periodogram/FFT method.
21 %%     See "help pwelch" for description of arguments, hints and references
22
23
24 function [varargout] = mscohere(varargin)
25   %%
26   %% Check fixed argument
27   if ( nargin<2 )
28     error( 'mscohere: Need at least 2 args. Use help mscohere' );
29   end
30   nvarargin = length(varargin);
31   %% remove any pwelch RESULT args and add 'cross'
32   for iarg=1:nvarargin
33     arg = varargin{iarg};
34     if ( ~isempty(arg) && ischar(arg) && ( strcmp(arg,'power') || ...
35            strcmp(arg,'cross') || strcmp(arg,'trans') || ...
36            strcmp(arg,'coher') || strcmp(arg,'ypower') ))
37       varargin{iarg} = [];
38     end
39   end
40   varargin{nvarargin+1} = 'coher';
41   %%
42   if ( nargout==0 )
43     pwelch(varargin{:});
44   elseif ( nargout==1 )
45     Pxx = pwelch(varargin{:});
46     varargout{1} = Pxx;
47   elseif ( nargout>=2 )
48     [Pxx,f] = pwelch(varargin{:});
49     varargout{1} = Pxx;
50     varargout{2} = f;
51   end
52 end