Skip to content

Commit

Permalink
added also auditory files
Browse files Browse the repository at this point in the history
  • Loading branch information
allthatsounds committed Nov 2, 2023
1 parent fa9c6d6 commit 2cd5805
Show file tree
Hide file tree
Showing 14 changed files with 747 additions and 0 deletions.
76 changes: 76 additions & 0 deletions sigproc/audfiltbw.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function bw = audfiltbw(fc,varargin)
%AUDFILTBW Bandwidth of auditory filter
% Usage: bw = audfiltbw(fc)
%
% `audfiltbw(fc)` returns the critical bandwidth of the auditory filter
% at center frequency *fc* defined in equivalent rectangular bandwidth.
% The function uses the relation:
%
% .. bw = 24.7 + fc/9.265
%
% .. math:: bw = 24.7 + \frac{fc}{9.265}
%
% as estimated in Glasberg and Moore (1990). This function is also used
% when the original ERB scale ('erb83') is chosen.
%
% `audfiltbw(fc,'bark')` returns the critical bandwidth at *fc* according
% to the Bark scale using the relation:
%
% .. bw = 25 + 75 ( 1+1.4*10^{-6} fc^2 )^0.69
%
% .. math:: bw = 25 + 75 ( 1+1.4\times10^{-6} fc^2 )^{0.69}
%
% as estimated by Zwicker and Terhardt (1980).
%
% For the scales 'mel', 'mel1000', 'log10' and 'semitone', no critical
% bandwidth function is usually given. Following the example of the
% equivalent rectangular bandwidth (associated with the ERB scale), we
% use the derivative of the inverse of the scale function F_{Scale},
% evaluated at F_{Scale}(fc), i.e.
%
% .. bw = (F_{scale}^{-1})'(F_{scale}(fc))
%
% .. math:: bw = (F_{scale}^{-1})'(F_{scale}(fc))
%
% See also: freqtoerb, erbspace, freqtoaud, audtofreq
%
% References: glasberg1990daf zwickerterhardt80

% AUTHOR : Peter L. Søndergaard

% ------ Checking of input parameters ---------

% narginchk(1,1);
if nargin<1
error('%s: Too few input parameters.',upper(mfilename));
end;

if ~isnumeric(fc) || any(fc(:)<0)
error('AUDFILTBW: fc must be non-negative.');
end;

definput.flags.audscale={'erb','erb83','bark','mel','mel1000','log10','semitone'};
[flags,kv]=ltfatarghelper({},definput,varargin);

% ------ Computation --------------------------

% FIXME: What is the upper frequency for which the estimation is valid?
if flags.do_erb || flags.do_erb83
bw = 24.7 + fc/9.265;
end

if flags.do_bark
bw = 25 + 75*(1 + 1.4E-6*fc.^2).^0.69;
end

if flags.do_mel
bw = log(17/7)*(700+fc)/1000;
end

if flags.do_mel1000
bw = log(2)*(1+fc/1000);
end;

if flags.do_log10 || flags.do_semitone
bw = fc;
end
2 changes: 2 additions & 0 deletions sigproc/auditoryinit.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
status=1;

60 changes: 60 additions & 0 deletions sigproc/audspace.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function [y,bw] = audspace(fmin,fmax,n,varargin)
%AUDSPACE Equidistantly spaced points on auditory scale
% Usage: y=audspace(fmin,fmax,n,scale);
%
% `audspace(fmin,fmax,n,scale)` computes a vector of length *n*
% containing values equidistantly scaled on the selected auditory scale
% between the frequencies *fmin* and *fmax*. All frequencies are
% specified in Hz.
%
% See the help on |freqtoaud| to get a list of the supported values of the
% *scale* parameter.
%
% `[y,bw]=audspace(...)` does the same but outputs the bandwidth between
% each sample measured on the selected scale.
%
% See also: freqtoaud, audspacebw, audfiltbw

% AUTHOR : Peter L. Søndergaard

%% ------ Checking of input parameters ---------

if nargin<3
error('%s: Too few input parameters.',upper(mfilename));
end;

% Default parameters.

if ~isnumeric(fmin) || ~isscalar(fmin)
error('%s: fmin must be a scalar.',upper(mfilename));
end;

if ~isnumeric(fmax) || ~isscalar(fmax)
error('%s: fmax must be a scalar.',upper(mfilename));
end;

if ~isnumeric(n) || ~isscalar(n) || n<=0 || fix(n)~=n
error('%s: n must be a positive, integer scalar.',upper(mfilename));
end;

if fmin>fmax
error('%s: fmin must be less than or equal to fmax.',upper(mfilename));
end;

definput.import={'freqtoaud'};
[flags,kv]=ltfatarghelper({},definput,varargin);


%% ------ Computation --------------------------

audlimits = freqtoaud([fmin,fmax],flags.audscale);

y = audtofreq(linspace(audlimits(1),audlimits(2),n),flags.audscale);

bw=(audlimits(2)-audlimits(1))/(n-1);

% Set the endpoints to be exactly what the user specified, instead of the
% calculated values
y(1)=fmin;
y(end)=fmax;

90 changes: 90 additions & 0 deletions sigproc/audspacebw.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
function [y,n] = audspacebw(fmin,fmax,varargin)
%AUDSPACEBW Auditory scale points specified by bandwidth
% Usage: y=audspacebw(fmin,fmax,bw,hitme);
% y=audspacebw(fmin,fmax,bw);
% y=audspacebw(fmin,fmax);
% [y,n]=audspacebw(...);
%
% `audspacebw(fmin,fmax,bw,scale)` computes a vector containing values
% equistantly scaled between frequencies *fmin* and *fmax* on the
% selected auditory scale. All frequencies are specified in Hz.The
% distance between two consecutive values is *bw* on the selected scale,
% and the points will be centered on the scale between *fmin* and *fmax*.
%
% See the help on |freqtoaud| to get a list of the supported values of the
% *scale* parameter.
%
% `audspacebw(fmin,fmax,bw,hitme,scale)` will do as above, but one of
% the points is quaranteed to be the frequency *hitme*.
%
% `[y,n]=audspacebw(...)` additionally returns the number of points *n* in
% the output vector *y*.
%
% See also: freqtoaud, audspace, audfiltbw

% AUTHOR : Peter L. Søndergaard

% ------ Checking of input parameters ---------

if nargin<2
error('%s: Too few input parameters.',upper(mfilename));
end;

if ~isnumeric(fmin) || ~isscalar(fmin) || fmin<0
error('%s: fmin must be a non-negative scalar.',upper(mfilename));
end;

if ~isnumeric(fmax) || ~isscalar(fmax) || fmax<0
error('%s: fmax must be a non-negative scalar.',upper(mfilename));
end;

if fmin>fmax
error('%s: fmin must be less than or equal to fmax.',upper(mfilename));
end;

definput.import={'freqtoaud'};
definput.keyvals.hitme=[];
definput.keyvals.bw=1;

[flags,kv,bw]=ltfatarghelper({'bw','hitme'},definput,varargin);

if ~isnumeric(bw) || ~isscalar(bw) || bw<=0
error('%s: bw must be a positive scalar.',upper(mfilename));
end;


%% ------ Computation --------------------------

if isempty(kv.hitme)
% Convert the frequency limits to auds.
audlimits = freqtoaud([fmin,fmax],flags.audscale);
audrange = audlimits(2)-audlimits(1);

% Calculate number of points, excluding final point
n = floor(audrange/bw);

% The remainder is calculated in order to center the points
% correctly between fmin and fmax.
remainder = audrange-n*bw;

audpoints = audlimits(1)+(0:n)*bw+remainder/2;

% Add the final point
n=n+1;

else

% Convert the frequency limits to auds.
audlimits = freqtoaud([fmin,fmax,kv.hitme],flags.audscale);
audrangelow = audlimits(3)-audlimits(1);
audrangehigh = audlimits(2)-audlimits(3);

% Calculate number of points, exluding final point.
nlow = floor(audrangelow/bw);
nhigh = floor(audrangehigh/bw);

audpoints=(-nlow:nhigh)*bw+audlimits(3);
n=nlow+nhigh+1;
end;

y = audtofreq(audpoints,flags.audscale);
60 changes: 60 additions & 0 deletions sigproc/audtofreq.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function freq = audtofreq(aud,varargin)
%AUDTOFREQ Converts auditory units to frequency (Hz)
% Usage: freq = audtofreq(aud);
%
% `audtofreq(aud,scale)` converts values on the selected auditory scale to
% frequencies measured in Hz.
%
% See the help on |freqtoaud| to get a list of the supported values of
% the *scale* parameter. If no scale is given, the erb-scale will be
% selected by default.
%
% See also: freqtoaud, audspace, audfiltbw

% AUTHOR: Peter L. Søndergaard

%% ------ Checking of input parameters ---------

if nargin<1
error('%s: Too few input parameters.',upper(mfilename));
end;


if ~isnumeric(aud)
error('%s: aud must be a number.',upper(mfilename));
end;

definput.import={'freqtoaud'};
[flags,kv]=ltfatarghelper({},definput,varargin);

%% ------ Computation --------------------------

if flags.do_mel
freq = 700*sign(aud).*(exp(abs(aud)*log(17/7)/1000)-1);
end;

if flags.do_mel1000
freq = 1000*sign(aud).*(exp(abs(aud)*log(2)/1000)-1);
end;

if flags.do_erb
freq = (1/0.00437)*sign(aud).*(exp(abs(aud)/9.2645)-1);
end;

if flags.do_bark
% This one was found through http://www.ling.su.se/STAFF/hartmut/bark.htm
freq = sign(aud).*1960./(26.81./(abs(aud)+0.53)-1);
end;

if flags.do_erb83
%freq = 14363./(1-exp((aud-43.0)/11.7))-14675;
freq = sign(aud).*14675.*(1-exp(0.0895255*abs(aud)))./(exp(0.0895255*abs(aud)) - 47.0353);
end;

if flags.do_freq
freq=aud;
end;

if flags.do_log10 || flags.do_semitone
freq = 10^(aud);
end
13 changes: 13 additions & 0 deletions sigproc/erbspace.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function [y,bw] = erbspace(fmin,fmax,n)
%ERBSPACE Equidistantly spaced points on erbscale
% Usage: y=erbspace(fmin,fmax,n);
%
% This is a wrapper around |audspace| that selects the erb-scale. Please
% see the help on |audspace| for more information.
%
% See also: audspace, freqtoaud

% AUTHOR : Peter L. Søndergaard

[y,bw] = audspace(fmin,fmax,n,'erb');

14 changes: 14 additions & 0 deletions sigproc/erbspacebw.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function [y,n] = erbspacebw(fmin,fmax,varargin)
%ERBSPACEBW Erbscale points specified by bandwidth
% Usage: y=erbspacebw(fmin,fmax,bw,hitme);
% y=erbspacebw(fmin,fmax,bw);
% y=erbspacebw(fmin,fmax);
%
% This is a wrapper around |audspacebw| that selects the erb-scale. Please
% see the help on |audspacebw| for more information.
%
% See also: audspacebw, freqtoaud

% AUTHOR : Peter L. Søndergaard

[y,n] = audspacebw(fmin,fmax,varargin{:},'erb');
21 changes: 21 additions & 0 deletions sigproc/erbtofreq.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function freq = erbtofreq(erb);
%ERBTOFREQ Converts erb units to frequency (Hz)
% Usage: freq = erbtofreq(erb);
%
% This is a wrapper around |audtofreq| that selects the erb-scale. Please
% see the help on |audtofreq| for more information.
%
% The following figure shows the corresponding frequencies for erb
% values up to 31:::
%
% erbs=0:31;
% freqs=erbtofreq(erbs);
% plot(erbs,freqs);
% xlabel('Frequency / erb');
% ylabel('Frequency / Hz');
%
% See also: audtofreq, freqtoaud

% AUTHOR: Peter L. Søndergaard

freq = audtofreq(erb,'erb');
Loading

0 comments on commit 2cd5805

Please sign in to comment.