%% Copyright (C) 2021 Tony Richardson
%%
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program.  If not, see <https://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @deftypefn {} {@var{[bt, at]} =} lp2hp (@var{b}, @var{a}, @var{Wo})
%% @deftypefnx {}{@var{[At,Bt,Ct,Dt]} =} lp2hp (@var{A}, @var{B}, @var{C}, @var{D}, @var{Wo})
%%
%% [bt, at] = lp2hp(b, a, Wo) transforms an analog lowpass filter in transfer
%% function form to an analog highpass filter with a different cutoff frequency (Wo).
%%
%% [At,Bt,Ct,Dt] = lp2hp(A, B, C, D, Wo) transforms an analog lowpass filter in state
%% space form to an analog highpass filter with a different cutoff frequency (Wo).
%% @seealso{lp2lp, lp2bp, lp2bs}
%% @end deftypefn

%% Author: Tony Richardson <richardson.tony@gmail.com>
%% Created: 2021-04-09

function [At Bt Ct Dt] = lp2hp(A, B, C, D, Wo)
  if (nargin == 3)
    Wo = C;
    [A B C D] = tf2ss(A, B);
  elseif nargin!=5
    print_usage;
  end
  [At Bt Ct Dt] = sstrans(A, B, C, D, Wo, true);
  if (nargout == 2)
    [At Bt] = ss2tf(At, Bt, Ct, Dt);
  end
end

%!demo
%! f = 100;
%! [ze pe ke] = ellipap(5, 3, 30);
%! [be ae] = zp2tf(ze, pe, ke);
%! 
%! w = logspace(-2, 1, 501);
%! H = freqs(be, ae, w);
%! figure(1)
%! clf
%! semilogx(w, 20*log10(abs(H)))
%! grid
%! 
%! [bh ah] = lp2hp(be, ae, 2*pi*f);
%! 
%! f = logspace(1, 3, 501);
%! H = freqs(bh, ah, 2*pi*f);
%! figure(2)
%! clf
%! semilogx(f, 20*log10(abs(H)))
%! grid
