www.gusucode.com > matlab编程SC-FDE系统仿真源码程序 > 程序.txt
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) ='); FrameNum=5000;%发送的数据帧数 if isempty(FrameNum) FrameNum = 5; end %FrameSize = input('size of each frame is(default=256) ='); FrameSize=256; %每帧数据的大小 if isempty(FrameSize) FrameSize = 256; end %Chan =input('channel IR is(default=[0.227 0.46 0.688 0.46 0.227]) ='); Chan=[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;%循环前缀大小CPLen=256/8= % ------------------------------------------------------------------- % % Generate Transmit Signal & BPSK Modulation % % ------------------------------------------------------------------- % % generate the random binary stream for transmitting % 产生随机的二进制流对于发射 BitsTranstmp = randint(1,FrameNum*FrameSize); % BitsTranstmp(1:10)为0,1的数据流 % 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 % convenience,reshape 重新安排BitsTrans用于增加cp AddCPtmp = reshape(BitsTrans,FrameSize,FrameNum);%原始数据部分 AddCP = zeros(FrameSize+CPLen,FrameNum); %最终增加CP的数据 AddPrefix = FrameSize-CPLen+1:FrameSize; %存放CP的位置 % the matrix below is as the same function of add cp to each frame one % by one,增加每帧 AddCP = [AddCPtmp(AddPrefix,:);AddCPtmp]; %将原始数据的部分数据作为CP % ------------------------------------------------------------------- % % 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通道系数fft 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时域接收位,使用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;