classdef zparameters < rf.internal.netparams.VoltageCurrentParameters
%zparameters Create a Z-parameters Object
%   OBJ = zparameters(FILENAME) creates the zparameters 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 (S, Y, etc...) then the data will be converted to Z-parameters.
%   All data is stored in real/imag format.
%
%   OBJ = zparameters(ZPARAM_OBJ) creates a deep copy of another
%   zparameters object ZPARAM_OBJ.
%
%   OBJ = zparameters(RFTBX_OBJ) extracts the network data in RFTBX_OBJ and
%   then converts it into Z-parameter data.  RFTBX_OBJ can have the
%   following types: sparameters, tparameters, yparameters, hparameters,
%   gparameters, abcdparameters, rfdata.data, rfdata.network, and any
%   analyzed rfckt type.
%
%   OBJ = zparameters(PARAMDATA,FREQ) creates a zparameters object directly
%   from specified data.  PARAMDATA is required and will be stored in the
%   "Parameters" property.  FREQ is required and will be stored in the
%   "Frequencies" property.
%
%PROPERTIES:
%   Parameters - An NxNxK complex array describing NxN Z-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 positive, real, increasing values.  It
%   describes the frequencies (in Hz) the Z-parameters were measured at.
%
%EXAMPLES:
%   % Read a file named 'defaultbandpass.s2p' and convert to Z-parameters
%   Z = zparameters('defaultbandpass.s2p');
%
%   % Extract Z11
%   z11 = rfparam(Z,1,1);
%
%   % Plot the imaginary part of Z11
%   plot(Z.Frequencies,imag(z11))
%
% See also rfparam, smith, rfwrite, sparameters, tparameters, zparameters,
% hparameters, gparameters, abcdparameters

%   Copyright 2016-2022 The MathWorks, Inc.

    properties(Constant,Access = protected)
        TypeFlag = 'Z'
    end
    
    methods
        function obj = zparameters(varargin)
            narginchk(1,2)
            [varargin{:}] = convertStringsToChars(varargin{:});
            obj = obj@rf.internal.netparams.VoltageCurrentParameters(varargin{:});
        end
    end
    
    % define abstract
    methods(Static,Access = protected)
        function validateParameters(newParam)
            rf.internal.netparams.validateNPortParameters(newParam,'zparameters')
        end
        
        function outdata = convert2me(str,indata,z0)
            switch lower(str(1))
                case 's'
                    outdata = s2z(indata,z0);
                case 't'
                    outdata = t2s(indata);
                    outdata = s2z(outdata,z0);
                case 'y'
                    outdata = y2z(indata);
                case 'z'
                    outdata = indata;
                case 'h'
                    outdata = h2z(indata);
                case 'g'
                    outdata = g2h(indata);
                    outdata = h2z(outdata);
                case 'a'
                    outdata = abcd2z(indata);
            end
        end
    end
    methods(Static,Hidden)
        function outobj = loadobj(in)
            data = in.Parameters;
            freq = in.Frequencies;
            outobj = zparameters(data,freq);
        end
    end
end
