tomwalters@0
|
1 %
|
tomwalters@0
|
2 % Frequency Response of GammaChirp
|
tomwalters@0
|
3 % Toshio IRINO
|
tomwalters@0
|
4 % Original Version: 30 Sept 98
|
tomwalters@0
|
5 % Modified: 7 June 2004 (removing transpose when NumCh==1)
|
tomwalters@0
|
6 %
|
tomwalters@0
|
7 % function [AmpFrsp, freq, Fpeak, GrpDly, PhsFrsp] ...
|
tomwalters@0
|
8 % = GammaChirpFrsp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,NfrqRsl);
|
tomwalters@0
|
9 % INPUT : Frs : Resonance Freq. (vector)
|
tomwalters@0
|
10 % SR : Sampling Freq.
|
tomwalters@0
|
11 % OrderG : Order of Gamma function t^(OrderG-1) (vector)
|
tomwalters@0
|
12 % CoefERBw: Coeficient -> exp(-2*pi*CoefERBw*ERB(f))
|
tomwalters@0
|
13 % CoefC : Coeficient -> exp(j*2*pi*Fr + CoefC*ln(t))
|
tomwalters@0
|
14 % Phase : Start Phase (0 ~ 2*pi)
|
tomwalters@0
|
15 % NfrqRsl : freq. resolution
|
tomwalters@0
|
16 % OUTPUT: AmpFrsp : abs(Response) (NumCh*NfrqRsl matrix)
|
tomwalters@0
|
17 % freq : frequency (1 * NfrqRsl vector)
|
tomwalters@0
|
18 % Fpeak : Peak frequency (NumCh * 1 vector)
|
tomwalters@0
|
19 % GrpDly : Group delay (NumCh*NfrqRsl matrix)
|
tomwalters@0
|
20 % PhsFrsp : angle(Response); (NumCh*NfrqRsl matrix)
|
tomwalters@0
|
21 %
|
tomwalters@0
|
22 function [AmpFrsp, freq, Fpeak, GrpDly, PhsFrsp ] ...
|
tomwalters@0
|
23 = GammaChirpFrsp(Frs,SR,OrderG,CoefERBw,CoefC,Phase,NfrqRsl);
|
tomwalters@0
|
24
|
tomwalters@0
|
25 if nargin < 1, help GammaChirpFrsp; return; end;
|
tomwalters@0
|
26 if nargin < 2, SR = 48000; end;
|
tomwalters@0
|
27 if length(SR) == 0, error('Specify Sampling Frequency'); end;
|
tomwalters@0
|
28 Frs = Frs(:);
|
tomwalters@0
|
29 NumCh = length(Frs);
|
tomwalters@0
|
30
|
tomwalters@0
|
31 if nargin < 3, OrderG = 4; end; % Default GammaTone
|
tomwalters@0
|
32 if length(OrderG) == 1, OrderG = OrderG*ones(NumCh,1); end;
|
tomwalters@0
|
33 if nargin < 4, CoefERBw = 1.019; end; % Default GammaTone
|
tomwalters@0
|
34 if length(CoefERBw) == 1, CoefERBw = CoefERBw*ones(NumCh,1); end;
|
tomwalters@0
|
35 if nargin < 5, CoefC = 0; end; % Default GammaTone
|
tomwalters@0
|
36 if length(CoefC) == 1, CoefC = CoefC*ones(NumCh,1); end;
|
tomwalters@0
|
37 if nargin < 6, Phase = []; end;
|
tomwalters@0
|
38 if length(Phase)==0, Phase = zeros(NumCh,1); end; % Default GammaTone
|
tomwalters@0
|
39 if nargin < 7, NfrqRsl = 1024; end;
|
tomwalters@0
|
40 if NfrqRsl < 256, help GammaChirpFrsp; error('NfrqRsl < 256'); end;
|
tomwalters@0
|
41
|
tomwalters@0
|
42 [ERBrate ERBw] = Freq2ERB(Frs(:));
|
tomwalters@0
|
43 freq = [0:NfrqRsl-1]/NfrqRsl*SR/2;
|
tomwalters@0
|
44
|
tomwalters@0
|
45 one1 = ones(1,NfrqRsl);
|
tomwalters@0
|
46 bh = ( CoefERBw(:).*ERBw(:) ) * one1;
|
tomwalters@0
|
47 fd = ones(NumCh,1)*freq(:)' - Frs(:)*one1;
|
tomwalters@0
|
48 cn = ( CoefC(:)./OrderG(:) ) * one1;
|
tomwalters@0
|
49 n = OrderG(:) *one1;
|
tomwalters@0
|
50 c = CoefC(:) *one1;
|
tomwalters@0
|
51 Phase = Phase(:) *one1;
|
tomwalters@0
|
52
|
tomwalters@0
|
53 %%% Analytic form (normalized at Fpeak) %%%
|
tomwalters@0
|
54 AmpFrsp = ( (1 + cn.^2)./(1 + (fd./bh).^2) ).^(n/2) ...
|
tomwalters@0
|
55 .* exp( c .* (atan(fd./bh) - atan(cn)));
|
tomwalters@0
|
56
|
tomwalters@0
|
57 if nargout > 2,
|
tomwalters@0
|
58 Fpeak = Frs + CoefERBw.*ERBw.*CoefC./OrderG;
|
tomwalters@0
|
59 if nargout > 3,
|
tomwalters@0
|
60 GrpDly = 1/(2*pi)*(n.*bh + c.*fd)./(bh.^2 + fd.^2);
|
tomwalters@0
|
61 if nargout > 4,
|
tomwalters@0
|
62 PhsFrsp= -n.*atan(fd./bh) -c./2.*log((2*pi*bh).^2 +(2*pi*fd).^2 )+Phase;
|
tomwalters@0
|
63 end;
|
tomwalters@0
|
64 end;
|
tomwalters@0
|
65 end;
|
tomwalters@0
|
66
|
tomwalters@0
|
67 return
|
tomwalters@0
|
68
|
tomwalters@0
|
69
|
tomwalters@0
|
70
|
tomwalters@0
|
71 %%% No use anymore since it is somewhat confusing 7 June 2004 %%%%%%%%%%%%
|
tomwalters@0
|
72
|
tomwalters@0
|
73 if NumCh == 1, % to let the results in column vector (same as freqz)
|
tomwalters@0
|
74 AmpFrsp = AmpFrsp(:);
|
tomwalters@0
|
75 freq=freq(:);
|
tomwalters@0
|
76 if nargout > 3,
|
tomwalters@0
|
77 GrpDly = GrpDly(:);
|
tomwalters@0
|
78 if nargout > 4,
|
tomwalters@0
|
79 PhsFrsp = PhsFrsp(:);
|
tomwalters@0
|
80 end;
|
tomwalters@0
|
81 end;
|
tomwalters@0
|
82 end;
|
tomwalters@0
|
83
|
tomwalters@0
|
84 return
|
tomwalters@0
|
85
|
tomwalters@0
|
86
|
tomwalters@0
|
87 % Fbw = sqrt( -1 + 2.^(1./OrderG)).*CoefERBw.*ERBw; % bandwidth when c=0
|
tomwalters@0
|
88
|
tomwalters@0
|
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
tomwalters@0
|
90
|
tomwalters@0
|
91 % OLD
|
tomwalters@0
|
92 % val = 2*pi*(bh + i*fd);
|
tomwalters@0
|
93 % arg = angle(val);
|
tomwalters@0
|
94 % FrspAna = 1./(abs(val)).^OrderG(nch) .* exp(CoefC(nch)* arg);
|
tomwalters@0
|
95 % FrspAna = FrspAna/max(FrspAna);
|
tomwalters@0
|
96
|
tomwalters@0
|
97
|
tomwalters@0
|
98 if 0
|
tomwalters@0
|
99
|
tomwalters@0
|
100 for nch = 1:NumCh
|
tomwalters@0
|
101 bh = CoefERBw(nch)*ERBw(nch);
|
tomwalters@0
|
102 fd = freq(:)' - Frs(nch);
|
tomwalters@0
|
103 cn = CoefC(nch)/OrderG(nch);
|
tomwalters@0
|
104 %%% Analytic form (normalized at Fpeak) %%%
|
tomwalters@0
|
105 FrspAna = (sqrt( (1+cn^2)./(1+(fd/bh).^2) ) ).^OrderG(nch) ...
|
tomwalters@0
|
106 .* exp( CoefC(nch) .* (atan(fd/bh) - atan(cn)));
|
tomwalters@0
|
107 % Frsp(nch, 1:NfrqRsl) = FrspAna;
|
tomwalters@0
|
108 sqrt(mean( ( Frsp(nch, 1:NfrqRsl) - FrspAna ).^2) )
|
tomwalters@0
|
109 GrpDly(nch,1:NfrqRsl) = ...
|
tomwalters@0
|
110 1/(2*pi)*(OrderG(nch)*bh + CoefC(nch)*fd)./(bh.^2 + fd.^2);
|
tomwalters@0
|
111 end;
|
tomwalters@0
|
112
|
tomwalters@0
|
113 end;
|
tomwalters@0
|
114
|
tomwalters@0
|
115
|