<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Scilab time frequency toolbox.
This file must be used under the terms of the  terms of the GNU General Public License 
as published by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Copyright (c) 1996 by CNRS (France).
-->


<refentry xml:id="Cwindow" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:scilab="http://www.scilab.org"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>Cwindow</refname><refpurpose>Creates a window of length N with a given shape.</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <title>Calling Sequence</title>
    <synopsis>
      H=Cwindow(N,NAME)
      H=Cwindow(N,NAME,PARAM)
      H=Cwindow(N,NAME,PARAM,PARAM2)
    </synopsis>
  </refsynopsisdiv>


  <refsection>
    <title>Parameters</title>
    <variablelist>
      <varlistentry>
        <term>N      :</term>
        <listitem>
          <para>a positive integer value: the length of the window</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>NAME   :</term>
        <listitem>
          <para>a character string : the name of the window shape (see below)</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>PARAM  :</term>
        <listitem>
          <para>a real number: an optional parameter for 'Kaiser', "Spline" or "Nutbess" windows</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>PARAM2 :</term>
        <listitem>
          <para>a real number: a second optional parameters for  "Spline" or "Nutbess" windows</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>H :</term>
        <listitem>
          <para>a real column  vector of length N: The window coefficients</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsection>

  <refsection>
    <title>Description</title>
    <para>
      Creates a window of length N with a given shape.
    </para>
    <para>
      Possible names are :
    </para>
    <para>
      <xref linkend="hamming_id">'Hamming'</xref>,  

      <xref linkend="hann_id">'Hanning'</xref>,
 
      <xref linkend="kaiser_id">'Kaiser'</xref>,  
  
      <xref linkend="nuttall_id">'Nuttall'</xref>,   

      <xref linkend="sine_id">'Papoulis'</xref>, 

      <xref linkend="sine_id">'Sine'</xref>, 
      
      <xref linkend="harris_id">'Harris'</xref>,  
  
      <xref linkend="rect_id">'Rect'</xref>,   
 
      <xref linkend="triang_id">'Triang'</xref>, 
   
      <xref linkend="bartlett_id">'Bartlett'</xref>,  

      <xref linkend="barthann_id">'BartHann'</xref>, 

      <xref linkend="blackman_id">'Blackman'</xref>
      
      <xref linkend="gauss_id">'Gauss'</xref>,    
 
      <xref linkend="parzen_id">'Parzen'</xref>,  

      <xref linkend="powersine_id">'Powersine'</xref>, 

      <xref linkend="nutbess_id">'Nutbess'</xref>,  

      <xref linkend="spline_id">'spline'</xref>,
      
      <xref linkend="flattop_id">'Flattop_ni'</xref>,

      <xref linkend="flattop_id">'Flattop'</xref>, 

      <xref linkend="flattopm_id">'Flattop_m'</xref>, 

      <xref linkend="flattopsrs_id">'Flattop_srs'</xref>
    </para>
    <itemizedlist>
      <listitem>
        <term id="hamming_id">The Hamming window</term> is defined by: 
        <para>
          <latex>
            H(n+1)=a_{0}-(1-a_0) \cos \left({\frac {2\pi n}{N-1}}\right),\quad 0\leq n\leq N-1
          </latex>
        </para>
        <para>With</para>
        <para>
          <latex>
            a_0=0.54;
          </latex>
        </para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"hamming"),"hamming");
        ]]></scilab:image>
      </listitem>

      <listitem>
        <term id="hann_id">The Hann (Hanning) window</term> is defined by: 
        <para>
          <latex>
            H(n+1)=a_{0}-\underbrace {(1-a_{0})} _{a_{1}}\cdot \cos \left({\tfrac {2\pi n}{N-1}}\right),\quad 0\leq n\leq N-1
          </latex>
        </para>
        <para>With </para>
        <para>
          <latex>
            a_0=0.5
          </latex>
        </para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"hanning"),"hanning");
        ]]></scilab:image>
      </listitem>

      <listitem>
        <term id="kaiser_id">The Kaiser window</term> is defined by:
        <para><latex>
          H(n+1)={\frac {I_{0}\left(\beta {\sqrt {1-({\frac {2n}{N-1}})^{2}}}\right)}{I_{0}(\pi \alpha )}}} w_{0}(n)={\frac {I_{0}\left(\pi \alpha {\sqrt {1-({\frac {2n}{N-1}})^{2}}}\right)}{I_{0}(\beta )},\quad 0\leq n\leq N-1
        </latex></para>
        <para>
          The optional parameter PARAM gives the beta value. Its  default value is 3*%pi.
        </para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Kaiser"),"Kaiser");
        ]]></scilab:image>
      </listitem>

      <listitem>
        <term id="nuttall_id">The Nuttall (Blackman Nuttall) window</term>  is defined by:
        <para><latex>
          H ( n+1) = a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right)-a_{3}\cos \left({\frac {6\pi n}{N-1}}\right),\quad 0\leq n\leq N-1
        </latex></para>
        <para>With</para>
        <para><latex>
          a_{0}=0.3635819;\quad a_{1}=0.4891775;\quad a_{2}=0.1365995;\quad a_{3}=0.0106411\,} a_{0}=0.3635819;\quad a_{1}=0.4891775;\quad a_{2}=0.1365995;\quad a_{3}=0.0106411
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Nuttall"),"Blackman Nuttall");
        ]]></scilab:image>
      </listitem>
      <listitem>
        <term id="blackman_id">The Blackman window</term> is defined by:
        <para><latex>
          H(n+1)=a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right),\quad 0\leq n\leq N-1
        </latex></para>
        <para>With</para>
        <para><latex>
          a_{0}={\frac {1-\alpha }{2}};\quad a_{1}={\frac {1}{2}};\quad a_{2}={\frac {\alpha }{2}};\quad\ \alpha = 0.16
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Blackman"),"Blackman")
        ]]></scilab:image>
      </listitem>
      <listitem>
        <term id="harris_id">The Harris (Blackman Harris) window</term> is defined by:
        <para><latex>H(n+1)=a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right)-a_{3}\cos \left({\frac {6\pi n}{N-1}}\right),\quad 0\leq n\leq N-1 </latex></para>
        <para>With</para>
        <para><latex>

          a_{0}=0.35875;\quad a_{1}=0.48829;\quad a_{2}=0.14129;\quad a_{3}=0.01168\,} a_{0}=0.35875;\quad a_{1}=0.48829;\quad a_{2}=0.14129;\quad a_{3}=0.01168
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Harris"),"Blackman Harris");
        ]]></scilab:image>
      </listitem>
      <listitem>
       <term id="triang_id">The Triang or Bartlett window</term> is defined by:
        <para><latex>
          H(n+1)=1-\left|{\frac {2 n}{N-1}-1\right|, \quad 0\leq n\leq N-1
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Triang"),"Triangular");
        ]]></scilab:image>
      </listitem>
      <listitem>
        <term id="barthann_id">The Barthann (Bartlett Hann) window</term> is defined by:
        <para><latex>
          H(n+1)=a_{0}-a_{1}\left|{\frac {n}{N-1}}-{\frac {1}{2}}\right|-a_{2}\cos \left({\frac {2\pi n}{N-1}}\right), \quad 0\leq n\leq N-1
        </latex></para>
        <para>With </para>
        <para><latex>
          a_{0}=0.62;\quad a_{1}=0.48;\quad a_{2}=0.38\,} a_{0}=0.62;\quad a_{1}=0.48;\quad a_{2}=0.38
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Barthann"),"Bartlett Hann");
        ]]></scilab:image>
        
      </listitem>
      <listitem>
        <term id="sine_id">The Papoulis or Sine  window</term>  is defined by:
        <para><latex>
          H(n+1)=\sin (\frac{n \pi}{N - 1});\quad 0\leq n\leq N-1
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Sine"),"Sine");
        ]]></scilab:image>
        
      </listitem>

      <listitem>
       <term id="gauss_id">The Gauss  window</term> is defined by:
        <para><latex>
          H(n+1)=e^{-1 + \frac{2*n}{N-1}^2 \log(K)};\quad 0\leq n\leq N-1
        </latex></para>
        
        <para>
          For the gaussian window, the optionnal parameter K
          sets the value at both extremities. The default value is 0.005
        </para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Gauss"),"Gauss");
        ]]></scilab:image>
        
      </listitem>
      <listitem>
        <term id="parzen_id">The Parzen  window</term> is defined by:
        <para><latex>
          H(n+1)=\left\{{\begin{array}{ll}1-6\left({\frac {n}{N/2}}\right)^{2}\left(1-{\frac {|n|}{N/2}}\right),&amp;0\leqslant |n|\leqslant {\frac {N}{4}}\\2\left(1-{\frac {|n|}{N/2}}\right)^{3},&amp;{\frac {N}{4}}\leq |n|\leq {\frac {N}{2}}\\\end{array}}\right.;\quad 0\leq n\leq N-1
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Parzen"),"Parzen");
        ]]></scilab:image>
      </listitem>

      <listitem>
        <term id="powersine_id">The Powersine  (Power of sine) windows</term> are defined by:
        <para><latex>
          H(n+1)=\sin(\frac{n \pi}{N-1})^{2 L};\quad 0\leq n\leq N-1
        </latex></para>
        
        <para>Where L is the optionnal parameter (defaut value: 1)</para>
        <para>The rectangular window (L = 0), the sine window (L = 1/2), and the Hann window (L = 1) are members of this family. </para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Powersine"),"Power sine");
        ]]></scilab:image>

      </listitem>
      <listitem>
        <term id="nutbess_id">The Nutbess  windows</term> are defined by:
       
        
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Nutbess"),"Nutbess");
        ]]></scilab:image>

      </listitem>

      <listitem>
        <term id="spline_id">The Spline window</term>  is  defined by:
        <para><latex>
          H(n+1)=sinc(\frac{nfreq}{2 p} (-frac{N-1}{2} + n))^ p;
        </latex></para>
        
        <para>
          Where nfreq (frequency bandwidth) is given by the arguement
          PARAM and the spline order p is given by the optional parameter PARAM2 (default value
          %pi*N*nfreq/10).
        </para>
        
        
        <para>
          Where nfreq (frequency bandwidth) is given by the arguement
          PARAM and the spline order p is given by the optional parameter PARAM2 (default value
          %pi*N*nfreq/10).
        </para>
      </listitem>

      <listitem>
        <term id="flattop_id">The Flattop and  Flattop_ni  windows</term> are  defined by:
        <para><latex>
          H(n+1)=a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right),\quad 0\leq n\leq N-1
        </latex></para>
        <para>With</para>
        <para><latex>
          a_{0}=0.2810639;\quad a_{1}=0.5208972;\quad a_{2}=0.1980399;
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Flattop"),"Flattop");
        ]]></scilab:image>

      </listitem>
      <listitem>
        <term id="flattopm_id">The Flattop_m (Matlab equivalent) window</term> is defined by:
        <para><latex>
          H(n+1)=a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right)-a_{3}\cos \left({\frac {6\pi n}{N-1}}\right)+a_{4}\cos \left({\frac {8\pi n}{N-1}}\right);\quad 0\leq n\leq N-1
        </latex></para>
        <para> With</para>
        <para><latex>
          a_{0}=.21557895;\quad a_{1}=0.41663158;\quad a_{2}=0.277263158;\quad a_{3}=0.083578947;\quad a_{4}=0.006947368;
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Flattop_m"),"Matlab Flattop");
        
        ]]></scilab:image>

      </listitem>
      <listitem>
        <term id="fltatopsrs_id">The Flattop_srs (Standford Research)  window</term> is defined by:
        <para><latex>
          H(n+1)=a_{0}-a_{1}\cos \left({\frac {2\pi n}{N-1}}\right)+a_{2}\cos \left({\frac {4\pi n}{N-1}}\right)-a_{3}\cos \left({\frac {6\pi n}{N-1}}\right)+a_{4}\cos \left({\frac {8\pi n}{N-1}}\right);\quad 0\leq n\leq N-1
        </latex></para>
        <para>With</para>
        <para><latex>
          a_{0}=1;\quad a_{1}=1.93;\quad a_{2}=1.29;\quad a_{3}=0.388;\quad a_{4}=0.028;
        </latex></para>
        <scilab:image><![CDATA[
        plotwindow(Cwindow(129,"Flattop_srs"),"Standford research Flattop");
        
        ]]></scilab:image>

      </listitem>

    </itemizedlist>
    <note>
      <para>
        this function is similar to <link
        linkend="tftb_window">tftb_window</link> but it is coded in C so
        it is more efficient
      </para>
    </note>
  </refsection>

  <refsection>
    <title>Examples</title>
    <programlisting role="example"><![CDATA[
    h=Cwindow(256,'Gauss',0.005); plot(h);
    ]]></programlisting>
  </refsection>
  <refsection>
    <title>See Also</title>
    <link linkend="tftb_window">tftb_window</link>,<link type="scilab" linkend="scilab.help/window">window</link>
  </refsection>
  <refsection>
    <title>Authors</title>
    <simplelist type="vert">
      <member>H. Nahrstaedt - Sep 2010</member>
      <member>Emmanuel Roy - 2000</member>
      <member>Serge Steer - 2018</member>
    </simplelist>
  </refsection>
</refentry>
