classdef(SupportExtensionMethods = true) sparameters <                  ...
         rf.internal.netparams.ScatteringParameters
%SPARAMETERS Create an S-parameters Object
%   OBJ = SPARAMETERS(FILENAME) creates the SPARAMETERS object OBJ from the
%   file specified by FILENAME.  FILENAME must describe a Touchstone
%   (*.snp, *.ynp, etc) file. If the file stores the data in some other
%   type (Y, Z, etc...) then the data will be converted to S-parameters.
%   All data is stored in real/imag format.
%
%   OBJ = SPARAMETERS(PARAMDATA,FREQ,Z0) creates an SPARAMETERS object
%   directly from specified data.  NxNxK complex array PARAMDATA is
%   required input and will be stored in the "Parameters" property.
%   Required input FREQ is a real vector of nonnegative increasing values,
%   and will be stored in the "Frequencies" property. Real reference
%   impedance Z0 is optional (default=50) and will be stored in the
%   "Impedance" property.
%
%   Z0 is specified as one of the following:
%   - Scalar used for all ports and frequencies
%   - Vector of length size(PARAMDATA,1), for per-port impedances
%   - Vector of length size(PARAMDATA,3), for per-frequency impedances
%
%   If size(PARAMDATA,1) == size(PARAMDATA,3) == numel(Z0), then Z0
%   specifies per-port impedances, unless Z0 is a 3-D array.
%
%   OBJ = SPARAMETERS(CKTOBJ,FREQ,Z0) calculates the S-parameters of
%   CKTOBJ, where CKTOBJ can have the following types: circuit, rffilter,
%   and lcladder. Z0 is optional (default=50).
%
%   OBJ = SPARAMETERS(SPARAM_OBJ) copies the contents of SPARAM_OBJ.
%
%   OBJ = SPARAMETERS(SPARAM_OBJ,Z0) converts the S-parameter data in
%   SPARAM_OBJ to the new impedance Z0.
%
%   OBJ = SPARAMETERS(RFTBX_OBJ) extracts S-parameter data when RFTBX_OBJ
%   is an nport object, an rfdata.data object or any analyzed rfckt object.
%   When RFTBX_OBJ is an rfdata.network object, the network data is first
%   extracted and then converted to S-parameter data.
%
%   OBJ = SPARAMETERS(RFTBX_OBJ,Z0) converts the data in RFTBX_OBJ into
%   S-parameter data.  RFTBX_OBJ can have the following types: tparameters,
%   yparameters, zparameters, hparameters, gparameters, and abcdparameters.
%   Z0 is optional (default=50).
%
%   OBJ = SPARAMETERS(ANT_OBJ,FREQ,Z0) calculates the S-parameters for
%   ANT_OBJ, which is either a scalar antenna or array object from the
%   Antenna Toolbox. Z0 is optional (default=50).
%
%PROPERTIES:
%   Parameters - An NxNxK complex array describing NxN S-parameter data for
%   each frequency in the Frequencies property.  Note that
%   size(obj.Parameters,3) must equal length(obj.Frequencies)
%
%   Frequencies - A Kx1 vector of nonnegative, real, increasing values.  It
%   describes the frequencies (in Hz) the S-parameters were measured at.
%
%   Impedance - A scalar or 1xN vector of numeric, positive, real value(s)
%   that describe(s) the per-port impedance used to measure the
%   S-Parameters.
%
%EXAMPLES:
%   % Read a file named 'default.s2p'
%   S1 = sparameters('default.s2p');
%
%   % Plot all the parameters in S
%   figure
%   rfplot(S1)
%
%   % Convert the S-parameters to 100 ohms then plot just the parameter S21
%   S2 = sparameters(S1,100);
%   figure
%   rfplot(S2,2,1)
%
%   % Extract S11 from the original data
%   s11 = rfparam(S1,1,1);
%
% See also rfplot, rfparam, smithplot, rfwrite, circuit, tparameters,
% yparameters, zparameters, hparameters, gparameters, abcdparameters,
% rf/ispassive, passivity

%   Copyright 2012-2023 The MathWorks, Inc.

%#codegen

    properties(Constant,Access = protected)
        TypeFlag = 'S'
    end
    
    % constructor
    methods
        function obj = sparameters(varargin)
            coder.allowpcode('plain');
            narginchk(0,5)
            [varargin{:}] = convertStringsToChars(varargin{:});
            obj = obj@rf.internal.netparams.ScatteringParameters(varargin{:});
        end
    end
    
    % define abstract methods
    methods(Static,Access = protected)
        function validateParameters(newParam)
            rf.internal.netparams.validateNPortParameters(newParam,'sparameters')
        end
        
        function outdata = convert2me(str,indata,z0)
            switch lower(str(1))
                case 's'
                    outdata = indata;
                case 't'
                    outdata = t2s(indata);
                case 'y'
                    outdata = y2s(indata,z0);
                case 'z'
                    outdata = z2s(indata,z0);
                case 'h'
                    outdata = h2s(indata,z0);
                case 'g'
                    outdata = g2h(indata);
                    outdata = h2s(outdata,z0);
                case 'a'
                    outdata = abcd2s(indata,z0);
            end
        end
        
        function outdata = me2s(indata)
            outdata = indata;
        end
    end
    methods(Static,Hidden)
        function outobj = loadobj(in)
            data = in.Parameters;
            freq = in.Frequencies;
            z0 = in.Impedance;
            outobj = sparameters(data,freq,z0);
        end
    end
end
