classdef yparameters < rf.internal.netparams.VoltageCurrentParameters
%yparameters Create a Y-parameters Object
%   OBJ = yparameters(FILENAME) creates the yparameters 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, Z, etc...) then the data will be converted to Y-parameters.
%   All data is stored in real/imag format.
%
%   OBJ = yparameters(YPARAM_OBJ) creates a deep copy of another
%   yparameters object YPARAM_OBJ.
%
%   OBJ = yparameters(RFTBX_OBJ) extracts the network data in RFTBX_OBJ and
%   then converts it into Y-parameter data.  RFTBX_OBJ can have the
%   following types: sparameters, tparameters, zparameters, hparameters,
%   gparameters, abcdparameters, rfdata.data, rfdata.network, and any
%   analyzed rfckt type.
%
%   OBJ = yparameters(PARAMDATA,FREQ) creates a yparameters 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 Y-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 Y-parameters were measured at.
%
%EXAMPLES:
%   % Read a file named 'default.s2p' and convert to Y-parameters
%   Y = yparameters('default.s2p');
%
%   % Plot the parameter Y11 on a smith chart
%   figure;
%   smith(Y,1,1)
%
%   % Extract Y21
%   y21 = rfparam(Y,2,1);
%
% See also rfparam, smith, rfwrite, sparameters, tparameters, zparameters,
% hparameters, gparameters, abcdparameters

%   Copyright 2016-2022 The MathWorks, Inc.

    properties(Constant,Access = protected)
        TypeFlag = 'Y'
    end
    
    methods
        function obj = yparameters(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,'yparameters')
        end
        
        function outdata = convert2me(str,indata,z0)
            switch lower(str(1))
                case 's'
                    outdata = s2y(indata,z0);
                case 't'
                    outdata = t2s(indata);
                    outdata = s2y(outdata,z0);
                case 'y'
                    outdata = indata;
                case 'z'
                    outdata = z2y(indata);
                case 'h'
                    outdata = h2y(indata);
                case 'g'
                    outdata = g2h(indata);
                    outdata = h2y(outdata);
                case 'a'
                    outdata = abcd2y(indata);
            end
        end
    end
    methods(Static,Hidden)
        function outobj = loadobj(in)
            data = in.Parameters;
            freq = in.Frequencies;
            outobj = yparameters(data,freq);
        end
    end
end
