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

📄 dem16ofdm.m

📁 802.16a协议物理层的matlab实现
💻 M
字号:
function dem16ofdm(demparams)
% dem16ofdm(demparams)
% 802.16a/D6+ OFDM basic demodulator simulation
%
% COMMERCIAL IN CONFIDENCE
% Copyright (c) Commsonic Ltd 2002

% Commsonic Ltd , St John's Innovation Centre, Cowley Road, 
% Cambridge CB4 0WS, England
% Tel/Fax +44 1223 871071


InBuff=zeros(1,256);
LoRefCorr=zeros(1,1000);
SymOffset=0;
state='DetectLS';
if demparams.SubChanEnable,
   [DataIndex, PilotIndex, LSf, LSt]=subchanpatterns(demparams.SubChanIndex);
   % compensate correlation detect threshold for reduced num carriers
   if demparams.SubChanIndex<=4,
      CorrThresh=5;
   else
      CorrThresh=7;
   end
else
   [SSf, LSf, SSt, LSt] = syncpatterns;
   PilotIndex=[-84 -60 -36 -12 12 36 60 84];
   CorrThresh=10;
end
LSt=fliplr(LSt);


switch demparams.Guard
case 1
   Guard=1/32;
case 2
   Guard=1/16;
case 3
   Guard=1/8;
case 4
   Guard=1/4;
otherwise
   error('dem16ofdm: Invalid Guard');
end

% open and read the input file
ipfid = fopen(demparams.infile, 'r');
if ipfid <= 0
   error('unable to open source file');
end
[RxData, datalen] = fread(ipfid, 'float32');
RxData =  [ 1 1j ] * reshape(RxData, 2, datalen/2);
Len = datalen/2;
fclose(ipfid);

%------- Main demod loop
for k=1:Len
   
   % 256 sample shift reg for correlator and FFT
   RxSample = RxData(k);
   InBuff(2:end) = InBuff(1:end-1);
   InBuff(1) = RxSample;
   
   switch state
      % Detect the long (128 sample) preamble sequence   
   case 'DetectLS'
      % Start running the FFT buffer
      LoRefCorr(k)=sum(InBuff(1:128).*conj(LSt));
      if abs(LoRefCorr(k)) > CorrThresh,
         state='DetectLS2';
         DetectTime = k;
         counter = 1;
         impz(1)=LoRefCorr(k); %???
      end
      
      
      % Get the second long preamble sequence   
   case 'DetectLS2'
      LoRefCorr(k)=sum(InBuff(1:128).*conj(LSt));
      if (k==(DetectTime+128)),
         state='GetData';
         
         long=fftshift(fft(fliplr(InBuff(1:256))/16,256));
         long(230:256)=[];long(1:28)=[];
         long=long(1:2:end);
         long(51)=0;
         
         LSf(101)=2; %avoid a div0 for DC
         warning off; % supress div0 warnings in sub-band mode
         ChanEst=long./LSf(1:2:end);
         warning on;
         ChanEst(51)=mean([ChanEst(50) ChanEst(52)]);
         FullChanEst=interp1(1:101,ChanEst,1:0.5:101,'linear');
         
         DetectTime = k;
         counter = 0;
         sym=1;
         
         
      end
      
      % Get the OFDM payload
   case 'GetData'
      if (k<(DetectTime+10)),
         % run the correlator a few more samples for a better plot
         LoRefCorr(k)=sum(InBuff(1:128).*conj(LSt));
      end
      counter = counter + 1;
      
      if counter == (1+Guard)*256,
         
         % fft
         FFT = fftshift(fft(fliplr(InBuff(1:256)),256)/16);
         FFT(230:256)=[]; FFT(1:28)=[];
         
         % apply chan correction
         CorrFFT = FFT./FullChanEst;
         
         counter=0;
         %if demparams.plottype==1,
         axes(demparams.handles.axes2);
         DataPlot=CorrFFT;
         DataPlot(PilotIndex+101)=[];
         DataPlot(97)=[];
         PilotPlot=CorrFFT(PilotIndex+101);
         if ((sym==1)&(demparams.DLUL==0)),
            plot(DataPlot,'r.');
         else
            plot(DataPlot,'.');
         end
         hold on
         plot(PilotPlot,'g.');
         axis([-1.5 1.5 -1.5 1.5]);
         %set(demparams.handles.axes2,'XGrid','off','YGrid','off','XTick',0,'YTick',0);
         drawnow;
         %if sym==1, hold off; end % don't persist the FCH symbol
         sym=sym+1;
      end
   otherwise
      error('Invalid State')
   end
end
hold off;
% Correlator plot
if demparams.plottype==2,
   axes(demparams.handles.axes2);
   plot(abs(LoRefCorr));
   drawnow;
end
% psd plot
if demparams.plottype==3,
   axes(demparams.handles.axes2);
   h=psd(RxData);
   plot(10*log10(fftshift(h)));
   drawnow;
end

⌨️ 快捷键说明

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