function [B,A] = oct3dsgn(Fc,Fs,N);
% OCT3DSGN Design of a one-third-octave filter.
% [B,A] = OCT3DSGN(Fc,Fs,N) designs a digital 1/3-octave filter with
% center frequency Fc for sampling frequency Fs.
% The filter is designed according to the Order-N specification
% of the ANSI S1.1-1986 standard. Default value for N is 3.
% Warning: for meaningful design results, center frequency used
% should preferably be in range Fs/200 < Fc < Fs/5.
% Usage of the filter: Y = FILTER(B,A,X).
% Requires the Signal Processing Toolbox.
% See also OCT3SPEC, OCTDSGN, OCTSPEC.
% Author: Christophe Couvreur, Faculte Polytechnique de Mons (Belgium)
% Last modification: Aug. 25, 1997, 2:00pm.
%  ANSI S1.1-1986 (ASA 65-1986): Specifications for
% Octave-Band and Fractional-Octave-Band Analog and
% Digital Filters, 1993.
% Copyright (c) 1997, Christophe COUVREUR
% All rights reserved.
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
if (nargin > 3) | (nargin < 2)
error('Invalide number of arguments.');
if (nargin == 2)
N = 3;
if (Fc > 0.88*(Fs/2))
error('Design not possible. Check frequencies.');
% Design Butterworth 2Nth-order one-third-octave filter
% Note: BUTTER is based on a bilinear transformation, as suggested in .
pi = 3.14159265358979;
f1 = Fc/(2^(1/6));
f2 = Fc*(2^(1/6));
Qr = Fc/(f2-f1);
Qd = (pi/2/N)/(sin(pi/2/N))*Qr;
alpha = (1 + sqrt(1+4*Qd^2))/2/Qd;
W1 = Fc/(Fs/2)/alpha;
W2 = Fc/(Fs/2)*alpha;
[B,A] = butter(N,[W1,W2]);