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

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

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

%!demo
%! [z p k] = cheb1ap(8, 3);
%! [b a] = zp2tf(z, p, real(k));
%!
%! Wo = 2*pi*30;
%! [bt at] = lp2lp(b, a, Wo);
%!
%! w = logspace(-2, 1, 501);
%! H = freqs(b, a, w);
%! figure(1)
%! clf
%! subplot(2, 1, 1)
%! loglog(w, abs(H))
%! grid on
%! subplot(2, 1, 2)
%! semilogx(w, rad2deg(angle(H)))
%! grid on
%!
%! w = logspace(0, 3, 501);
%! H = freqs(bt, at, w);
%!
%! figure(2)
%! clf
%! subplot(2, 1, 1)
%! loglog(w, abs(H))
%! grid on
%! subplot(2, 1, 2)
%! semilogx(w, rad2deg(angle(H)))
%! grid on
