<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
          xmlns:scilab="http://www.scilab.org" xml:id="flts" xml:lang="en">
    <refnamediv>
        <refname>flts</refname>
        <refpurpose>time response (discrete time, sampled system)</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
          y = flts(u, sl)
          y = flts(u, sl, past)
          y = flts(u, sl, x0)
          [y,x] = flts(u, sl, x0)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>u</term>
                <listitem>
                    <para>matrix (input vector)</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>sl</term>
                <listitem>
                    <para>
                        A linear dynamical system, in state space,
                        transfer function or zpk representations, in
                        discrete time.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>x0</term>
                <listitem>
                    <para>vector (initial state ; default
                        value=<literal>0</literal>)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>past</term>
                <listitem>
                    <para>matrix (of the past ; default
                        value=<literal>0</literal>)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>x,y</term>
                <listitem>
                    <para>matrices (state and output)</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <itemizedlist>
            <listitem>
                <para>State-space form:</para>
            </listitem>
        </itemizedlist>
        <para>
            <literal>sl</literal> is a discrete linear system given by its state
            space representation (see <link linkend="syslin">syslin</link> ):
        </para>
        <para>
            <literal>sl=syslin('d',A,B,C,D)</literal> :
        </para>
        <screen><![CDATA[
x[t+1] = A x[t] + B u[t]
y[t]   = C x[t] + D u[t]
]]></screen>
        <para>
            or, more generally, if <literal>D</literal> is a polynomial matrix
            (<literal>p = degree(D(z))</literal>) :
        </para>
        <screen><![CDATA[
D(z) = D_0 + z D_1 + z^2 D_2 +..+ z^p D_p
y[t] = C x[t] + D_0 u[t] + D_1 u[t+1] +..+ D_[p] u[t+p]
]]></screen>
        <itemizedlist>
            <listitem>
                <para>Transfer form:</para>
            </listitem>
        </itemizedlist>
        <para>
            <literal> y=flts(u,sl[,past])</literal>. Here <literal>sl</literal>
            is a linear system in transfer matrix representation i.e
        </para>
        <para>
            <literal>sl=syslin('d',transfer_matrix)</literal> (see
            <literal>
                <link linkend="syslin">syslin</link>
            </literal>
            ).
        </para>
        <screen><![CDATA[
past = [u     ,...,  u   ]
       [ -nd           -1]
       [y     ,...,  y   ]
       [ -nd           -1]
]]></screen>
        <para>is the matrix of past values of u and y.</para>
        <para>
            <literal>nd</literal> is the maximum of degrees of lcm's of each row
            of the denominator matrix of <literal>sl</literal>.
        </para>
        <screen><![CDATA[
u = [u0 u1 ... un]  (input)
y = [y0 y1 ... yn]  (output)
]]></screen>
        <para>p is the difference between maximum degree of numerator and maximum
            degree of denominator
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
sl=syslin('d',1,1,1);u=1:10;
y=flts(u,sl);
plot2d(y)
[y1,x1]=flts(u(1:5),sl);y2=flts(u(6:10),sl,x1);
y-[y1,y2]

//With polynomial D:
z=poly(0,'z');
D=1+z+z^2; p =degree(D);
sl=syslin('d',1,1,1,D);
y=flts(u,sl);[y1,x1]=flts(u(1:5),sl);
y2=flts(u(5-p+1:10),sl,x1);  // (update)
y-[y1,y2]

//Delay (transfer form): flts(u,1/z)
// Usual responses
z=poly(0,'z');
h=syslin(0.1,(1-2*z)/(z^2+0.3*z+1))
imprep=flts(eye(1,20),tf2ss(h));   //Impulse response
clf();
plot(imprep,'b')
u=ones(1,20);
stprep=flts(ones(1,20),tf2ss(h));   //Step response
plot(stprep,'g')
 ]]></programlisting>
        <scilab:image>
            sl=syslin('d',1,1,1);u=1:10;
            y=flts(u,sl);
            plot2d(y)
            [y1,x1]=flts(u(1:5),sl);y2=flts(u(6:10),sl,x1);
            y-[y1,y2]

            z=poly(0,'z');
            D=1+z+z^2; p =degree(D);
            sl=syslin('d',1,1,1,D);
            y=flts(u,sl);[y1,x1]=flts(u(1:5),sl);
            y2=flts(u(5-p+1:10),sl,x1);
            y-[y1,y2]

            z=poly(0,'z');
            h=syslin(0.1,(1-2*z)/(z^2+0.3*z+1))
            imprep=flts(eye(1,20),tf2ss(h));
            clf();
            plot(imprep,'b')
            u=ones(1,20);
            stprep=flts(ones(1,20),tf2ss(h));
            plot(stprep,'g')
        </scilab:image>
        <programlisting role="example"><![CDATA[
// Other examples
A=[1 2 3;0 2 4;0 0 1];
B=[1 0;0 0;0 1];
C=eye(3,3);
Sys=syslin('d',A,B,C);
H=ss2tf(Sys); u=[1;-1]*(1:10);
//
yh=flts(u,H); ys=flts(u,Sys);
norm(yh-ys,1)
//hot restart
[ys1,x]=flts(u(:,1:4),Sys);ys2=flts(u(:,5:10),Sys,x);
norm([ys1,ys2]-ys,1)
//
yh1=flts(u(:,1:4),H);yh2=flts(u(:,5:10),H,[u(:,2:4);yh(:,2:4)]);
norm([yh1,yh2]-yh,1)
//with D&lt;&gt;0
D=[-3 8;4 -0.5;2.2 0.9];
Sys=syslin('d',A,B,C,D);
H=ss2tf(Sys); u=[1;-1]*(1:10);
rh=flts(u,H); rs=flts(u,Sys);
norm(rh-rs,1)
//hot restart
[ys1,x]=flts(u(:,1:4),Sys);ys2=flts(u(:,5:10),Sys,x);
norm([ys1,ys2]-rs,1)
//With H:
yh1=flts(u(:,1:4),H);yh2=flts(u(:,5:10),H,[u(:,2:4); yh1(:,2:4)]);
norm([yh1,yh2]-rh)
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="ltitr">ltitr</link>
            </member>
            <member>
                <link linkend="dsimul">dsimul</link>
            </member>
            <member>
                <link linkend="rtitr">rtitr</link>
            </member>
        </simplelist>
    </refsection>
    <refsection role="history">
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>6.0</revnumber>
                <revdescription>
                    <para>handling zpk representation</para>
                </revdescription>
            </revision>
        </revhistory>
    </refsection>

</refentry>
