1 ## Copyright (C) 1999 Paul Kienzle <pkienzle@users.sf.net>
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
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
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/>.
16 ## usage: [P, w] = __power (b, a, [, nfft [, Fs]] [, range] [, units])
18 ## Plot the power spectrum of the given ARMA model.
20 ## b, a: filter coefficients (b=numerator, a=denominator)
21 ## nfft is number of points at which to sample the power spectrum
22 ## Fs is the sampling frequency of x
23 ## range is 'half' (default) or 'whole'
24 ## units is 'squared' or 'db' (default)
25 ## range and units may be specified any time after the filter, in either
28 ## Returns P, the magnitude vector, and w, the frequencies at which it
29 ## is sampled. If there are no return values requested, then plot the power
30 ## spectrum and don't return anything.
32 ## TODO: consider folding this into freqz --- just one more parameter to
33 ## TODO: distinguish between 'linear', 'log', 'logsquared' and 'squared'
35 function [varargout] = __power (b, a, varargin)
36 if (nargin < 2 || nargin > 6) print_usage; endif
45 for i=1:length(varargin)
47 if strcmp(arg, 'squared') || strcmp(arg, 'db')
49 elseif strcmp(arg, 'whole')
52 elseif strcmp(arg, 'half')
68 if isempty(nfft); nfft = 256; endif
69 if isempty(Fs); Fs = 2; endif
75 [P, w] = freqz(b, a, nfft, range, Fs);
77 P = (range_fact/Fs)*(P.*conj(P));
79 if strcmp(units, 'squared')
82 plot(w, 10.0*log10(abs(P)), ";;");
85 if nargout >= 1, varargout{1} = P; endif
86 if nargout >= 2, varargout{2} = w; endif