annotate aim-mat/modules/bmm/pzfc/AGCdampStep.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 function [pdampsmod, agcstate] = AGCdampStep(detect, pdamps, ...
tomwalters@0 2 agcepsilons, agcgains, agcstate, agcfactor);
tomwalters@0 3 %
tomwalters@0 4
tomwalters@0 5 % function [pdampsmod, agcstate] = AGCdampStep(detect, pdamps,
tomwalters@0 6 % agcepsilons, agcgains, agcstate);
tomwalters@0 7 %
tomwalters@0 8 % update the dampings and agcstates based on present outputs
tomwalters@0 9 % including 50% stereo coupling if two channels based on size of
tomwalters@0 10 % agcstate is twice the number of channels
tomwalters@0 11
tomwalters@0 12 if nargin < 6
tomwalters@0 13 agcfactor=12;
tomwalters@0 14 end
tomwalters@0 15
tomwalters@0 16 Nch = length(pdamps);
tomwalters@0 17 Ntracks = size(detect,2); % two columns for stereo
tomwalters@0 18 Nstages = length(agcepsilons);
tomwalters@0 19
tomwalters@0 20
tomwalters@0 21 if length(detect)==0,
tomwalters@0 22 Ntracks = 1; % mono default
tomwalters@0 23 if size(agcstate,2)>Nstages
tomwalters@0 24 Ntracks = round(size(agcstate,2)/Nstages); % pass in agcstate big
tomwalters@0 25 % enough to do stereo
tomwalters@0 26 end
tomwalters@0 27 detect = DetectFun(0.0)*ones(Nch,1);
tomwalters@0 28 %agcstate = 1.2*detect*ones(1,Ntracks*Nstages); % a detect-dependent
tomwalters@0 29 %hack to initialize damping
tomwalters@0 30 rep = 1+rem((1:Ntracks*Nstages)-1,Nstages);
tomwalters@0 31 agcstate = 1.2*detect*agcgains(rep); % rep is like [1 2 3 4 1 2 3 4]
tomwalters@0 32 detect = DetectFun(0.0)*ones(Nch,Ntracks);
tomwalters@0 33 end
tomwalters@0 34
tomwalters@0 35 agcepsleft = 0.3; % 0.15;
tomwalters@0 36 agcepsright = 0.3; % 0.15;
tomwalters@0 37 spacecoeffs = [agcepsleft, 1.0-agcepsleft-agcepsright, agcepsright];
tomwalters@0 38
tomwalters@0 39 for k = 1:Ntracks % track number (1 for mono, 2 for second channel)
tomwalters@0 40 for j = 1:Nstages % stage number
tomwalters@0 41 jj = j + (k-1)*Nstages; % index into state columns
tomwalters@0 42 %spatial smoothing:
tomwalters@0 43 agcavg = filter(spacecoeffs, 1, [agcstate(1,jj); agcstate(:,jj); ...
tomwalters@0 44 agcstate(Nch,jj)]);
tomwalters@0 45 agcavg = agcavg(3:(Nch+2));
tomwalters@0 46 %time smoothing:
tomwalters@0 47 epsilon = agcepsilons(j);
tomwalters@0 48 agcstate(:,jj) = agcavg*(1-epsilon) + epsilon*detect(:,k)*agcgains(j);
tomwalters@0 49 end
tomwalters@0 50 end
tomwalters@0 51
tomwalters@0 52 %agcstate can't exceed 0.25, usually , with max detect being 0.5
tomwalters@0 53 % only INCREASE the damping over pdamp
tomwalters@0 54 %agcfactor = 12; % 6.0; % 12.0;
tomwalters@0 55 % now set above or as an argument
tomwalters@0 56
tomwalters@0 57 offset = 1-agcfactor*DetectFun(0.0); % 0.7422 for DetectFun(0)=0.0215
tomwalters@0 58 % this makes the minimum damping (with 0 signal into AGC and agcstate being
tomwalters@0 59 % equal to the DetectFun value at zero, which may be zero) equal the nominal
tomwalters@0 60
tomwalters@0 61 for k = 1:Ntracks % track number (1 for mono, 2 for second channel)
tomwalters@0 62 % pdampsmod(:,k) = pdamps.*min(1.5,(offset+agcfactor*...
tomwalters@0 63 % (mean(agcstate')' + mean(agcstate(:,((k-1)*Nstages+1):k*Nstages)')')/2));
tomwalters@0 64 pdampsmod(:,k) = pdamps.*(offset+agcfactor*...
tomwalters@0 65 (mean(agcstate')' + mean(agcstate(:,((k-1)*Nstages+1):k*Nstages)')')/2);
tomwalters@0 66 % the above hack weights the track AGC and the average equally
tomwalters@0 67 % for mono is same as just ...ofset+agcfactor*sum(agcstates')'
tomwalters@0 68 end
tomwalters@0 69
tomwalters@0 70 %plot([detect, pdamps, pdampsmod, agcstate, sum(agcstate')'])
tomwalters@0 71 %drawnow