annotate aim-mat/modules/bmm/dcgc/InvFxGCFBv205.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 74dedb26614d
children
rev   line source
tomwalters@0 1 % Inverse Filterbank with Fixed Passive/Compressive Gammachirp
tomwalters@0 2 % No dynamic resynthesis
tomwalters@0 3 % Version 2.05
tomwalters@0 4 % Toshio IRINO
tomwalters@0 5 % Created: 9 Nov 2004
tomwalters@0 6 % Modified: 11 Nov 2004 Renamed and based on InvPGCFBv2.m
tomwalters@0 7 % Modified: 18 July 2005 v205
tomwalters@0 8 %
tomwalters@0 9 % function [SynSnd, SynGCout] = InvFxGCFB2(GCout,GCparam,GCresp,SwMethod)
tomwalters@0 10 % INPUT: GCout: pGCout or cGCout
tomwalters@0 11 % GCparam: Gammachirp parameters
tomwalters@0 12 % Fp: peak frequency vector for synthesis filter
tomwalters@0 13 % SwMethod: 1: pGCout - pGCsyn
tomwalters@0 14 % 2: cGCout - pGCsyn
tomwalters@0 15 % 3: cGCout - Fixed(Ref) cGCsyn
tomwalters@0 16 %
tomwalters@0 17 % OUTPUT: SynSnd: Synthetic Sound
tomwalters@0 18 %
tomwalters@0 19 %
tomwalters@0 20 % References:
tomwalters@0 21 % Irino, T. and Unoki, M.: IEEE ICASSP'98 paper, AE4.4 (12-15, May, 1998)
tomwalters@0 22 % Irino, T. and Patterson, R.D. : JASA, Vol.101, pp.412-419, 1997.
tomwalters@0 23 % Irino, T. and Patterson, R.D. : JASA, Vol.109, pp.2008-2022, 2001.
tomwalters@0 24 % Patterson, R.D., Unoki, M. and Irino, T. : JASA, Vol.114,pp.1529-1542,2003.
tomwalters@0 25 %
tomwalters@0 26 %
tomwalters@0 27 function [SynSnd,SynGCout] = InvFxGCFB2(GCout,GCparam,GCresp,SwMethod)
tomwalters@0 28
tomwalters@0 29 %%%% Handling Input Parameters %%%%%
tomwalters@0 30 if nargin < 4, help InvFxGCFBv2; end;
tomwalters@0 31
tomwalters@0 32
tomwalters@0 33 GCparam = GCFBv205_SetParam(GCparam);
tomwalters@0 34
tomwalters@0 35 %%%%%%%%%%%%%
tomwalters@0 36 fs = GCparam.fs;
tomwalters@0 37 NumCh0 = GCparam.NumCh;
tomwalters@0 38 if length(GCparam.b1) == 1 & length(GCparam.c1) == 1
tomwalters@0 39 b1 = GCparam.b1(1); % Freq. independent
tomwalters@0 40 c1 = GCparam.c1(1); % Freq. independent
tomwalters@0 41 else
tomwalters@0 42 error('Not prepared yet: Freq. dependent b1, c1');
tomwalters@0 43 end;
tomwalters@0 44
tomwalters@0 45 [NumCh, LenSnd] = size(GCout);
tomwalters@0 46 if NumCh ~= NumCh0, error('Mismatch in NumCh'); end;
tomwalters@0 47
tomwalters@0 48 if SwMethod == 1
tomwalters@0 49 disp('*** Inverse Passive Gammmachirp Calculation ***');
tomwalters@0 50 Fr1 = GCresp.Fr1;
tomwalters@0 51 elseif SwMethod == 2;
tomwalters@0 52 disp('*** Inverse Passive Gammmachirp Calculation ***');
tomwalters@0 53 Fr1 = Fpeak2Fr(GCparam.n,b1,c1,GCresp.cGCRef.Fp2); % pGC peak == Fp2
tomwalters@0 54 elseif SwMethod == 3
tomwalters@0 55 disp('*** Inverse Fixed Compressive Gammmachirp Calculation ***');
tomwalters@0 56 Fr1 = GCresp.Fr1;
tomwalters@0 57 end;
tomwalters@0 58
tomwalters@0 59
tomwalters@0 60 LenInv = 50/1000*fs; % 50 ms zero filling for processing
tomwalters@0 61 zz = zeros(NumCh,LenInv);
tomwalters@0 62 TrGCout = fliplr(GCout); %%% time-reversal %%
tomwalters@0 63 TrGCout = [zz TrGCout zz];
tomwalters@0 64 [NumCh,LenTr] = size(TrGCout);
tomwalters@0 65 SynGCout = zeros(NumCh,LenTr);
tomwalters@0 66 TrGCout1 = zeros(NumCh,LenTr);
tomwalters@0 67
tomwalters@0 68 %%%%% Time-Reversal ACfilter cGC %%%
tomwalters@0 69
tomwalters@0 70 Tstart = clock;
tomwalters@0 71 nDisp = 20*fs/1000; % display every 20 ms
tomwalters@0 72 if SwMethod == 3, % The same function is applied like wavelet trans.
tomwalters@0 73 [ACFcoef] = MakeAsymCmpFiltersV2(fs,...
tomwalters@0 74 GCresp.cGCRef.Fr2,GCresp.cGCRef.b2,GCresp.cGCRef.c2);
tomwalters@0 75 [dummy,ACFstatus] = ACFilterBank(ACFcoef,[]); % initiallization
tomwalters@0 76 for nsmpl = 1:LenTr
tomwalters@0 77 [SigOut,ACFstatus] = ACFilterBank(ACFcoef,ACFstatus,TrGCout(:,nsmpl));
tomwalters@0 78 TrGCout1(:,nsmpl) = GCresp.cGCRef.NormFctFp2.*SigOut;
tomwalters@0 79 if nsmpl==1 | rem(nsmpl,nDisp)==0,
tomwalters@0 80 disp(['Time-Reversal ACF-cGC : Time ' num2str(nsmpl/fs*1000,3) ...
tomwalters@0 81 ' (ms) / ' num2str(LenSnd/fs*1000) ' (ms). elapsed time = ' ...
tomwalters@0 82 num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']);
tomwalters@0 83 end;
tomwalters@0 84 end;
tomwalters@0 85 TrGCout = TrGCout1;
tomwalters@0 86 end;
tomwalters@0 87
tomwalters@0 88 %%%%% Time-Reversal Passive Gammachirp %%%
tomwalters@0 89
tomwalters@0 90 for nch=1:NumCh
tomwalters@0 91 pgc = GammaChirp(Fr1(nch),fs,GCparam.n,b1,c1,0,'','peak');
tomwalters@0 92 SynGCout(nch,1:LenTr) = fftfilt(pgc,TrGCout(nch,:));
tomwalters@0 93 if nch == 1 | rem(nch,20)==0
tomwalters@0 94 disp(['Time-Reversal Passive-Gammachirp ch #' num2str(nch) ...
tomwalters@0 95 ' / #' num2str(NumCh) '. elapsed time = ' ...
tomwalters@0 96 num2str(fix(etime(clock,Tstart)*10)/10) ' (sec)']);
tomwalters@0 97 end;
tomwalters@0 98 end;
tomwalters@0 99
tomwalters@0 100 SynGCout = fliplr(SynGCout);
tomwalters@0 101 SynSnd = mean(SynGCout)*sqrt(NumCh); % Approximately all right
tomwalters@0 102 % Maybe depend on filter shape
tomwalters@0 103 % 11 Nov 2004
tomwalters@0 104
tomwalters@0 105 %%%%% Inverse of Outer-Mid Ear Compensation %%%%
tomwalters@0 106 if length(GCparam.OutMidCrct) > 2
tomwalters@0 107 disp(['*** Inverse Outer/Middle Ear correction: ' GCparam.OutMidCrct ' ***']);
tomwalters@0 108 InvOutMid = OutMidCrctFilt(GCparam.OutMidCrct,fs,0,1); % Inverse
tomwalters@0 109 %% OutMidCrct--> 1kHz: -4 dB, 2kHz: -1 dB, 4kHz: +4 dB
tomwalters@0 110 %% [dummy NpIOM] = max(abs(InvOutMid));
tomwalters@0 111 SynSnd = filter(InvOutMid,1,SynSnd);
tomwalters@0 112 Nout = LenInv+length(InvOutMid)+(1:LenSnd);
tomwalters@0 113 else
tomwalters@0 114 disp('*** No Outer/Middle Ear correction ***');
tomwalters@0 115 Nout = LenInv+(1:LenSnd);
tomwalters@0 116 end;
tomwalters@0 117
tomwalters@0 118 SynSnd = SynSnd(Nout);
tomwalters@0 119 SynGCout = SynGCout(:,Nout);
tomwalters@0 120
tomwalters@0 121 disp(' ');
tomwalters@0 122 return