⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tfb.m

📁 ADSL经典仿真程序
💻 M
📖 第 1 页 / 共 3 页
字号:
   Dmax = get(hndlList(8),'Userdata');
   v = get(gco,'Userdata');
   s = get(gco,'String');
   vv = eval(s,num2str(v(1)));
   % Dmin cannot be smaller than 1 and larger than Dmax
   if vv<1 | vv > Dmax, 
      vv = v; 
   end
   set(gco,'Userdata',vv,'String',num2str(vv))
   return
   
   % set Dmax   
elseif strcmp(action,'setDmax'),
   hndlList=get(gcf,'Userdata');
   Dmin = get(hndlList(7),'Userdata');
   v = get(gco,'Userdata');
   s = get(gco,'String');
   vv = eval(s,num2str(v(1)));
   % Dmax cannot be smaller than 1 and Dmin
   if vv < 1 | vv < Dmin, 
      vv = v;
   end
   set(gco,'Userdata',vv,'String',num2str(vv))
   return
   
   % set N   
elseif strcmp(action,'setN'),
   hndlList=get(gcf,'Userdata');
   v = get(gco,'Userdata');
   s = get(gco,'String');
   vv = eval(s,num2str(v(1)));
   % N has to be a power of 2
   if (floor(log(vv)/log(2))-(log(vv)/log(2))) ~= 0
      vv = v; 
   end
   set(gco,'Userdata',vv,'String',num2str(vv))
   return

elseif strcmp(action,'setHDelaySearch'),
   hndlList=get(gcf,'Userdata');
   hd=hndlList(22);
   od=hndlList(23);
  set(hd,'value',get(hd,'Max'));
  set(hd,'userdata','1');
  set(od,'value',get(od,'Min'));
  set(od,'userdata','0');
         
   return
   
 elseif strcmp(action,'setODelaySearch'),
   hndlList=get(gcf,'Userdata');
   hd=hndlList(22);
   od=hndlList(23);
  set(od,'value',get(od,'Max'));
  set(od,'userdata','1');
  set(hd,'value',get(hd,'Min'));
  set(hd,'userdata','0');
   return
   % design TEQ   
elseif strcmp(action,'design'),
   set(gcf,'Pointer','watch');
   % get handles
   axHndl=gca;
   fhndlList=get(gcf,'Userdata');
   freqzHndl = fhndlList(1);
   NbHndl = fhndlList(2);
   NwHndl = fhndlList(3);
   NHndl = fhndlList(4);
   CGHndl = fhndlList(5);
   MarginHndl = fhndlList(6);
   DminHndl = fhndlList(7);
   DmaxHndl = fhndlList(8);
   PwrHndl = fhndlList(9);
   AWGNHndl = fhndlList(10);
   CSAHndl = fhndlList(11);
   viewHndl = fhndlList(12);
   helpHndl = fhndlList(13);
   closeHndl = fhndlList(14);
   methodHndl = fhndlList(15);
   methRateHndl = fhndlList(16);
   methSNRHndl = fhndlList(17);
   methSSNRHndl = fhndlList(18);
   methMSEHndl = fhndlList(19);
   methDelayHndl = fhndlList(20);
   methMaxHndl = fhndlList(21);
   HDHndl=fhndlList(22);
   ODHndl=fhndlList(23);
   
   colors = get(gca,'colororder'); 
  
   % init variables
   Nb = get(NbHndl,'userdata');
   Nw = get(NwHndl,'userdata');
   N = get(NHndl,'userdata');
   codingGain = get(CGHndl,'userdata');
   margin = get(MarginHndl,'userdata');
   Dmin = get(DminHndl,'userdata');
   Dmax = get(DmaxHndl,'userdata');
   totalInputPower = get(PwrHndl,'userdata');
   AWGNpower = get(AWGNHndl,'userdata');
   loopNum = get(CSAHndl,'userdata');
   method = get(methodHndl,'value');
   HD=get(HDHndl,'value');
   OD=get(ODHndl,'value');
   if (HD==1)&(OD==0)
       delaySearch=1; %delaySearch=1 => heuristic delay search
   elseif (HD==0)&(OD==1)
       delaySearch=0; %delaySearch=0 => optimal delay search
   else
       delaySearch=1;
   end
   barflag = 1;
   chflag=1;
   %number of iteration per TEQ tap
   numIter = 1000;

   
   %generate signal,noise, and channel data
   [recNoisySig,receivedSignal,noise,channel,inputSignal,gamma,fs,NEXTnoise,AWGN,FX] = ...
      siggen_tfb(N,Nb,AWGNpower,loopNum,totalInputPower,codingGain,margin,barflag,chflag);
 
  %save tmp1.mat inputSignal, receivedSignal, noise;

   %estimate the power spectrums
   [inputSpecAll, noiseSpecAll, channelGainAll]=...
      specestim(inputSignal,noise,channel,N,barflag);
   
   %calculate SNRs and usable channels
   [subMFBall,subMFB,usedSubs,noiseSpec,channelGain,inputSpec] = ...
   calcsnrs(inputSpecAll,channelGainAll,noiseSpecAll,gamma);

   
%     % chose method and design TEQ
%    
%    [B, W, D, MSE, Dv, I,title_str] = selmeth(method,inputSignal,...
%       receivedSignal,noise,channel(1:N),...
%    Nb,Nw,Dmin,Dmax,barflag,N,numIter,inputSpec,noiseSpec,channelGain,...
%    usedSubs,gamma);

%chose method and design pertone
[RTFB, tfbsubsnr,optimalD,teqfbcoef, feqcoef, title_str, totalRateVector] = selmeth_tfb(method,channel, ...
    inputSignal, AWGN, NEXTnoise, Dmin, Dmax, gamma, N, Nw, Nb, delaySearch);
save teqfilterbank  recNoisySig FX optimalD teqfbcoef feqcoef  channel N;
%calculate bit rate and subcarrier SNR by running through data
%[RTFB,tfbsubsnr]=perform_tfb(recNoisySig,FX,optimalD,teqfbcoef,feqcoef,channel,N);

   RDMT=sum(RTFB)*fs/(N+Nb);
   bmfb(usedSubs) = ba_cal(subMFBall(usedSubs), 9.8, margin, codingGain, 0, 100, 0);
   RDMTmfb = fs/(N+Nb)*sum(bmfb);
   % put results into table
   str = sprintf('%1.3fe6',RDMT/1e6);
   set(methRateHndl,'string',str);
   str = '-';
   set(methSNRHndl,'string',str);
   str = '-';
   set(methSSNRHndl,'string',str);
   str = sprintf('%d',optimalD);
   set(methDelayHndl,'string',str);
   str = '-';
   set(methMSEHndl,'string',str);
   str = sprintf('%1.3fe6',RDMTmfb/1e6);
   set(methMaxHndl,'string',str);
   
  save tfbtmpresults title_str N Nb recNoisySig receivedSignal noise channel inputSignal gamma fs NEXTnoise AWGN...
      inputSpecAll noiseSpecAll channelGainAll subMFBall subMFB usedSubs noiseSpec channelGain inputSpec...
      RTFB tfbsubsnr optimalD teqfbcoef RDMT RDMTmfb feqcoef totalRateVector delaySearch Dmin Dmax;

%    TEQequalizerTaps = W;
%    TEQtargetImpulseResp = B;
%    TEQoptimalDelay = D;
%    TEQoriginalChannel = channel;
%    TEQequalizedChannel = hw;
%    TEQmatchedFilterBoundPerChannel = subMFB;
%    TEQSNRperChannel = subSNR;
%    TEQoriginalChannelFreqResp = Fh;
%    TEQequalizerFreqResp = Fw;
%    TEQequalizedChannelFreqResp = Fhw;
%    TEQchanNoisePowSpecAfterEqual = colorNoiseaft;
%    TEQchanNoisePowSpecBeforeEqual = noiseSpec;
%    TEQperformanceVersusDelay = Dv;
    TEQDmin = Dmin;
    TEQDmax = Dmax;
    TEQNb = Nb;
    TEQNw = Nw;
    TEQN = N;
    TEQFB = teqfbcoef;
    TEQFBSubsnr = tfbsubsnr;
    TEQoriginalChannel = channel;
    TEQoptimalDelay = optimalD;
    TEQCodingGain=codingGain;
    TEQMargin=margin;
    TEQInputPower=totalInputPower;
    TEQAWGNPower=AWGNpower;
    TEQLoopnum=loopNum;
    TEQFEQ=feqcoef;
    save teqfbresults TEQDmin TEQDmax TEQNb TEQNw TEQN TEQFB TEQFBSubsnr TEQoriginalChannel ...
    TEQoptimalDelay TEQCodingGain TEQMargin TEQInputPower TEQAWGNPower TEQLoopnum TEQFEQ;

%    save teqresults TEQequalizerTaps TEQtargetImpulseResp  ...
% 	   TEQoptimalDelay TEQoriginalChannel TEQequalizedChannel ...
% 	   TEQmatchedFilterBoundPerChannel TEQSNRperChannel ...
% 	   TEQoriginalChannelFreqResp TEQequalizerFreqResp ...
% 	   TEQequalizedChannelFreqResp TEQchanNoisePowSpecAfterEqual...
% 	   TEQchanNoisePowSpecBeforeEqual TEQDmin TEQDmax TEQNb TEQNw TEQN;
	   
   % plot result
   tfb('plotGraph');
   set(gcf,'Pointer','arrow');
   return
   
   % plot graph
elseif strcmp(action,'plotGraph'),
  legend off
  set(gcf,'Pointer','watch');
   % get handles
   fhndlList = get(gcf,'Userdata');
   viewHndl = fhndlList(12);
   freqzHndl = fhndlList(1);
   % set axis
   axHndl = gca;
   axes(freqzHndl);
   % which graph is going to be plotted
   graphNum = get(viewHndl,'value'); 
   %1= TIR/SIR, 2= TEQ impulse res., 3= TEQ freq. res., 4= SNR/MFB
   %5=original and short channel impulse res, 6 = noise power spec., 
   %7= delay plot, 8= equalized channel freq
   
   % load results for current TEQ
   load tfbtmpresults;
   freqAxis = 1:N/2+1;
   
   % plot chosen graph
   if graphNum == 1      
 	  legend off
     plot([6:N/2-1],RTFB(7:N/2));
     xlabel('subcarrier number');
     ylabel('bits/subcarrier');
     title([title_str,' bit allocation']);
      
   elseif graphNum == 2
      legend off
      plot([6:N/2-1],10*log10(tfbsubsnr(7:N/2)));
      xlabel('subcarrier number');
      ylabel('subcarrier snr');
      title([title_str,' subSNR']);
      
  elseif graphNum == 3 
      if delaySearch==0
        legend off
        plot([Dmin:Dmax],totalRateVector*fs/(N+Nb));
        xlabel('delay');
        ylabel('bit rate');
        title([title_str,' bit rate vs. delay']);
      else
        legend off
        plot([optimalD],totalRateVector*fs/(N+Nb));
        xlabel('delay');
        ylabel('bit rate');
        title([title_str,' bit rate vs. delay']); 
      end
   end
   
   grid on
   
   set(gcf,'Pointer','arrow');
   return
   
      %save tfb to a file 
elseif strcmp(action,'savetfb');
   
    [filename,path]=uiputfile('*');
    if filename==0
        return;    
    end
    
    load teqfbresults;
    output=fopen([path,filename],'w');
    fprintf(output,'%s','optimal delay =');
    fprintf(output,' %d ;\n',TEQoptimalDelay);
    fprintf(output,'\n');
    [rowNum,colNum]=size(TEQFB);
    for j=1:rowNum
        fprintf(output,'subcarrier %d TEQ =[\n',j+6);
        for i=1:colNum
            fprintf(output,'%f \n',TEQFB(j,i));
        end
        fprintf(output,'%s\n','];');
        fprintf(output,'\n');
    end
    
    fprintf(output,'FEQ =[\n');
    for i=1:length(TEQFEQ)
        fprintf(output,'%f\n',TEQFEQ(i));
    end
    fprintf(output,'];');
    fclose(output);
    
    
       %save all parameters
elseif strcmp(action,'saveall')
    [filename,path]=uiputfile('*');
    if filename==0;
        return;
    end
    
    load teqfbresults;
    output=fopen([path,filename],'w');
    fprintf(output,'all the parameters are also saved into %s.mat\n',filename);
    fprintf(output,'%s','SIR length =');
    fprintf(output,' %d\n',TEQNb);
    fprintf(output,'%s','TEQ length =');
    fprintf(output,' %d;\n',TEQNw);
    fprintf(output,'%s','FFT size =');
    fprintf(output,' %d;\n',TEQN);
    fprintf(output,'%s','coding gain =');
    fprintf(output,' %f;\n',TEQCodingGain);
    fprintf(output,'%s','margin =');
    fprintf(output,' %d;\n',TEQMargin);
    fprintf(output,'%s','Dmin =');
    fprintf(output,' %d;\n',TEQDmin);
    fprintf(output,'%s','Dmax =');
    fprintf(output,' %d;\n',TEQDmax);
    fprintf(output,'%s','input power =');
    fprintf(output,' %f (dBm);\n',TEQInputPower);
    fprintf(output,'%s','AWGN power =');
    fprintf(output,' %f (dBm/Hz);\n',TEQAWGNPower);
    fprintf(output,'%s','loop number =');
    fprintf(output,' %d;\n',TEQLoopnum);
    fclose(output);
    str=sprintf(['save ', filename,' TEQNb TEQNw TEQN TEQCodingGain TEQMargin TEQDmin',...
            ' TEQDmax TEQInputPower TEQAWGNPower TEQLoopnum;']);
    eval(str);

   % get help
elseif strcmp(action,'info'),
   ttlStr = get(gcf,'name');
   myFig = gcf;
  
  topic1 =  ['TEQ filter bank design demo'];
 
   helptop1 = [...
     'This demonstration implements the design of an discrete multitone     '
     'modulation equalizer that consists of a filter bank of N/2 time       '
     'domain equalizers (TEQs), a bank of N/2 Goertzel filters, and N/2     '
     'single-tap frequency domain equalizer (FEQ).  Each TEQ is a finite    '
     'impulse response filter of the same length (Nw taps).  Each Goertzel  '
     'filter computes the discrete Fourier transform coefficient for one    '
     'subchannel (tone).  Each TEQ is tailored for a particular             '
     'subchannel (tone).  This time-domain filter bank equalizer structure  '
     'is essentially a dual of the per tone equalizer structure.  However,  '
     'the time-domain filter bank structure is not intended to ultimately   '
     'be implemented in a transceiver. Instead, it provides an upper bound  '
     'on the bit rate that can be achieved with a linear, critically        '
     'sampled, periodically time-varying multicarrier equalizer.            '
     '                                                                      '
     'Usage: Set parameters to desired values and hit the Calculate button. '
     '                                                                      '
     'The following design methods are supported:                           '
	 '  Data Rate Optimal Design Method                                     '
     '      M. Milosevic, L.F.C. Pessoa, B. L. Evans, and R. Baldick,       '
     '      "Optimal Time Domain Equalization Design for Maximizing Data    '
     '      Rate of Discrete Multi-tone Systems", IEEE Trans. on Signal     '
     '      Proc., submitted.                                               '
     '      M. Milosevic, L. F. C. Pessoa, B. L. Evans, and R. Baldick,     '
     '      "DMT Bit Rate Maximization With Optimal Time Domain Equalizer   '
     '      Filter Bank Architecture", IEEE Asilomar Conf. on Signals,      '
     '      Systems, and Computers, Nov. 3-6, 2002, Pacific Grove, CA, USA, '
     '      invited paper.                                                  '
     '   http://www.ece.utexas.edu/~bevans/papers/2002/optimalTEQ/index.html'];
  
   topic2 =  ['Design and Simulation Parameters'];
   helptop2 = [...
	 'On the top of he control window on the right is a pulldown menu       '
     'from which a design method can be chosen.                             '
	 'Below this pulldown menu are the following editable text windows      '
     'which are used to set the desired parameters,                         '
     '  SIR length. Define the length of the shortened channel              '
     '   Subband equalizer length. Defines the number of taps of            ' 
	 '   the equalizer for each tone.                                       '
     '  Fast Fourier transform (FFT) size. Sets the FFT size used in DMT    '
     '   modulation. It is twice the number of subchannels.                 '
     '  Coding gain (dB). Defines a coding in dB used during capacity       '
     '   calculations.                                                      '
     '  Margin (dB). Sets the desired system margin in dB. This is also     '
     '   used in capacity calculations.                                     '
     '  Dmin and Dmax. The optimal delay is search in the interval between  '
     '   Dmin and Dmax.                                                     '
	 '  Input power (dBm). Defines the input signal power in dBm.           '
	 '  AWGN pow (dBm/Hz). Sets the amount of additive white Gaussian noise '
     '   in dBm/Hz. AWGN is added to the near-end crosstalk noise.          '
     '  CSA loop \# (1-8). Selects the desired channel to run the simulation'
     '   on. Currently 8 standard CSA loops are supported.                  '];
   
     topic3 =  ['Graphics'];
   helptop3 = [...
	 'Below the editable text windows is another pull-down menu which       '
     'is used to select the desired graph to be displayed.                  '
     'The following graphics can be selected:                               '
     '  TFB bit allocation. The bit allocation scheme is displayed          '
     '   as a function of frequency (subchannels).                          '
     '  Subcarrier SNR. Shows the SNR in each subcarrier.                   '
     ];
 
   topic4 =  ['Performance Measures'];
   helptop4 = [...
'The two remaining buttons in the control frame are                    '
'   Info. Displays this help.                                          '
'   Calculate. Starts the calculation and performance evaluation of the'
'    TEQ.                                                              '
'The following performance measures are calculated and listed in the   '
'table:                                                                '
'   Rate. Gives the achievable bit rate with the given channel and Per '
'    Tone Equalizers settings.                                         '
'   Max Rate. Shows the absolute maximum achievable bit rate given the '
'    channel and equalizer settings. It is basically the capacity      '
'   calculated from the MFB.                                           '];
		 
   str =  { topic1 helptop1; topic2 helptop2; topic3 helptop3; topic4 helptop4 };
   
   helpwin(str,'Topic 1','TEQ filter bank design demo')                   
   return  
   
else
   disp(sprintf( 'Internal ERROR: ''%s'' not recognized',action))
end    






 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -