# v_frq2erb

## PURPOSE

V_FRQ2ERB Convert Hertz to ERB frequency scale ERB=(FRQ)

## SYNOPSIS

function [erb,bnd] = v_frq2erb(frq)

## DESCRIPTION

    V_FRQ2ERB  Convert Hertz to ERB frequency scale ERB=(FRQ)
        erb = v_frq2erb(frq) converts a vector of frequencies (in Hz)
        to the corresponding values on the ERB-rate scale on which
          the human ear has roughly constant resolution as judged by
          psychophysical measurements of the cochlear filters. The
       inverse function is v_erb2frq.

## CROSS-REFERENCE INFORMATION

This function calls:

- v_xticksi V_XTIXKSI labels the x-axis of a plot using SI multipliers S=(AH)
- 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 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 [erb,bnd] = v_frq2erb(frq)
    0002 %V_FRQ2ERB  Convert Hertz to ERB frequency scale ERB=(FRQ)
    0003 %    erb = v_frq2erb(frq) converts a vector of frequencies (in Hz)
    0004 %    to the corresponding values on the ERB-rate scale on which
    0005 %      the human ear has roughly constant resolution as judged by
    0006 %      psychophysical measurements of the cochlear filters. The
    0007 %   inverse function is v_erb2frq.
    0008
    0009 %   The erb scale is measured using the notched-noise method [3].
    0010 %
    0011 %    We have df/de = 6.23*f^2 + 93.39*f + 28.52
    0012 %    where the above expression gives the Equivalent Rectangular
    0013 %    Bandwidth (ERB)in Hz  of a human auditory filter with a centre
    0014 %    frequency of f kHz.
    0015 %
    0016 %    By integrating the reciprocal of the above expression, we
    0017 %    get:
    0018 %        e = a ln((f/p-1)/(f/q-1))
    0019 %
    0020 %    where p and q are the roots of the equation: -0.312 and -14.7
    0021 %      and a = 1000/(6.23*(p-q)) = 11.17268
    0022 %
    0023 %    We actually implement e as
    0024 %
    0025 %        e = a ln (h - k/(f+c))
    0026 %
    0027 %    where k = 1000(q - q^2/p) = 676170.42
    0028 %         h = q/p = 47.065
    0029 %          c = -1000q = 14678.49
    0030 %    and f is in Hz
    0031 %
    0032 %    References:
    0033 %
    0034 %      [1] B.C.J.Moore & B.R.Glasberg "Suggested formula for
    0035 %          calculating auditory-filter bandwidth and excitation
    0036 %          patterns", J Acoust Soc America V74, pp 750-753, 1983
    0037 %      [2] O. Ghitza, "Auditory Models & Human Performance in Tasks
    0038 %          related to Speech Coding & Speech Recognition",
    0039 %          IEEE Trans on Speech & Audio Processing, Vol 2,
    0040 %          pp 115-132, Jan 1994
    0041 %     [3] R. D. Patterson. Auditory filter shapes derived with noise
    0042 %         stimuli. J. Acoust. Soc. Amer., 59:640-654, 1976.
    0043 %     [4] B. Glasberg and B. Moore. Derivation of auditory filter shapes from
    0044 %         notched-noise data. Hearing Research, 47(1-2):103–138, 1990.
    0045 %         doi: 10.1016/0378-5955(90)90170-T.
    0046
    0047 %      Copyright (C) Mike Brookes 1998-2015
    0048 %      Version: $Id: v_frq2erb.m 10865 2018-09-21 17:22:45Z dmb $
    0049 %
    0050 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0051 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0052 %
    0053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0054 %   This program is free software; you can redistribute it and/or modify
    0055 %   it under the terms of the GNU Lesser General Public License as published by
    0056 %   the Free Software Foundation; either version 3 of the License, or
    0057 %   (at your option) any later version.
    0058 %
    0059 %   This program is distributed in the hope that it will be useful,
    0060 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0061 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0062 %   GNU Lesser General Public License for more details.
    0063 %
    0064 %   You can obtain a copy of the GNU Lesser General Public License from
    0065 %   https://www.gnu.org/licenses/ .
    0066 %
    0067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0068 persistent u a h k c
    0069 if ~numel(u)
    0070     u=[6.23e-6 93.39e-3 28.52];     % from equation (3) in [1] (an simpler formula is (3) in [4])
    0071     p=sort(roots(u));               % p=[-14678.5 -311.9]
    0072     a=1e6/(6.23*(p(2)-p(1)));       % a=11.17
    0073     c=p(1);                         % c=-14678.5
    0074     k = p(1) - p(1)^2/p(2);         % k=676170.42
    0075     h=p(1)/p(2);                    % h=47.065
    0076 end
    0077 g=abs(frq);
    0078 % erb=11.17268*sign(frq).*log(1+46.06538*g./(g+14678.49));
    0079 erb=a*sign(frq).*log(h-k./(g-c));
    0080 bnd=polyval(u,g);
    0081 if ~nargout
    0082     plot(frq,erb,'-x');
    0083     xlabel(['Frequency (' v_xticksi 'Hz)']);
    0084     ylabel(['Frequency (' v_yticksi 'Erb-rate)']);
    0085 end