WINDOWS Generate a standard windowing function (TYPE,N,MODE,P,H) Inputs: WTYPE is a string 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] 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 'v' option) [default floor(N/2)] Outputs: W(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 (see [1]): Name Params 'blackman' 'cauchy' 1 'cos' 1 cos window to the power P [default P=1] 'dolph' 1 Dolph-Chebyshev window with sideband attenuation P dB [default P=50] 'gaussian' 1 truncated at +-P std deviations [default P=3] 'hamming' 'hanning' also called "hann" or "von hann" 'harris3' 3-term blackman-harris with 67dB sidelobes 'harris4' 4-term blackman-harris with 92dB sidelobes 'kaiser' 1 with parameter P (often called beta) [default P=8] 'rectangle' 'triangle' 1 triangle to the power P [default P=1] 'tukey' 1 cosine tapered 0<P<1 [default P=0.5] 'vorbis' perfect reconstruction window from [2] (use mode='sE2') 'rsqvorbis' raised squared vorbis with lower sidelobes (use mode='sdD2') Window equivalences: 'hanning' = cospow(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 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 coinditions with mode 'boqD2' [3]. Window Mode Overlap-Factor Sidelobe 3dB-BW 6dB-BW Equiv-noise-BW rsqvorbis sqD2 2 -26dB 1.1 1.5 1.1 hamming sqD2 2,3,5 -24dB 1.1 1.5 1.1 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 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 6808 2015-09-13 11:22:27Z 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 General Public License as published by the Free Software Foundation; either version 2 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 can obtain a copy of the GNU General Public License from http://www.gnu.org/copyleft/gpl.html or by writing to Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

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

Generated on Tue 10-Oct-2017 08:30:10 by