Home > v_mfiles > v_bark2frq.m

# v_bark2frq

## PURPOSE

V_BARK2FRQ Convert the BARK frequency scale to Hertz FRQ=(BARK)

## SYNOPSIS

function [f,c] = v_bark2frq(b,m)

## DESCRIPTION

```V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)

Inputs: b  matrix of frequencies in Bark
m  mode options
'h'   use high frequency correction from [1]
'l'   use low frequency correction from [1]
'H'   do not apply any high frequency correction
'L'   do not apply any low frequency correction
'u'   unipolar version: do not force b to be an odd function
This has no effect on the default function which is odd anyway
's'   use the expression from Schroeder et al. (1979)
'g'   plot a graph

Outputs: f  frequency values in Hz
c  Critical bandwidth: d(freq)/d(bark)```

## CROSS-REFERENCE INFORMATION

This function calls:
• v_frq2bark V_FRQ2BARK Convert Hertz to BARK frequency scale BARK=(FRQ)
• v_yticksi V_YTIXKSI labels the y-axis of a plot using SI multipliers S=(AH)
This function is called by:
• v_filtbankm V_FILTBANKM determine matrix for a linear/mel/erb/bark-spaced v_filterbank [X,IL,IH]=(P,N,FS,FL,FH,W)
• v_gammabank V_GAMMABANK gammatone filter bank [b,a,fx,bx,gd]=(n,fs,w,fc,bw,ph,k)
• v_melbankm V_MELBANKM determine matrix for a mel/erb/bark-spaced v_filterbank [X,MN,MX]=(P,N,FS,FL,FH,W)
• v_spgrambw V_SPGRAMBW Draw spectrogram [T,F,B]=(s,fs,mode,bw,fmax,db,tinc,ann)

## SOURCE CODE

```0001 function [f,c] = v_bark2frq(b,m)
0002 %V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)
0003 %
0004 % Inputs: b  matrix of frequencies in Bark
0005 %         m  mode options
0006 %            'h'   use high frequency correction from [1]
0007 %            'l'   use low frequency correction from [1]
0008 %            'H'   do not apply any high frequency correction
0009 %            'L'   do not apply any low frequency correction
0010 %            'u'   unipolar version: do not force b to be an odd function
0011 %                  This has no effect on the default function which is odd anyway
0012 %            's'   use the expression from Schroeder et al. (1979)
0013 %            'g'   plot a graph
0014 %
0015 % Outputs: f  frequency values in Hz
0016 %          c  Critical bandwidth: d(freq)/d(bark)
0017
0018 %   The Bark scale was defined by an ISO committee and published in [2]. It
0019 %   was based on a varienty of experiments on the thresholds for complex
0020 %   sounds, masking, perception of phase and the loudness of complex
0021 %   sounds. The Bark scale is named in honour of Barkhausen, the creator
0022 %   of the unit of loudness level [2]. Critical band k extends
0023 %   from v_bark2frq(k-1) to v_bark2frq(k). The inverse function is v_frq2bark.
0024 %
0025 %   There are many published formulae approximating the Bark scale.
0026 %   The default is the one from [1] but with a correction at high and
0027 %   low frequencies to give a better fit to [2] with a continuous derivative
0028 %   and ensure that 0 Hz = 0 Bark.
0029 %   The h and l mode options apply the corrections from [1] which are
0030 %   not as good and do not give a continuous derivative. The H and L
0031 %   mode options suppress the correction entirely to give a simple formula.
0032 %   The 's' option uses the less accurate formulae from [3] which have been
0033 %   widely used in the lterature.
0034 %
0035 %   [1] H. Traunmuller, Analytical Expressions for the
0036 %       Tonotopic Sensory Scale�, J. Acoust. Soc. Am. 88,
0037 %       1990, pp. 97-100.
0038 %   [2] E. Zwicker, Subdivision of the audible frequency range into
0039 %       critical bands, J Accoust Soc Am 33, 1961, p248.
0040 %   [3] M. R. Schroeder, B. S. Atal, and J. L. Hall. Optimizing digital
0041 %       speech coders by exploiting masking properties of the human ear.
0042 %       J. Acoust Soc Amer, 66 (6): 1647�1652, 1979. doi: 10.1121/1.383662.
0043
0044 %      Copyright (C) Mike Brookes 2006-2010
0045 %      Version: \$Id: v_bark2frq.m 10865 2018-09-21 17:22:45Z dmb \$
0046 %
0047 %   VOICEBOX is a MATLAB toolbox for speech processing.
0049 %
0050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051 %   This program is free software; you can redistribute it and/or modify
0052 %   it under the terms of the GNU General Public License as published by
0053 %   the Free Software Foundation; either version 2 of the License, or
0054 %   (at your option) any later version.
0055 %
0056 %   This program is distributed in the hope that it will be useful,
0057 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0058 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0059 %   GNU General Public License for more details.
0060 %
0061 %   You can obtain a copy of the GNU General Public License from
0062 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0063 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0065 persistent A B C E D P Q R S T U V W X Y Z
0066 if isempty(P)
0067     A=26.81;
0068     B=1960;
0069     C=-0.53;
0070     E = A+C;
0071     D=A*B;
0072     P=(0.53/(3.53)^2);
0073     V=3-0.5/P;
0074     W=V^2-9;
0075     Q=0.25;
0076     R=20.4;
0077     xy=2;
0078     S=0.5*Q/xy;
0079     T=R+0.5*xy;
0080     U=T-xy;
0081     X = T*(1+Q)-Q*R;
0082     Y = U-0.5/S;
0083     Z=Y^2-U^2;
0084 end
0085 if nargin<2
0086     m=' ';
0087 end
0088 if any(m=='u')
0089     a=b;
0090 else
0091     a=abs(b);
0092 end
0093 if any(m=='s')
0094     f=650*sinh(a/7);
0095 else
0096     if any(m=='l')
0097         m1=(a<2);
0098         a(m1)=(a(m1)-0.3)/0.85;
0099     elseif ~any(m=='L')
0100         m1=(a<3);
0101         a(m1)=V+sqrt(W+a(m1)/P);
0102     end
0103     if any(m=='h')
0104         m1=(a>20.1);
0105         a(m1)=(a(m1)+4.422)/1.22;
0106     elseif ~any(m=='H')
0107         m2=(a>X);
0108         m1=(a>U) & ~m2;
0109         a(m2)=(a(m2)+Q*R)/(1+Q);
0110         a(m1)=Y+sqrt(Z+a(m1)/S);
0111     end
0112     f=(D*(E-a).^(-1)-B);
0113 end
0114 if ~any(m=='u')
0115     f=f.*sign(b);          % force to be odd
0116 end
0117 if nargout>1
0118     [bx,c] = v_frq2bark(f,m);
0119 end
0120 if ~nargout || any(m=='g')
0121     [bx,c] = v_frq2bark(f,m);
0122     subplot(212)
0123     semilogy(b,c,'-r');
0124     ha=gca;
0125     xlabel('Bark');
0126     ylabel(['Critical BW (' v_yticksi 'Hz)']);
0127     subplot(211)
0128     plot(b,f,'x-b');
0129     hb=gca;
0130     xlabel('Bark');
0131     ylabel(['Frequency (' v_yticksi 'Hz)']);