[Scilab-users] Trying to work a tukeywin function
Arvid Rosén
arvid at softube.com
Thu Sep 20 08:41:59 CEST 2012
Hi,
Can you send us the file as it is now, and I'll take a look.
Cheers,
A
20 sep 2012 kl. 08:20 skrev Lester Anderson <arctica1963 at gmail.com>:
> Hi Samuel,
> Thanks for the pointers. It still fails with lots of errors even with changing the sections you noted). I have copied the errors here, it is like a few errors can have a compound effect on the rest:
>
> -->exec('C:\Users\Lester\Documents\3DInver\convert\tukeywin.sce', -1)
> function w = tukeywin (L, r = 1/2)
> !--error 37
> Incorrect function at line 31.
>
> at line 31 of exec file called by :
> exec('C:\Users\Lester\Documents\3DInver\convert\tukeywin.sce', -1)
>
> -->function w = tukeywin (L, r = 1/2)
> !--error 37
> Incorrect function.
>
> --> //nargin=>argn(2)
> --> // if (nargin < 1 || nargin > 2)
> --> if (argn(2) < 1 || argn(2) > 2)
> !--error 2
> Invalid factor.
>
> --> print_usage;
> !--error 4
> Undefined variable: print_usage
>
> --> elseif (nargin == 2)
> !--error 34
> Incorrect control instruction syntax.
>
> --> // check that 0 < r < 1
> --> if r > 1
> !--error 4
> Undefined variable: r
>
> --> r = 1;
> --> elseif r < 0
> !--error 34
> Incorrect control instruction syntax.
>
> --> r = 0;
> --> end
> !--error 34
> Incorrect control instruction syntax.
>
> --> end
> !--error 34
> Incorrect control instruction syntax.
>
> --> // generate window
> --> select r
> --> case 0,
> --> // full box
> --> w = ones (L, 1);
> !--error 4
> Undefined variable: L
>
> --> case 1,
> !--error 34
> Incorrect control instruction syntax.
>
> --> // Hanning window
> --> // = hanning (L);
> --> window('hanning',L)
> !--error 4
> Undefined variable: L
>
> --> else
> !--error 34
> Incorrect control instruction syntax.
>
> --> // cosine-tapered window
> --> t = linspace(0,1,L)(1:$:(1:$/2)';
> !--error 4
> Undefined variable: L
>
> --> w = (1 + cos(%pi*(2*t/r-1)))/2;
> !--error 4
> Undefined variable: t
>
> --> w(floor(r*(L-1)/2)+2:end) = 1;
> !--error 4
> Undefined variable: L
>
> --> w = [w; ones(modulo(L,2)); flipdim(w,1)];
> !--error 4
> Undefined variable: w
>
> --> end
> !--error 34
> Incorrect control instruction syntax.
>
> -->endfunction
> !--error 16
> Incorrect command!
>
> Thanks for any help
>
> Lester
>
> // Copyright (C) 2007 Laurent Mazet <mazet at crm.mot.com>
> //
> // This program is free software; you can redistribute it and/or modify it under
> // the terms of the GNU General Public License as published by the Free Software
> // Foundation; either version 3 of the License, or (at your option) any later
> // version.
> //
> // This program is distributed in the hope that it will be useful, but WITHOUT
> // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
> // details.
> //
> // You should have received a copy of the GNU General Public License along with
> // this program; if not, see <http://www.gnu.org/licenses/>.
>
> // -*- texinfo -*-
> // @deftypefn {Function File} {@var{w} =} tukeywin (@var{L}, @var{r})
> // Return the filter coefficients of a Tukey window (also known as the
> // cosine-tapered window) of length @var{L}. @var{r} defines the ratio
> // between the constant section and and the cosine section. It has to be
> // between 0 and 1. The function returns a Hanning window for @var{r}
> // egals 0 and a full box for @var{r} egals 1. By default @var{r} is set
> // to 1/2.
> //
> // For a definition of the Tukey window, see e.g. Fredric J. Harris,
> // "On the Use of Windows for Harmonic Analysis with the Discrete Fourier
> // Transform, Proceedings of the IEEE", Vol. 66, No. 1, January 1978,
> // Page 67, Equation 38.
> // @end deftypefn
>
> function w=tukeywin(L, r= 1/2)
>
> //nargin=>argn(2)
> // if (nargin < 1 || nargin > 2)
> if (argn(2) < 1 || argn(2) > 2)
> print_usage;
> elseif (nargin == 2)
> // check that 0 < r < 1
> if r > 1
> r = 1;
> elseif r < 0
> r = 0;
> end
> end
>
> // generate window
> select r
> case 0,
> // full box
> w = ones (L, 1);
> case 1,
> // Hanning window
> // w = hanning (L);
> window('hanning',L)
> else
> // cosine-tapered window
> t = linspace(0,1,L)(1:$:(1:$/2)';
> w = (1 + cos(%pi*(2*t/r-1)))/2;
> w(floor(r*(L-1)/2)+2:end) = 1;
> w = [w; ones(modulo(L,2)); flipdim(w,1)];
> end
>
> endfunction
>
> // demo
> // L = 100;
> // r = 1/3;
> // w = tukeywin (L, r);
> // title(sprintf("%d-point Tukey window, R = %d/%d", L, [p, q] = rat(r), q));
> // plot(w);
>
>
> On 19 September 2012 23:31, Samuel Gougeon <sgougeon at free.fr> wrote:
> Hello,
>
> Le 20/09/2012 00:05, Lester Anderson a écrit :
>>
>> function w=tukeywin(L, r= 1/2)
>>
>> if (nargin < 1 || nargin > 2) ------ Not sure how to replace this bit (variable not defined)
>>
> nargin => argn(2)
>
>> .../...
>>
>> // generate window
>>
>> switch r --------- think this should be select ?
>>
> Right
>> .../...
>> case 1,
>>
>> // Hanning window
>> w = hanning (L);
>>
> window('hn',L)
>> otherwise ------------- else
>>
> Yes
>
>> // cosine-tapered window
>> t = linspace(0,1,L)(1:end/2)';
>>
> replace end with $ : (1:$/2)';
>
>
>> w = (1 + cos(pi*(2*t/r-1)))/2;
>>
> pi => %pi
>
>
>> w(floor(r*(L-1)/2)+2:end) = 1;
>> w = [w; ones(mod(L,2)); flipud(w)];
>>
> mod => modulo
> flipud(w) => flipdim(w,1)
>
>> endswitch ------------------------------------ end ?
>>
> Yes
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
--
Arvid Rosén
Softube AB
S:t Larsgatan 10c
SE-582 24 Linköping
Sweden
Mobile: (+46) 73 25 123 47
Office: (+46) 13 21 16 23
Fax: (+46) 13 10 00 23
Mail: arvid at softube.com
URL: www.softube.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20120920/1460a3de/attachment.htm>
More information about the users
mailing list