function varargout = freqz(f,varargin)
%FREQZ  Filt object frequency response.
%   [H,W] = FREQZ(G) computes the frequency response of the
%   DFILT object G, and returns it in vector H.  The vector of
%   frequencies at which H is evaluated is returned in vector W.
%
%   [H,W] = FREQZ(G,N) uses N frequency points to compute the
%   frequency response.  If you don't specify N, it defaults to 512.
%
%   FREQZ(G,N,'whole') uses N points around the whole unit circle.  
%
%   [H,F] = FREQZ(G,N,Fs) and [H,F] = FREQZ(G,N,'whole',Fs)
%   uses the sampling frequency Fs (in Hz) for the computation and
%   returns a vector of frequencies F, also in Hz.
%
%   H = FREQZ(G,W) and H = FREQZ(G,F,Fs), where W or F are vectors,
%   return the frequency response evaluated at the points in W
%   (in radians/sample) or F (in Hz).
%
%   FREQZ(...) with no output arguments plots the frequency response.
%
%   [H,W,S] = FREQZ(...) or [H,F,S] = FREQZ(...) returns plotting information
%   to be used with FREQZPLOT.  S is a structure whose fields can be altered
%   to obtain different frequency response plots.  For more information see
%   the help for FREQZPLOT.
%
%   See also DFILT/IMPZ, DFILT/STEPZ, DFILT/ZPLANE, DFILT/GRPDELAY.

%   Author(s): R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.3 $  $Date: 2000/06/13 21:21:00 $ 

[h,w,s] = computefreqz(f,varargin{:});

if nargout == 0,
    freqzplot(h,w,s);
else
    varargout = {h,w,s};
end

%--------------------------------------------------------------
function [h,w,s] = computefreqz(f,varargin)
%COMPUTEFREQZ  Compute freq. response of multiple sections.

% Initialize h
switch f.connection,
case 'cas',
    [h,w,s] = freqz(1,1,varargin{:});
case 'par',
    [h,w,s] = freqz(0,1,varargin{:});
end

for n = 1:nsections(f),
    fsec = section(f,n);
    [b,a] = tf(fsec);
    % Compute freq. response of each section
    ht = freqz(b,a,varargin{:});
    
    switch f.connection,
    case 'cas',
        % For cascaded connections, multiply all freq. responses
        h = h.*ht;
    case 'par',
        % For parallel connections, add all freq. responses
        h = h + ht;
    end
end
    
% [EOF] - freqz.m

