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