<?xml version="1.0" encoding="UTF-8"?>

<!--
 *
 * This help file was generated from fir2.sci using help_from_sci().
 *
 -->

<refentry version="5.0-subset Scilab" xml:id="fir2" 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:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:scilab="http://www.scilab.org"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>fir2</refname>
    <refpurpose>Design an FIR filter with an arbitrary frequency response.</refpurpose>
  </refnamediv>


<refsynopsisdiv>
   <title>Syntax</title>
   <synopsis>
   b = fir2(n, f, m)
   b = fir2(n, f, m, grid_n)
   b = fir2(n, f, m, grid_n, ramp_n)
   b = fir2(n, f, m, grid_n, ramp_n, window)
   
   </synopsis>
</refsynopsisdiv>

<refsection>
   <title>Parameters</title>
   <variablelist>
        <varlistentry>
            <term>n:</term>
            <listitem><para> Order of the filter.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>f:</term>
            <listitem><para> Vector of normalized frequency points (values between 0 and 1, where 1 corresponds to the Nyquist frequency).</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>m:</term>
            <listitem><para> Vector of magnitude values corresponding to the frequency points in `f`. Must be the same length as `f`.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>grid_n:</term>
            <listitem><para> (optional) Number of grid points for interpolation. Default is 512 or the next power of 2 greater than `n+1`.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>ramp_n:</term>
            <listitem><para> (optional) Width of the ramp applied to discontinuities in the frequency response. Default is `grid_n / 25`.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>window:</term>
            <listitem><para> (optional) Window function to shape the filter. If not specified, a Hamming window of length `n+1` is used.</para></listitem>
        </varlistentry>
        <varlistentry>
            <term>b:</term>
            <listitem><para> Vector containing the FIR filter coefficients.</para></listitem>
        </varlistentry>
   </variablelist>
</refsection>

<refsection>
   <title>Description</title>
   <para>
The `fir2` function designs an FIR filter of order `n` with an arbitrary frequency response specified by the vectors `f` and `m`.
The filter is designed using the frequency sampling method, where the desired frequency response is interpolated onto a grid
and transformed into the time domain. An optional window can be applied to shape the filter.
   </para>
   <para>
</para>
</refsection>

<refsection>
   <title>Examples</title>
   <programlisting role="example"><![CDATA[
// Design a filter with a discontinuous frequency response
f = [0, 0.3, 0.3, 0.6, 0.6, 1]
m = [0, 0, 1, 0.5, 0, 0]
[h, w] = freqz(fir2(100, f, m))
plot(f, m, , w / %pi, abs(h));
legend("target response","filter response");
   ]]></programlisting>
</refsection>

<refsection>
   <title>Authors</title>
   <simplelist type="vert">
   <member>FOSSEE Team</member>
   <member>toolbox@scilab.in</member>
   </simplelist>
</refsection>
</refentry>
