# v_windows

## PURPOSE

V_WINDOWS Generate a standard windowing function (TYPE,N,MODE,P,OV)

## SYNOPSIS

function w = v_windows(wtype,n,mode,p,ov)

## DESCRIPTION

    V_WINDOWS Generate a standard windowing function (TYPE,N,MODE,P,OV)
     Usage: (1) w=v_windows(3,n)';         % same as w=hamming(n);
            (2) w=v_windows(3,n,'l')';     % same as w=hanning(n,'periodic');
            (3) w=v_windows(2,n)';         % same as w=hanning(n);
            (4) w=v_windows(2,n,'l')';     % same as w=hanning(n,'periodic');
            (5) v_windows('hamming');      % plot window information

     Inputs:   WTYPE  is a string or integer specifying the window type (see below)
               N      is the number of output points to generate (actually FLOOR(N))
                      and also determines the period of the underlying window [default 256]
                      Alternatively, with the 'v' or 'V' options, a vector of positions within the window
               MODE   is a string specifying various options (see below)
               P      is a vector of parameters required for some window types
               OV     is the overlap in samples between succesive windows (must be H<=N/2 and
                      used only for the 'o' option) [default floor(N/2)]

     Outputs:  W(1,N)   is the output window. If no output is specified, a graph
                      of the window and its frequency response will be drawn.

     The WTYPE input specifies one of the following window types (either name, short or code can be used):

           Name     Short Code  Params
        'blackman'   'b'    6
        'cauchy'     'y'   13     1
        'cos'        'c'   10     1      cos window to the power P [default P=1]
        'dolph'      'd'   14     1      Dolph-Chebyshev window with sideband attenuation P dB [default P=50]
                                         Note that this window has impulses at the two ends.
        'gaussian'      'g'   12     1      truncated at +-P std deviations [default P=3]
        'hamming'    'm'    3
        'hanning'    'n'    2            also called "hann" or "von hann"
        'harris3'      '3'    4            3-term blackman-harris with 67dB sidelobes
        'harris4'      '4'    5            4-term blackman-harris with 92dB sidelobes
        'kaiser'      'k'   11     1      with parameter P (often called beta) [default P=8]
        'rectangle'  'r'    1
        'triangle'   't'    9     1      triangle to the power P [default P=1]
        'tukey'      'u'   15     1      cosine tapered 0<P<1 [default P=0.5]
        'vorbis'     'v'    7            perfect reconstruction window from [2] (use mode='sE2')
        'rsqvorbis'  'w'    8            raised squared vorbis with lower sidelobes (use mode='sdD2')

     Window equivalences:

        'hanning'   =    cos(2) = tukey(1)
        'rectangle' =    tukey(0)
        'reisz'     =    triangle(2)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

     The MODE input determines the scaling and sampling of the window function and
         is a text string with characters whose meanings are given below. The
         default is 'ubw' for window functions whose end points are non-zero and 'unw'
         for window functions whose end points are zero (e.g. hanning window)

             scaling:
                    1-9 = set target gain to G = 1/n in scaling options [default n=1 so G=1]
                      u = unscaled  with the peak of the underlying continuous
                          window equalling G. [default]
                      p = scaled to make the actual peak G
                      d = scaled to make DC gain equal to G (summed sample values).
                      D = scaled to make average value equal G
                      e = scaled to make energy = G (summed squared sample values).
                      E = scaled to make mean energy = G (mean squared sample values).
                      q = take square root of the window after scaling

             first and last samples (see note on periodicity below):
                      b [both]    = The first and last samples are at the extreme ends of
                                    the window [default for most windows].
                      n [neither] = The first and last samples are one sample away from the ends
                                    of the window [default for windows having zero end points].
                      s [shifted] = The first and last samples are half a sample away from the
                                    ends of the window .
                      l [left]    = The first sample is at the end of the window while the last
                                    is one sample away from the end .
                      r [right]   = The first sample is one sample away from the end while the
                                    last is at the end of the window .

             whole/half window (see note on periodicity below):
                      w = The whole window is included [default]
                      c = The first sample starts in the centre of the window
                      h = The first sample starts half a sample beyond the centre
                      v = The n input is a vector of window positions where window goes from -1 to +1
                      V = The n input is a vector of window positions where window goes from 0 to +1

             convolve with rectangle
                      o = convolve w(n) with a rectangle of length N-H [default floor(N/2)]
                          This can be used to force w(n) to satisfy the Princen-Bradley condition

     Periodicity:
         The underlying period of the window function depends on the chosen mode combinations and
         is given in the table below. For overlapping windows with perfect reconstruction choose
         N to be an integer and modes 'ws', 'wl' or 'wr'.

            Whole/half window -->     w         h         c

            End points:       b      N-1      2N-1      2N-2
                              n      N+1      2N+1       2N
                              s       N        2N       2N-1
                              l       N       2N+1       2N
                              r       N       2N-1      2N-2

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     To obtain unity gain for windowed overlap-add processing you can use
     the following. Bandwidths have been multiplied by the window length.
     For perfect reconstruction, you can use any multiple of the overlap factors
     shown assuming the same window is used for both analysis and synthesis.
     These are the Princen-Bradley conditions: fliplr(w)=w, w(i)^2+w(i+n/2)^2=1
     Any symmetric window will satisfy the conditions with mode 'boqD2' [3].

       Window     Mode Overlap-Factor Sidelobe  3dB-BW  6dB-BW Equiv-noise-BW
       rectangle  E        1           -13dB     0.9      1.2      1.0
       rsqvorbis  sqD2     2           -26dB     1.1      1.5      1.1
       hamming    sqD2     2,3,5       -24dB     1.1      1.5      1.1
       hanning    sqD2     2,3,5       -23dB     1.2      1.6      1.2 =cos('sE2')
       cos        sE2      2,3,5       -23dB     1.2      1.6      1.2 used in MP3
       kaiser(5)  boqD2    2           -23dB     1.2      1.7      1.3 used in AAC [4]
       vorbis     sE2      2,9,15      -21dB     1.3      1.8      1.4 used in Vorbis
       hamming    sE4      3,4,5       -43dB     1.3      1.8      1.4
       hanning    sE4      3,4,5       -31dB     1.4      2.0      1.5
     The integer following D or E in the mode string should match the overlap factor

     References:
      [1]  F. J. Harris. On the use of windows for harmonic analysis with the
           discrete fourier transform. Proc IEEE, 66 (1): 51-83, Jan. 1978.
      [2]    L. D. Fielder, M. Bosi, G. Davidson, M. Davis, C. Todd, and S. Vernon.
           AC-2 and AC-3: Low-complexity transform-based audio coding.
           In Audio Engineering Society Conference: Collected Papers on Digital Audio Bit-Rate Reduction, May 1996.
      [3]    J. Princen, A. Johnson, and A. Bradley. Subband/transform coding using filter
           bank designs based on time domain aliasing cancellation.
           In Proc. IEEE Intl Conf. Acoustics, Speech and Signal Processing, volume 12,
           pages 2161-2164, 1987. doi: 10.1109/ICASSP.1987.1169405.
      [4]    T. Sporer, K. Brandenburg, and B. Edler.
           The use of multirate filter banks for coding of high quality digital audio.
           In Proc EUSIPCO, volume 1, pages 211-214, 1992.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          Copyright (C) Mike Brookes 2002-2015
          Version: $Id: v_windows.m 10477 2018-06-03 16:16:45Z dmb $

       VOICEBOX is a MATLAB toolbox for speech processing.
       Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       This program is free software; you can redistribute it and/or modify
       it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

       You can obtain a copy of the GNU Lesser General Public License from
       https://www.gnu.org/licenses/ .

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

## CROSS-REFERENCE INFORMATION

This function calls:

- v_windinfo V_WINDINFO window information and figures of merit X=(W,FS)

This function is called by:

- v_correlogram V_CORRELOGRAM calculate correlogram [y,ty]=(x,inc,nw,nlag,m,fs)
- v_lpcauto V_LPCAUTO performs autocorrelation LPC analysis [AR,E,K]=(S,P,T)
- v_stftw V_STFTW converts a time-domain signal into the time-frequency domain with the Short-time Fourier Transform [Y,SO,T,F]=(X,NW,M,OV)

## SOURCE CODE

    0001 function w = v_windows(wtype,n,mode,p,ov)
    0002 %V_WINDOWS Generate a standard windowing function (TYPE,N,MODE,P,OV)
    0003 % Usage: (1) w=v_windows(3,n)';         % same as w=hamming(n);
    0004 %        (2) w=v_windows(3,n,'l')';     % same as w=hanning(n,'periodic');
    0005 %        (3) w=v_windows(2,n)';         % same as w=hanning(n);
    0006 %        (4) w=v_windows(2,n,'l')';     % same as w=hanning(n,'periodic');
    0007 %        (5) v_windows('hamming');      % plot window information
    0008 %
    0009 % Inputs:   WTYPE  is a string or integer specifying the window type (see below)
    0010 %           N      is the number of output points to generate (actually FLOOR(N))
    0011 %                  and also determines the period of the underlying window [default 256]
    0012 %                  Alternatively, with the 'v' or 'V' options, a vector of positions within the window
    0013 %           MODE   is a string specifying various options (see below)
    0014 %           P      is a vector of parameters required for some window types
    0015 %           OV     is the overlap in samples between succesive windows (must be H<=N/2 and
    0016 %                  used only for the 'o' option) [default floor(N/2)]
    0017 %
    0018 % Outputs:  W(1,N)   is the output window. If no output is specified, a graph
    0019 %                  of the window and its frequency response will be drawn.
    0020 %
    0021 % The WTYPE input specifies one of the following window types (either name, short or code can be used):
    0022 %
    0023 %       Name     Short Code  Params
    0024 %    'blackman'   'b'    6
    0025 %    'cauchy'     'y'   13     1
    0026 %    'cos'        'c'   10     1      cos window to the power P [default P=1]
    0027 %    'dolph'      'd'   14     1      Dolph-Chebyshev window with sideband attenuation P dB [default P=50]
    0028 %                                     Note that this window has impulses at the two ends.
    0029 %    'gaussian'      'g'   12     1      truncated at +-P std deviations [default P=3]
    0030 %    'hamming'    'm'    3
    0031 %    'hanning'    'n'    2            also called "hann" or "von hann"
    0032 %    'harris3'      '3'    4            3-term blackman-harris with 67dB sidelobes
    0033 %    'harris4'      '4'    5            4-term blackman-harris with 92dB sidelobes
    0034 %    'kaiser'      'k'   11     1      with parameter P (often called beta) [default P=8]
    0035 %    'rectangle'  'r'    1
    0036 %    'triangle'   't'    9     1      triangle to the power P [default P=1]
    0037 %    'tukey'      'u'   15     1      cosine tapered 0<P<1 [default P=0.5]
    0038 %    'vorbis'     'v'    7            perfect reconstruction window from [2] (use mode='sE2')
    0039 %    'rsqvorbis'  'w'    8            raised squared vorbis with lower sidelobes (use mode='sdD2')
    0040 %
    0041 % Window equivalences:
    0042 %
    0043 %    'hanning'   =    cos(2) = tukey(1)
    0044 %    'rectangle' =    tukey(0)
    0045 %    'reisz'     =    triangle(2)
    0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0047 %
    0048 % The MODE input determines the scaling and sampling of the window function and
    0049 %     is a text string with characters whose meanings are given below. The
    0050 %     default is 'ubw' for window functions whose end points are non-zero and 'unw'
    0051 %     for window functions whose end points are zero (e.g. hanning window)
    0052 %
    0053 %         scaling:
    0054 %                1-9 = set target gain to G = 1/n in scaling options [default n=1 so G=1]
    0055 %                  u = unscaled  with the peak of the underlying continuous
    0056 %                      window equalling G. [default]
    0057 %                  p = scaled to make the actual peak G
    0058 %                  d = scaled to make DC gain equal to G (summed sample values).
    0059 %                  D = scaled to make average value equal G
    0060 %                  e = scaled to make energy = G (summed squared sample values).
    0061 %                  E = scaled to make mean energy = G (mean squared sample values).
    0062 %                  q = take square root of the window after scaling
    0063 %
    0064 %         first and last samples (see note on periodicity below):
    0065 %                  b [both]    = The first and last samples are at the extreme ends of
    0066 %                                the window [default for most windows].
    0067 %                  n [neither] = The first and last samples are one sample away from the ends
    0068 %                                of the window [default for windows having zero end points].
    0069 %                  s [shifted] = The first and last samples are half a sample away from the
    0070 %                                ends of the window .
    0071 %                  l [left]    = The first sample is at the end of the window while the last
    0072 %                                is one sample away from the end .
    0073 %                  r [right]   = The first sample is one sample away from the end while the
    0074 %                                last is at the end of the window .
    0075 %
    0076 %         whole/half window (see note on periodicity below):
    0077 %                  w = The whole window is included [default]
    0078 %                  c = The first sample starts in the centre of the window
    0079 %                  h = The first sample starts half a sample beyond the centre
    0080 %                  v = The n input is a vector of window positions where window goes from -1 to +1
    0081 %                  V = The n input is a vector of window positions where window goes from 0 to +1
    0082 %
    0083 %         convolve with rectangle
    0084 %                  o = convolve w(n) with a rectangle of length N-H [default floor(N/2)]
    0085 %                      This can be used to force w(n) to satisfy the Princen-Bradley condition
    0086 %
    0087 % Periodicity:
    0088 %     The underlying period of the window function depends on the chosen mode combinations and
    0089 %     is given in the table below. For overlapping windows with perfect reconstruction choose
    0090 %     N to be an integer and modes 'ws', 'wl' or 'wr'.
    0091 %
    0092 %        Whole/half window -->     w         h         c
    0093 %
    0094 %        End points:       b      N-1      2N-1      2N-2
    0095 %                          n      N+1      2N+1       2N
    0096 %                          s       N        2N       2N-1
    0097 %                          l       N       2N+1       2N
    0098 %                          r       N       2N-1      2N-2
    0099 %
    0100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0101 % To obtain unity gain for windowed overlap-add processing you can use
    0102 % the following. Bandwidths have been multiplied by the window length.
    0103 % For perfect reconstruction, you can use any multiple of the overlap factors
    0104 % shown assuming the same window is used for both analysis and synthesis.
    0105 % These are the Princen-Bradley conditions: fliplr(w)=w, w(i)^2+w(i+n/2)^2=1
    0106 % Any symmetric window will satisfy the conditions with mode 'boqD2' [3].
    0107 %
    0108 %   Window     Mode Overlap-Factor Sidelobe  3dB-BW  6dB-BW Equiv-noise-BW
    0109 %   rectangle  E        1           -13dB     0.9      1.2      1.0
    0110 %   rsqvorbis  sqD2     2           -26dB     1.1      1.5      1.1
    0111 %   hamming    sqD2     2,3,5       -24dB     1.1      1.5      1.1
    0112 %   hanning    sqD2     2,3,5       -23dB     1.2      1.6      1.2 =cos('sE2')
    0113 %   cos        sE2      2,3,5       -23dB     1.2      1.6      1.2 used in MP3
    0114 %   kaiser(5)  boqD2    2           -23dB     1.2      1.7      1.3 used in AAC [4]
    0115 %   vorbis     sE2      2,9,15      -21dB     1.3      1.8      1.4 used in Vorbis
    0116 %   hamming    sE4      3,4,5       -43dB     1.3      1.8      1.4
    0117 %   hanning    sE4      3,4,5       -31dB     1.4      2.0      1.5
    0118 % The integer following D or E in the mode string should match the overlap factor
    0119 %
    0120 % References:
    0121 %  [1]  F. J. Harris. On the use of windows for harmonic analysis with the
    0122 %       discrete fourier transform. Proc IEEE, 66 (1): 51-83, Jan. 1978.
    0123 %  [2]    L. D. Fielder, M. Bosi, G. Davidson, M. Davis, C. Todd, and S. Vernon.
    0124 %       AC-2 and AC-3: Low-complexity transform-based audio coding.
    0125 %       In Audio Engineering Society Conference: Collected Papers on Digital Audio Bit-Rate Reduction, May 1996.
    0126 %  [3]    J. Princen, A. Johnson, and A. Bradley. Subband/transform coding using filter
    0127 %       bank designs based on time domain aliasing cancellation.
    0128 %       In Proc. IEEE Intl Conf. Acoustics, Speech and Signal Processing, volume 12,
    0129 %       pages 2161-2164, 1987. doi: 10.1109/ICASSP.1987.1169405.
    0130 %  [4]    T. Sporer, K. Brandenburg, and B. Edler.
    0131 %       The use of multirate filter banks for coding of high quality digital audio.
    0132 %       In Proc EUSIPCO, volume 1, pages 211-214, 1992.
    0133 %
    0134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0135 %      Copyright (C) Mike Brookes 2002-2015
    0136 %      Version: $Id: v_windows.m 10477 2018-06-03 16:16:45Z dmb $
    0137 %
    0138 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0139 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0140 %
    0141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0142 %   This program is free software; you can redistribute it and/or modify
    0143 %   it under the terms of the GNU Lesser General Public License as published by
    0144 %   the Free Software Foundation; either version 3 of the License, or
    0145 %   (at your option) any later version.
    0146 %
    0147 %   This program is distributed in the hope that it will be useful,
    0148 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0149 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0150 %   GNU Lesser General Public License for more details.
    0151 %
    0152 %   You can obtain a copy of the GNU Lesser General Public License from
    0153 %   https://www.gnu.org/licenses/ .
    0154 %
    0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0156 persistent wnam wnami wnamp
    0157 if isempty(wnam)
    0158     wnam={'rectangle','hann','hamming','harris3','harris4','blackman',...
    0159         'vorbis','rsqvorbis','triangle','cos','kaiser','gaussian',...
    0160         'cauchy','dolph','tukey','hanning','vonhann','r','n','m','3','4','b','v','w','t','c','k','g','y','d','u'};
    0161     wnami=[1:15 2 2 1:15];
    0162     wnamp=[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1]; % parameters required
    0163 end
    0164 kk=[-1 1 1 -1; 0 0 2 -2; 0 1 2 -1;    % mode  w,  h,  c  [normal windows]
    0165     -1 0 1 0; 0 0 2 0; 0 1 2 1;       % modes lw, lh, lc
    0166     -1 2 1 0; 0 0 2 -2; 0 1 2 -1;     % modes rw, rh, rc
    0167     -1 1 1 -1; 0 0 2 -2; 0 1 2 -1;    % modes bw, bh, bc
    0168     -1 1 1 1; 0 0 2 0; 0 1 2 1;       % modes nw, nh, nc
    0169     -1 1 1 0; 0 0 2 -1; 0 1 2 0;];    % modes sw, sh, sc
    0170
    0171 if nargin<2 || isempty(n)
    0172     n=2520;                         % 2^3 * 3^2 * 5 * 7
    0173 end
    0174 if nargin<3 || isempty(mode) || ~ischar(mode)
    0175     mode='uw';                      % default to unscaled full window
    0176 end
    0177 mm=zeros(1,length(mode)+1);
    0178 ll='hc lrbns';
    0179 for i=1:8
    0180     mm(mode==ll(i))=i-3;
    0181 end
    0182 if ischar(wtype)
    0183     wtype=wnami(find(strcmpi(lower(wtype),wnam),1)); % convert window type to integer
    0184 end
    0185 k=1+3*max(mm)-min(mm);              % min(mm) gives whole/half window, max(mm) gives window positioning
    0186 if k<4
    0187     k=k+12*any(wtype==[2 6 7 9 10 15]); % if window is zero at ends add 12 to default to the 'n' option
    0188 end
    0189 % determine the sample points
    0190 if any(lower(mode)=='v')
    0191     ov=0; % do not convolve with rectangle
    0192     if wtype==14
    0193         error('cannot use ''v'' option with dolph window');
    0194     end
    0195     if any(mode=='v')
    0196         v=mod(n(:)'+1,2)-1; % input N is winodw position in range -1 to +1
    0197     else
    0198         v=2*mod(n(:)',1)-1;  % input N is winodw position in range 0 to +1
    0199     end
    0200     n=length(v);
    0201 else
    0202     if any(mode=='o')                   % need to convolve with rectangle
    0203         if nargin<5 || ~numel(h)
    0204             ov=floor(n/2);
    0205         end
    0206         n=n-ov+1;                       % shorten baseline window
    0207     else
    0208         ov=0;
    0209     end
    0210     % the number of points corresponding to a full period is (kk(k,3)*n+kk(k,4))
    0211     fn=floor(n);
    0212     kp=(kk(k,3)*n+kk(k,4)); % number of points corresponding to a full period
    0213     ks=kk(k,1)*fn+kk(k,2);
    0214     v=((0:2:2*fn-2)+ks)/kp;
    0215 end
    0216
    0217 % now make the window; v has positions int he range -1 to 1
    0218
    0219 switch wtype
    0220     case 1 % 'rectangle'
    0221         w = ones(size(v));
    0222     case 2 % 'hanning'
    0223         w = 0.5+0.5*cos(pi*v);
    0224     case 3 % 'hamming'
    0225         w = 0.54+0.46*cos(pi*v);
    0226     case 4 % 'harris3'
    0227         w = 0.42323 + 0.49755*cos(pi*v) + 0.07922*cos(2*pi*v);
    0228     case 5 % 'harris4'
    0229         w = 0.35875 + 0.48829*cos(pi*v) + 0.14128*cos(2*pi*v) + 0.01168*cos(3*pi*v);
    0230     case 6 % 'blackman'
    0231         w = 0.42+0.5*cos(pi*v) + 0.08*cos(2*pi*v);
    0232     case 7 % 'vorbis'
    0233         w = sin(0.25*pi*(1+cos(pi*v)));
    0234     case 8 % 'rsqvorbis'
    0235         w = 0.571-0.429*cos(0.5*pi*(1+cos(pi*v)));
    0236     case 9 % 'triangle'
    0237         if nargin<4, p=1; end;
    0238         w = 1-abs(v).^p(1);
    0239     case 10 % 'cos'
    0240         if nargin<4, p=1; end;
    0241         w = cos(0.5*pi*v).^p(1);
    0242     case 11 % 'kaiser'
    0243         if nargin<4, p=8; end;
    0244         w=besseli(0,p*sqrt(1-v.^2))/besseli(0,p(1));
    0245     case 12 % 'gaussian'
    0246         if nargin<4, p=3; end;
    0247         w=exp(-0.5*p(1)^2*(v.*v));
    0248     case 13 % 'cauchy'
    0249         if nargin<4, p=1; end;
    0250         w = (1+(p(1)*v).^2).^-1;
    0251     case 14 % 'dolph'
    0252         if nargin<4, p=50; end;
    0253         if rem(ks+kp,2)     % for shifted windows, we generate twice as many points
    0254             w=chebwin(2*kp+1,abs(p(1)));
    0255             w=w((1:2:2*fn)+round(ks+kp));
    0256         else
    0257             w=chebwin(kp+1,abs(p(1)));
    0258             w=w((1:fn)+round((ks+kp)/2));
    0259         end
    0260         w=w(:)'; % convert to row vector
    0261     case 15 % 'tukey'
    0262         if nargin<4, p=0.5; end;
    0263         if p(1)>0
    0264             p(1)=min(p(1),1);
    0265             w = 0.5+0.5*cos(pi*max(1+(abs(v)-1)/p(1),0));
    0266         else
    0267             w = ones(size(v));
    0268         end
    0269     otherwise
    0270         error(sprintf('Unknown window type: %s', wtype));
    0271 end;
    0272 % now convolve with rectangle
    0273 if ov
    0274     %     w=filter(ones(1,ov),1,w); % more adds but might be just as efficient as cumsum
    0275     w=cumsum(w);
    0276     w(n+1:n+ov-1)=w(n)-w(n-ov+1:n-1);
    0277     w(ov+1:n)=w(ov+1:n)-w(1:n-ov);
    0278     n=n+ov-1; % restore original value of n
    0279 end
    0280 % scale if required
    0281 mk=find(mode>='1' & mode<='9',1);
    0282 if numel(mk)
    0283     g=1/(mode(mk)-'0');
    0284 else
    0285     g=1;
    0286 end
    0287 if any(mode=='d')
    0288     w=w*(g/sum(w));
    0289 elseif any(mode=='D') || any(mode=='a')
    0290     w=w*(g/mean(w));
    0291 elseif any(mode=='e')
    0292     w=w*sqrt(g/sum(w.^2));
    0293 elseif any(mode=='E')
    0294     w=w*sqrt(g/mean(w.^2));
    0295 elseif any(mode=='p')
    0296     w=w*(g/max(w));
    0297 end
    0298 if any(mode=='q')
    0299     w=sqrt(w);
    0300 end
    0301 if ~nargout
    0302     v_windinfo(w,n);
    0303     np=wnamp(wtype); % number of parameters
    0304     if np>0
    0305         title(sprintf('%s(%s) window  - mode=''%s''',wnam{wtype},sprintf('%g',p(1:np)),mode));
    0306     else
    0307         title(sprintf('%s window - mode=''%s''',wnam{wtype},mode));
    0308     end
    0309 end
    0310