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

📄 awgnofdm.m

📁 正交频分复用系统(OFDM)的频率偏移误差抑制技术仿真程序
💻 M
字号:
%---------------------------------------------------------------
%Simulation file
%OFDM System with 16 QAM Modulation
%Size of FFT/IFFT=16
%Needed M-Files
% QAMlev16
% QAM16
% gngauss
% discrm16
% revsymQAM16
% levtobin16
%Author: 王博
%Filename: awgnofdm.m
%-----------------------------------------------------------------------------

%clearing and setting variables in the MATLAB environment
clear
home
format short g
N=16;                           %size of FFT
iterate=1000;                     %number of iterations per Eb/No snr value 
error=0:2:30;                     % Eb/No values to be scanned
%declaration of frequency offset corresponding from 0% to10%
%with 2% increments
%1% computed as (1/(size of FFT))/100
%so for FFT size 16 = => 1%=1/(16*100)=0.000625
freqerr=0:.00125:.00625;              %frequency offset with 2% increments
freqerr=[ ];                         %matrix where BER values will be saved
echo off
%there will be 3 loops for the whole simulation
%for each frequency offset value
%the snr is sweeped
%for each snr value there is an repetitive iteration

for ff=1:length(freqerr)%first loop (frequency offset)
for diff=1:length(error)%second loop (snr values)

   echo off;
   count=0;
errorcount=0;             %variable that monitors the number of bit
                        %errors
%computation of the corresponding sgma or variance of the
%Gaussian Noise generator. The whole system is normalized meaning
%the symbol %(QAM16) signaling is kept constant while increasing the 
%variance of the GN Generator
d=1;
Eav=10*d^2;            %average power of a 16 QAM system
snr=10^(error(diff)/10);    %computation of linear snr; error is in dB
sgma=sqrt(16*Eav/(8*snr)); %computation of the variance of Gaussian Generator
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Numberous iteration starts here; this loop 
for go = 1: iterate
%start of transmitter model
y = rand(1,64);      %generates random values between 0 to 1
o = y > .5;          %floors or ceils; converts to logic 1 or 0

for B = 0:15         %groups the bits into sets of 4 numbers
sym(B+1, 1:4) = o(4*B+1:4*B+4);   %divides into 4 bit chunks
end

% QAM leveler
for B = 0:15            %assigns a level number per combination of 4 number
symlev(B+1) = QAMlev16(sym(B+1, 1:4)); % QAMlev16 returns the level number
end

%generation of 16 QAM mapped symbols
for B = 1:16       %each level will be assigned to the QAM constellation
   aftQAM16(B) = QAM16(symlev(B));  %maps to a 16 point QAM point
end

%computation of the IFFT complex modulation
OUTIFFT = N.*ifft(aftQAM16,N);
%end of transmitter model

%channel model starts here
for B = 1:16,
   [a b]=gngauss(sgma);          %generate Gaussian Noise
   %here we insert noise in the channel
   OUTIFFTplusnoisel(B) = OUTIFFT(B)+a+i*b;
   %frequency offset is also inserted into the signal
   %resulting vector OUT(B) is now affected by frequency offset and
   %Gaussian Noise
   OUT(B) = OUTIFFTplusnoisel(B)*exp(i*2*pi(B-1)*freqerr(ff));
end;
%end of channel model
%start of receiver model
%computation of the FFT; complex demodulation
OUTFFT1 = fft(OUT,N)./N;

%start of receiver model
%we calculate the distances of the OUTFFT points to possible
%QAM constellation points
%the one with the least distance will assign as output
for B = 1:16
   outsym(B)=discrim16(OUTFFT1(B));
%return the nearest constellation coordinates
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%reassigns the constellation coordinate to a voltage level
for B=1:16
revsymlev16(B)=revsymQAM16(outsym(B));
%voltage level corresponds to the assignment to QAMlev16
end

%reverse of QAM leveler
for B=1:16
outbin(B,1:4)=levtobin16(revsymlev16(B));
% reassigns the voltage level to a binary pair
end
%end of receiver model

%start of bit error rate computation
%evaluation of the bit discrepancies found per 4 bit sets
for B=1:16
if outbin(B,1:4)==sym(B,1:4)
   errorcount=errorcount;           %perfect reception is achiever
else
   difference=sum(xor(outbin(B,1:4),sym(B,1:4)));
%count the bit difference
  errorcount=errorcount+difference;
%accumulate the bit errors
end          %end for the if statement
end

end          %back to the numerous iteration
             %corresponds to the for loop of “for go=1:iterate”

%after counting all the bit errors per set of parameters
%compute the normalized number of errors accumulated
%with respect to the number of bits generated
bang(diff)=errorcount/(iterate*16*4);

end              %now update for new snr value
%corresponds to for loop “for diff=1:length(error)”
%second loop (snr values)

%save the error count values for all levels of frequency offset
freqres=[freqres;bang];

end      %now update for a new frequency offset value
         %corresponds to for loop “for ff=1:length(freqerr)”

a=clock;   %the time information
%saving the significant information for this simulation run save AWGNconvofdm freqres error N iterate d freqerr a
%displaying the BER curves
%figure; semilogy(error,freqres);

⌨️ 快捷键说明

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