Hello,<br><br>I have found the Matlab code for a tukeywin function but am unsure of the conversion:<br><br><pre style="font-family:Monospaced;font-style:normal;font-size:14.0"><span style="color:rgb(1,168,1);font-style:italic">//  Copyright (C) 2007 Laurent Mazet </span><span style="color:rgb(1,168,1);font-style:italic"><</span><span style="color:rgb(1,168,1);font-style:italic"><a href="mailto:mazet@crm.mot.com">mazet@crm.mot.com</a></span><span style="color:rgb(1,168,1);font-style:italic">></span>
<span style="color:rgb(1,168,1);font-style:italic">// </span>
<span style="color:rgb(1,168,1);font-style:italic">//  This program is free software; you can redistribute it and/or modify it under</span>
<span style="color:rgb(1,168,1);font-style:italic">//  the terms of the GNU General Public License as published by the Free Software</span>
<span style="color:rgb(1,168,1);font-style:italic">//  Foundation; either version 3 of the License, or (at your option) any later</span>
<span style="color:rgb(1,168,1);font-style:italic">//  version.</span>
<span style="color:rgb(1,168,1);font-style:italic">// </span>
<span style="color:rgb(1,168,1);font-style:italic">//  This program is distributed in the hope that it will be useful, but WITHOUT</span>
<span style="color:rgb(1,168,1);font-style:italic">//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
<span style="color:rgb(1,168,1);font-style:italic">//  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more</span>
<span style="color:rgb(1,168,1);font-style:italic">//  details.</span>
<span style="color:rgb(1,168,1);font-style:italic">// </span>
<span style="color:rgb(1,168,1);font-style:italic">//  You should have received a copy of the GNU General Public License along with</span>
<span style="color:rgb(1,168,1);font-style:italic">//  this program; if not, see </span><span style="color:rgb(1,168,1);font-style:italic"><</span><span style="color:rgb(1,168,1);font-style:italic"><a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a></span><span style="color:rgb(1,168,1);font-style:italic">></span><span style="color:rgb(1,168,1);font-style:italic">.</span>

<span style="color:rgb(1,168,1);font-style:italic">//  -*- texinfo -*-</span>
<span style="color:rgb(1,168,1);font-style:italic">//  @deftypefn {Function File} {@var{w} =} tukeywin (@var{L}, @var{r})</span>
<span style="color:rgb(1,168,1);font-style:italic">//  Return the filter coefficients of a Tukey window (also known as the</span>
<span style="color:rgb(1,168,1);font-style:italic">//  cosine-tapered window) of length @var{L}. @var{r} defines the ratio</span>
<span style="color:rgb(1,168,1);font-style:italic">//  between the constant section and and the cosine section. It has to be</span>
<span style="color:rgb(1,168,1);font-style:italic">//  between 0 and 1. The function returns a Hanning window for @var{r}</span>
<span style="color:rgb(1,168,1);font-style:italic">//  egals 0 and a full box for @var{r} egals 1. By default @var{r} is set</span>
<span style="color:rgb(1,168,1);font-style:italic">//  to 1/2.</span>
<span style="color:rgb(1,168,1);font-style:italic">// </span>
<span style="color:rgb(1,168,1);font-style:italic">//  For a definition of the Tukey window, see e.g. Fredric J. Harris,</span>
<span style="color:rgb(1,168,1);font-style:italic">//  </span><span style="color:rgb(1,168,1);font-style:italic">"</span><span style="color:rgb(1,168,1);font-style:italic">On the Use of Windows for Harmonic Analysis with the Discrete Fourier</span>
<span style="color:rgb(1,168,1);font-style:italic">//  Transform, Proceedings of the IEEE</span><span style="color:rgb(1,168,1);font-style:italic">"</span><span style="color:rgb(1,168,1);font-style:italic">, Vol. 66, No. 1, January 1978,</span>
<span style="color:rgb(1,168,1);font-style:italic">//  Page 67, Equation 38.</span>
<span style="color:rgb(1,168,1);font-style:italic">//  @end deftypefn</span>

<span style="color:rgb(176,24,19)">function</span> <span style="color:rgb(131,67,16);font-weight:bold">w</span><span style="color:rgb(92,92,92)">=</span><span style="color:rgb(0,0,0);text-decoration:underline">tukeywin</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(0,0,0)">, </span><span style="color:rgb(131,67,16);font-weight:bold">r</span><span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span>

  <span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">nargin</span> <span style="color:rgb(92,92,92)"><</span> <span style="color:rgb(188,143,143)">1</span> <span style="color:rgb(92,92,92)">|</span><span style="color:rgb(92,92,92)">|</span> <span style="color:rgb(0,0,0)">nargin</span> <span style="color:rgb(92,92,92)">></span> <span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span>    ------ Not sure how to replace this bit (variable not defined)
    <span style="color:rgb(0,0,0)">print_usage</span><span style="color:rgb(0,0,0)">;</span>
  <span style="color:rgb(160,32,240)">elseif</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">nargin</span> <span style="color:rgb(92,92,92)">==</span> <span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span>
      <span style="color:rgb(1,168,1);font-style:italic">//  check that 0 </span><span style="color:rgb(1,168,1);font-style:italic"><</span><span style="color:rgb(1,168,1);font-style:italic"> r </span><span style="color:rgb(1,168,1);font-style:italic"><</span><span style="color:rgb(1,168,1);font-style:italic"> 1</span>
      <span style="color:rgb(160,32,240)">if</span> <span style="color:rgb(131,67,16);font-weight:bold">r</span> <span style="color:rgb(92,92,92)">></span> <span style="color:rgb(188,143,143)">1</span>
        <span style="color:rgb(131,67,16);font-weight:bold">r</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(0,0,0)">;</span>
      <span style="color:rgb(160,32,240)">elseif</span> <span style="color:rgb(131,67,16);font-weight:bold">r</span> <span style="color:rgb(92,92,92)"><</span> <span style="color:rgb(188,143,143)">0</span>
        <span style="color:rgb(131,67,16);font-weight:bold">r</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">0</span><span style="color:rgb(0,0,0)">;</span>
      <span style="color:rgb(0,0,0)">endif</span>
  <span style="color:rgb(0,0,0)">endif</span>

  <span style="color:rgb(1,168,1);font-style:italic">//  generate window</span>
  <span style="color:rgb(0,0,0)">switch</span> <span style="color:rgb(131,67,16);font-weight:bold">r</span>   --------- think this should be select ?
    <span style="color:rgb(160,32,240)">case</span> <span style="color:rgb(188,143,143)">0</span><span style="color:rgb(0,0,0)">,</span>
      <span style="color:rgb(1,168,1);font-style:italic">//  full box</span>
      <span style="color:rgb(131,67,16);font-weight:bold">w</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(50,185,185)">ones</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(0,0,0)">,</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
    <span style="color:rgb(160,32,240)">case</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(0,0,0)">,</span>
      <span style="color:rgb(1,168,1);font-style:italic">//  Hanning window</span>
      <span style="color:rgb(131,67,16);font-weight:bold">w</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(0,0,0)">hanning</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span>
    <span style="color:rgb(0,0,0)">otherwise</span>   ------------- else
      <span style="color:rgb(1,168,1);font-style:italic">//  cosine-tapered window</span>
      <span style="color:rgb(0,0,0)">t</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(174,92,176);text-decoration:underline">linspace</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(160,32,240)">end</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">'</span><span style="color:rgb(0,0,0)">;</span>
      <span style="color:rgb(131,67,16);font-weight:bold">w</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">1</span> <span style="color:rgb(92,92,92)">+</span> <span style="color:rgb(50,185,185)">cos</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">pi</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(0,0,0)">t</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(131,67,16);font-weight:bold">r</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(0,0,0)">;</span>
      <span style="color:rgb(131,67,16);font-weight:bold">w</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(50,185,185)">floor</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">r</span><span style="color:rgb(92,92,92)">*</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(92,92,92)">-</span><span style="color:rgb(188,143,143)">1</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">/</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(92,92,92)">+</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(255,170,0)">:</span><span style="color:rgb(160,32,240)">end</span><span style="color:rgb(74,85,219)">)</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(188,143,143)">1</span><span style="color:rgb(0,0,0)">;</span>
      <span style="color:rgb(131,67,16);font-weight:bold">w</span> <span style="color:rgb(92,92,92)">=</span> <span style="color:rgb(74,85,219)">[</span><span style="color:rgb(131,67,16);font-weight:bold">w</span><span style="color:rgb(0,0,0)">;</span> <span style="color:rgb(50,185,185)">ones</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(0,0,0)">mod</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">L</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(188,143,143)">2</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(0,0,0)">;</span> <span style="color:rgb(0,0,0)">flipud</span><span style="color:rgb(74,85,219)">(</span><span style="color:rgb(131,67,16);font-weight:bold">w</span><span style="color:rgb(74,85,219)">)</span><span style="color:rgb(74,85,219)">]</span><span style="color:rgb(0,0,0)">;</span>
  <span style="color:rgb(0,0,0)">endswitch</span>  ------------------------------------ end ?

<span style="color:rgb(176,24,19)">endfunction</span>

<span style="color:rgb(1,168,1);font-style:italic">// demo</span>
<span style="color:rgb(1,168,1);font-style:italic">// L = 100;</span>
<span style="color:rgb(1,168,1);font-style:italic">// r = 1/3;</span>
<span style="color:rgb(1,168,1);font-style:italic">// w = tukeywin (L, r);</span>
<span style="color:rgb(1,168,1);font-style:italic">// title(sprintf(</span><span style="color:rgb(1,168,1);font-style:italic">"</span><span style="color:rgb(1,168,1);font-style:italic">%d-point Tukey window, R = %d/%d</span><span style="color:rgb(1,168,1);font-style:italic">"</span><span style="color:rgb(1,168,1);font-style:italic">, L, [p, q] = rat(r), q));</span>
<span style="color:rgb(1,168,1);font-style:italic">// plot(w);</span></pre>I tried the mfile2sci conversion but this was not helpful. Found this source in the Octave package.<br><br>Still learning scilab, so some pointers would be helpful.<br>
<br>Lester<br>