tomwalters@0
|
1 % support file for 'aim-mat'
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % (c) 2011, University of Southampton
|
bleeck@3
|
4 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
5 % download of current version is on the soundsoftware site:
|
bleeck@3
|
6 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
7 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
8
|
tomwalters@0
|
9
|
tomwalters@0
|
10
|
tomwalters@0
|
11 %
|
tomwalters@0
|
12 % Gammachirp : Theoretical auditory filter
|
tomwalters@0
|
13 % Toshio IRINO
|
tomwalters@0
|
14 % 7 Apr. 97 (additional comments)
|
tomwalters@0
|
15 % 20 Aug. 97 (Simplify & Carrier Selection)
|
tomwalters@0
|
16 % 10 Jun. 98 (SwNorm)
|
tomwalters@0
|
17 % 26 Nov. 98 (phase = phase + c ln fr/f0)
|
tomwalters@0
|
18 % 7 Jan. 2002 (adding 'envelope' option)
|
tomwalters@0
|
19 % 22 Nov. 2002 (debugging 'peak' option)
|
tomwalters@0
|
20 %
|
tomwalters@0
|
21 % gc(t) = t^(n-1) exp(-2 pi b ERB(Frs)) cos(2*pi*Frs*t + c ln t + phase)
|
tomwalters@0
|
22 %
|
tomwalters@0
|
23 % function [GC, LenGC, Fps, InstFreq ] ...
|
tomwalters@0
|
24 % = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm);
|
tomwalters@0
|
25 % INPUT : Frs : Asymptotic Frequency ( vector )
|
tomwalters@0
|
26 % SR : Sampling Frequency
|
tomwalters@0
|
27 % OrderG : Order of Gamma function t^(OrderG-1) == n
|
tomwalters@0
|
28 % CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f)) == b
|
tomwalters@0
|
29 % CoefC : Coeficient -> exp(j*2*pi*Frs + CoefC*ln(t)) == c
|
tomwalters@0
|
30 % Phase : Start Phase(0 ~ 2*pi)
|
tomwalters@0
|
31 % SwCarr : Carrier ('cos','sin','complex','envelope': 3 letters)
|
tomwalters@0
|
32 % SwNorm : Normalization of peak spectrum level ('no', 'peak')
|
tomwalters@0
|
33 % OUTPUT: GC : GammaChirp ( matrix )
|
tomwalters@0
|
34 % LenGC : Length of GC for each channel ( vector )
|
tomwalters@0
|
35 % Fps : Peak Frequency ( vector )
|
tomwalters@0
|
36 % InstFreq: Instanteneous Frequency ( matrix )
|
tomwalters@0
|
37 %
|
tomwalters@0
|
38 %
|
tomwalters@0
|
39 function [GC, LenGC, Fps, InstFreq ] ...
|
tomwalters@0
|
40 = GammaChirp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,SwCarr,SwNorm);
|
tomwalters@0
|
41
|
tomwalters@0
|
42 if nargin < 2, help GammaChirp; return; end;
|
tomwalters@0
|
43 Frs = Frs(:);
|
tomwalters@0
|
44 NumCh = length(Frs);
|
tomwalters@0
|
45 if nargin < 3, OrderG = []; end;
|
tomwalters@0
|
46 if length(OrderG) == 0, OrderG = 4; end; % Default GammaTone
|
tomwalters@0
|
47 if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end;
|
tomwalters@0
|
48 if nargin < 4, CoefERBw = []; end;
|
tomwalters@0
|
49 if length(CoefERBw) == 0, CoefERBw = 1.019; end; % Default GammaTone
|
tomwalters@0
|
50 if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end;
|
tomwalters@0
|
51 if nargin < 5, CoefC = []; end;
|
tomwalters@0
|
52 if length(CoefC) == 0, CoefC = 0; end; % Default GammaTone
|
tomwalters@0
|
53 if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end;
|
tomwalters@0
|
54 if nargin < 6, Phase = []; end;
|
tomwalters@0
|
55 if length(Phase) == 0, Phase = 0; end;
|
tomwalters@0
|
56 if length(Phase) == 1, Phase = Phase*ones(NumCh,1); end;
|
tomwalters@0
|
57 if nargin < 7, SwCarr = []; end;
|
tomwalters@0
|
58 if length(SwCarr) == 0, SwCarr = 'cos'; end;
|
tomwalters@0
|
59 if nargin < 8, SwNorm = []; end;
|
tomwalters@0
|
60 if length(SwNorm) == 0, SwNorm = 'no'; end;
|
tomwalters@0
|
61
|
tomwalters@0
|
62
|
tomwalters@0
|
63 [ERBrate ERBw] = Freq2ERB(Frs); % G&M (1990)
|
tomwalters@0
|
64 LenGC1kHz = (40*max(OrderG)/max(CoefERBw) + 200)*SR/16000; % 2 Aug 96
|
tomwalters@0
|
65 [dummy ERBw1kHz] = Freq2ERB(1000);
|
tomwalters@0
|
66
|
tomwalters@0
|
67 if strcmp(SwCarr,'sin'), Phase = Phase - pi/2*ones(1,NumCh); end;
|
tomwalters@0
|
68 %%% Phase compensation
|
tomwalters@0
|
69 Phase = Phase + CoefC.*log(Frs/1000); % relative phase to 1kHz
|
tomwalters@0
|
70
|
tomwalters@0
|
71 LenGC = fix(LenGC1kHz*ERBw1kHz./ERBw);
|
tomwalters@0
|
72
|
tomwalters@0
|
73 %%%%% Production of GammaChirp %%%%%
|
tomwalters@0
|
74 GC = zeros(NumCh,max(LenGC));
|
tomwalters@0
|
75 if nargout > 2, Fps = Fr2Fpeak(OrderG,CoefERBw,CoefC,Frs); end; % Peak Freq.
|
tomwalters@0
|
76 if nargout > 3, InstFreq = zeros(NumCh,max(LenGC)); end;
|
tomwalters@0
|
77
|
tomwalters@0
|
78
|
tomwalters@0
|
79 for nch = 1:NumCh,
|
tomwalters@0
|
80 t = (1:LenGC(nch)-1)/SR;
|
tomwalters@0
|
81
|
tomwalters@0
|
82 GammaEnv = t.^(OrderG(nch)-1).*exp(-2*pi*CoefERBw(nch)*ERBw(nch)*t);
|
tomwalters@0
|
83 GammaEnv = [ 0 GammaEnv/max(GammaEnv)];
|
tomwalters@0
|
84
|
tomwalters@0
|
85 if strcmp(SwCarr(1:3),'env') % envelope
|
tomwalters@0
|
86 Carrier = ones(size(GammaEnv));
|
tomwalters@0
|
87 elseif strcmp(SwCarr(1:3),'com') % complex
|
tomwalters@0
|
88 Carrier = [ 0 exp(i * (2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch)) )];
|
tomwalters@0
|
89 else
|
tomwalters@0
|
90 Carrier = [ 0 cos(2*pi*Frs(nch)*t + CoefC(nch)*log(t) +Phase(nch))];
|
tomwalters@0
|
91 end;
|
tomwalters@0
|
92
|
tomwalters@0
|
93 GC(nch,1:LenGC(nch)) = GammaEnv.*Carrier;
|
tomwalters@0
|
94
|
tomwalters@0
|
95 if nargout > 3,
|
tomwalters@0
|
96 InstFreq(nch,1:LenGC(nch)) = [0, [Frs(nch) + CoefC(nch)./(2*pi*t)]];
|
tomwalters@0
|
97 end;
|
tomwalters@0
|
98
|
tomwalters@0
|
99 if strcmp(SwNorm,'peak') == 1, % peak gain normalization
|
tomwalters@0
|
100 [frsp freq] = freqz(GC(nch,1:LenGC(nch)),1,LenGC(nch),SR);
|
tomwalters@0
|
101 fp = Fr2Fpeak(OrderG(nch),CoefERBw(nch),CoefC(nch),Frs(nch));
|
tomwalters@0
|
102 [dummy np] = min(abs(freq-fp));
|
tomwalters@0
|
103 GC(nch,:) = GC(nch,:)/abs(frsp(np));
|
tomwalters@0
|
104 end;
|
tomwalters@0
|
105
|
tomwalters@0
|
106 end; % nch = ...
|
tomwalters@0
|
107
|
tomwalters@0
|
108 return
|
tomwalters@0
|
109
|
tomwalters@0
|
110 %% ERBw = 0.128*Frs; % Complete Constant Q only for check.
|
tomwalters@0
|
111
|
tomwalters@0
|
112 % old
|
tomwalters@0
|
113 % Amp = ones(NumCh,1); % No normalization
|
tomwalters@0
|
114 % if strcmp(SwNorm,'peak'), Amp = ERBw./ERBw1kHz; end; % Peak spectrum==const.
|
tomwalters@0
|
115 % when it is gammatone
|
tomwalters@0
|
116 % if strcmp(SwNorm,'peak'), ...
|
tomwalters@0
|
117 % Amp = 2.815*sqrt(4/OrderG).*CoefERBw.*ERBw/SR; end;
|
tomwalters@0
|
118 % Peak spectrum==const. The gain is 1.0 when filtering sinusoid at cf.
|
tomwalters@0
|
119 % GC(nch,:) = GC(nch,:)/max(abs(freqz(GC(nch,:),1,LenGC(nch))));
|
tomwalters@0
|
120 %
|