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

📄 single_carrier_fd_equalization.m

📁 Single Carrier Frequency Domain Equalization Simulation(单载波频域均衡仿真程序)
💻 M
字号:
echo off;clear all;close all;clc;
fprintf( 'Single Carrier Frequency Domain Equalization Simulation\n\n\n') ;
tic
% ------------------------------------------------------------------- %
%                   Parameters  Declaration                           %
% ------------------------------------------------------------------- %
%  Initialize the parameters
FrameNum = input('number of frames transmitted is(default=5000) =');
if isempty(FrameNum)
    FrameNum = 5;
end
FrameSize = input('size of each frame is(default=256) =');
if isempty(FrameSize)
    FrameSize = 256;
end
Chan =input('channel IR is(default=[0.227 0.46 0.688 0.46 0.227]) =');
if isempty(Chan)
    Chan = [0.227 0.46 0.688 0.46 0.227];
end
CPLen = FrameSize/8;
% ------------------------------------------------------------------- %
%             Generate Transmit Signal  & BPSK Modulation             %
% ------------------------------------------------------------------- %
%  generate the random binary stream for transmitting
BitsTranstmp = randint(1,FrameNum*FrameSize);
%  modulate ,generate the BPSK symbols  
Table=[-1 1];
%  After the step upon,Table = [-1.0000-0.0000i 1.000]
BitsTrans = Table(BitsTranstmp+1);    
% ------------------------------------------------------------------- %
%                               Add CP                                %
% ------------------------------------------------------------------- %
%  the function RESHAPE is to rearrange the BitsTrans to add cp for con-
%  venience
AddCPtmp = reshape(BitsTrans,FrameSize,FrameNum);
AddCP = zeros(FrameSize+CPLen,FrameNum);
AddPrefix = FrameSize-CPLen+1:FrameSize;
%  the matrix below is as the same function of add cp to each frame one 
%  by one 
AddCP = [AddCPtmp(AddPrefix,:);AddCPtmp];
% ------------------------------------------------------------------- %
%                         Go Through The Channel                      %
% ------------------------------------------------------------------- %
RecChantmp = filter(Chan,1,AddCP);
%----------------------------------------------------------------------
%  function explain :y = filter(b,a,x)
%  y = filter(b,a,X) filters the data in vector X with the filter desc-
%  ribed by numerator coefficient vector b and denominator coefficient
%  vector a,if x is a matrix,filter operates on the columns of X,so we 
%  could use filter here.
%----------------------------------------------------------------------
BerSnrTable = zeros(10,7);
for snr = 0:9
    BerSnrTable(snr+1,1) = snr*5;
% convert Eb/N0 from unit db to normal numbers  
    BerSnrTable(snr+1,2) = 10^(BerSnrTable(snr+1,1)/10); 
% standard deviation of AWGN noise
    BerSnrTable(snr+1,3) = 1/sqrt(2*BerSnrTable(snr+1,2));  
% add noise
    RecChan = awgn(RecChantmp,snr*5,'measured');
% ------------------------------------------------------------------- %
%                            Remove The CP                            %
% ------------------------------------------------------------------- %
RemovCP = zeros(FrameSize,FrameNum); 
% the rows of (CPLen+1:FrameSize+CPLen)of matrix RecChan is the 
% numbers which we wanted
RemovCP = RecChan(CPLen+1:FrameSize+CPLen,:);
% ------------------------------------------------------------------- %
%                   Frequency Domain Equalization                     %
% ------------------------------------------------------------------- %
% reshaping the matrix RemovCP for frequency domain equalization 
BitsFilt = reshape(RemovCP,1,FrameSize*FrameNum);
TimeBitsRec = zeros(1,FrameSize*FrameNum);
% fft of channel coeffients
FreqChan = fft(Chan,FrameSize);
for i = 1:FrameNum
    FreRectmp = zeros(1,FrameSize);
    for j = 1:FrameSize
        FreRectmp(j) = BitsFilt(j+(i-1)*FrameSize);
    end  
% fft of received frames
      FreqRec = zeros(1,FrameSize);
      FreqRec = fft(FreRectmp);
% equaliztion coefficients
      EqCoe = zeros(1,FrameSize);
      EqCoe = conj(FreqChan)./(BerSnrTable(snr+1,3)^2+abs(FreqChan).^2);
% equaliztion
      EqualFram = zeros(1,FrameSize);
      EqualFram = FreqRec.*EqCoe;
% received bits of time domain,using ifft
      TimeFram = ifft(EqualFram);
%gained the received bits after equalization  
      for j1 = 1:FrameSize    
        TimeBitsRec(j1+((i-1)*FrameSize)) = TimeFram(j1);
      end
end
% ------------------------------------------------------------------- %
%              Make Decision (Including Demodulate BPSK)              %
% ------------------------------------------------------------------- %
BitsRec = zeros(1,FrameSize*FrameNum);
for m = 1:FrameSize*FrameNum
    Real =real(TimeBitsRec(m));
    if Real>0
       BitsRec(1,m)=1;
    else 
       BitsRec(1,m)=0;
    end
end
% ------------------------------------------------------------------- %
%                Compute Bits&Frame Error Number&Rate                 %
% ------------------------------------------------------------------- %
%compute the frame error rate and number
RecFrame = reshape(BitsRec,FrameSize,FrameNum);
GenFrame = reshape(BitsTranstmp,FrameSize,FrameNum);
FrameErrNum = 0;
for n = 1:FrameNum
    if GenFrame(:,n) == RecFrame(:,n)
        FrameErrNum = FrameErrNum;
    else
        FrameErrNum = FrameErrNum+1;
    end
end
BerSnrTable(snr+1,6) = FrameErrNum;
BerSnrTable(snr+1,7) = FrameErrNum/FrameNum;
%comput the bits error rate and number
[ErrNum,Ber] = symerr(BitsTranstmp,BitsRec)

BerSnrTable(snr+1,4) = ErrNum ;
BerSnrTable(snr+1,5) = Ber ;
% end of (for snr = 0:9)
end

figure(1);
plot(BerSnrTable(:,1),BerSnrTable(:,4),'o-');grid on;
title({'Simulation of Single Carrier with Frequency Domain Equalization';'Modulation Method:BPSK';'Channel Coefficients [0.227 0.46 0.688 0.46 0.227]';'';'bit error number of SC-FDE simulation'})
xlabel('SNR(db)');ylabel('BIT ERR NUMBER')
figure(2)
plot(BerSnrTable(:,1),BerSnrTable(:,5),'o-');grid on;
title({'Simulation of Single Carrier with Frequency Domain Equalization';'Modulation Method:BPSK';'Channel Coefficients [0.227 0.46 0.688 0.46 0.227]';'';'bit error rate of SC-FDE simulation'})
xlabel('SNR(db)');ylabel('BIT ERR RATE')
% -------------------------------------------------------------------
time_of_sim = toc
echo on;















⌨️ 快捷键说明

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