Home > m > timetools > statespacefunctions > ltpda_ss_ss2iir.m

ltpda_ss_ss2iir

PURPOSE ^

ltpda_ss_ss2iir converts a state space system into a iir object

SYNOPSIS ^

function varargout = ltpda_ss_ss2iir(varargin)

DESCRIPTION ^

 ltpda_ss_ss2iir converts a state space system into a iir object
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: ltpda_ss_ss2iir converts a state space system into a iir
 object. The output field is an array of filter of 3 dimensions. First is
 the output (in the order specified), second the input, third the system.

 CALL: iir = ltpda_ss_ss2iir(systs, Params)

 INPUTS: systs - state space subsystem array 
 Params - a plist containing the corresponding names of the inputs,
 row number, and output line number.

 OUTPUTS: iir - a miiir object

 ***** THERE ARE NO DEFAULT PARAMETERS *****

 VERSION: $Id: ltpda_ss_ss2iir.m,v 1.4 2008/03/11 16:52:56 adrien Exp $

 HISTORY: 26-02-2008
 Creation 02-01-2008 A Grynagier

 To do :  more checks! Numerical and syntaxic.  
 Also discuss the case when the ouput is in PFD form...
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = ltpda_ss_ss2iir(varargin)
0002 % ltpda_ss_ss2iir converts a state space system into a iir object
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: ltpda_ss_ss2iir converts a state space system into a iir
0006 % object. The output field is an array of filter of 3 dimensions. First is
0007 % the output (in the order specified), second the input, third the system.
0008 %
0009 % CALL: iir = ltpda_ss_ss2iir(systs, Params)
0010 %
0011 % INPUTS: systs - state space subsystem array
0012 % Params - a plist containing the corresponding names of the inputs,
0013 % row number, and output line number.
0014 %
0015 % OUTPUTS: iir - a miiir object
0016 %
0017 % ***** THERE ARE NO DEFAULT PARAMETERS *****
0018 %
0019 % VERSION: $Id: ltpda_ss_ss2iir.m,v 1.4 2008/03/11 16:52:56 adrien Exp $
0020 %
0021 % HISTORY: 26-02-2008
0022 % Creation 02-01-2008 A Grynagier
0023 %
0024 % To do :  more checks! Numerical and syntaxic.
0025 % Also discuss the case when the ouput is in PFD form...
0026 %
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029 %% standard calls for LTPDA function data
0030 
0031 ALGONAME = mfilename;
0032 VERSION = '$Id: ltpda_ss_ss2iir.m,v 1.4 2008/03/11 16:52:56 adrien Exp $';
0033 CATEGORY = 'STATESPACE';
0034 display(['starting ' ALGONAME]);
0035 
0036 if not(isempty(varargin))
0037     if isequal( varargin{1}, 'Version')
0038         varargout = VERSION;
0039         return;
0040     elseif isequal(varargin{1}, 'Params')
0041         varargout = plist('INPUTS', 'U_1', 'INPUTCOLUMNS', 1 ,'OUTPUTROW',1);
0042         return;
0043     elseif isequal(varargin{1}, 'Category')
0044         varargout = CATEGORY;
0045         return;
0046     end
0047 end
0048 iirs = miir();%found no other way to declare right size of iir array
0049 
0050 %% retriveing data
0051 systs = varargin{1};
0052 Params = varargin{2};
0053 INPUTS = find(Params, 'INPUTS');
0054 INPUTCOLUMNS = find(Params, 'INPUTCOLUMNS');
0055 if not(length(INPUTS)==length(INPUTCOLUMNS))
0056     msg ='error because differnent number of inputs and input columns specified';
0057     error(msg);
0058 end
0059 OUTPUTS = find(Params, 'OUTPUTROWS');
0060 for i_syst=1:length(systs) % for every system
0061     syst = systs(i_syst);
0062     AMAT = find(syst,'AMAT');
0063     CMAT = find(syst,'CMAT');
0064     BMATS = find(syst,'BMATS');
0065     DMATS = find(syst,'DMATS');
0066     Ninputs = find(syst,'NBINPUTS');
0067     NAME = find(syst,'NAME');
0068     INPUTSIZES = find(syst,'INPUTSIZES');
0069     INPUTNAMES = find(syst,'INPUTNAMES');
0070     STEPSIZE = find(syst,'TIMESTEP');
0071     for i_inputs=1:length(INPUTS) % for every input
0072         j_inputs =0;
0073         for i=1:length(INPUTNAMES) %finding corresponding indice in the system
0074             if isequal(INPUTNAMES{i}, INPUTS{i_inputs})
0075                 j_inputs = i;
0076             end
0077         end
0078         if j_inputs == 0
0079             error(['error : Input name ', INPUTS{i_inputs} ,' not found in system ', NAME])
0080             
0081         elseif INPUTCOLUMNS(i_inputs) > INPUTSIZES(j_inputs)
0082             error(['error: Input name ', INPUTS{i_inputs} ,' in system ', NAME, ' was given with a row indice ', num2str(INPUTCOLUMNS(i_inputs)), ' bigger than possible ', num2str(INPUTSIZES(j_inputs)) ])
0083         end
0084         for i_outputs=1:length(OUTPUTS)
0085 
0086             if STEPSIZE == 0
0087                 %to do instead : discretize system to 0.1s
0088                 display('Error because timestep must be nonzero to make a time discrete filter');
0089                 STEPSIZE = 1;
0090             end
0091             if size(BMATS{j_inputs},2)==0 ||size(CMAT{1},1)==0 %should not be called anymore
0092                 iirs(i_outputs,i_inputs,i_syst) = {};
0093             elseif size(AMAT{1},1)==0
0094                 D = DMATS{j_inputs};
0095                 a = D(OUTPUTS(i_outputs),INPUTCOLUMNS(i_inputs));
0096                 b = 1;
0097                 iirs(i_outputs,i_inputs,i_syst) = miir(plist('a', a, 'b', b, 'gain', 1, 'ntaps', 1, 'name', [NAME,'_',INPUTNAMES{i}], 'fs', 1/STEPSIZE));
0098             else
0099                 C = CMAT{1};
0100                 B = BMATS{j_inputs};
0101                 D = DMATS{j_inputs};
0102                 [a,b] = ss2tf(AMAT{1}, B(:,INPUTCOLUMNS(i_inputs)), C(OUTPUTS(i_outputs),:), D(OUTPUTS(i_outputs),INPUTCOLUMNS(i_inputs)));
0103                 Gain=1;
0104                 m = miir();
0105                 m.a = a;
0106                 m.b = b;
0107                 m.fs = 1/STEPSIZE;
0108                 m.name = [NAME,'_',INPUTNAMES{i}];
0109                 m.gain = Gain;
0110                 iirs(i_outputs,i_inputs,i_syst) = m;
0111             end
0112         end
0113     end
0114 end
0115 varargout = {iirs};
0116 end
0117

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003