function [allpassnum, allpassden] = allpasslp2bsc(wo, wt)
%ALLPASSLP2BSC Allpass for lowpass to complex bandstop frequency transformation.
%   [AllpassNum,AllpassDen] = ALLPASSLP2BSC(Wo,Wt) returns numerator,
%   ALLPASSNUM, and the denominator, ALLPASSDEN, of the allpass mapping filter.
%
%   Inputs:
%     Wo         - Frequency value to be transformed from the prototype filter.
%                  The frequency should be normalized to be between 0 and 1,
%                  with 1 corresponding to half the sample rate.
%     Wt         - Desired frequency location in the transformed target filter.
%                  The frequency should be normalized to be between -1 and 1,
%                  with 1 corresponding to half the sample rate.
%   Outputs:
%     AllpassNum - Numerator of the mapping filter
%     AllpassDen - Denominator of the mapping filter
%
%   Example:
%        % Allpass mapper changing the lowpass with cutoff frequency originally
%        % at Wo=0.5 to the complex bandstop with bandedges at Wt1=0.2 and Wt2=0.4
%        Wo = 0.5;
%        Wt = [0.2,0.4];
%        [AllpassNum, AllpassDen] = allpasslp2bsc(Wo, Wt);
%        % Calculate the spectrum of the allpass mapping filter
%        [h, f] = freqz(AllpassNum, AllpassDen, 'whole');
%        % Plot the phase response normalized to PI as a mapping function Wo(Wt)
%        plot(f/pi, angle(h)/pi, Wt, Wo.*[1,-1], 'ro');
%        title('The mapping function Wo(Wt)');
%        xlabel('New frequency, Wt');
%        ylabel('Old frequency, Wo');
%
%   See also IIRLP2BSC and ZPKLP2BSC.

%   Author(s): Dr. Artur Krukowski, University of Westminster, London, UK.
%   Copyright 1999-2021 The MathWorks, Inc.

%#codegen
% --------------------------------------------------------------------
% Perform the parameter validity check

narginchk(2,2);

ftransfargchk(wo, 'Frequency value from the prototype filter', ...
                        'scalar',  'real', 'normalized');
ftransfargchk(wt, 'Desired frequency location in the target filter', ...
                        'vector2', 'real', 'full normalized');

% ---------------------------------------------------------------------
% Calculate the mapping filter

wc         = sum(wt) / 2;
bw         = max(wt) - min(wt);
alpha      = cos(pi*(wo+bw/2)/2) / cos(pi*(wo-bw/2)/2);
beta       = exp(-pi*1i*wc);
allpassnum = fliplr(conj([      -beta +alpha]));
allpassden = fliplr(conj([-alpha*beta 1]));
