%**************************************************************************
%The simulation adopted the model in paper "ML estimation of time and
%frequency offset" written by J.J van de Beek e.t.Programmed by binyue-Liu
%**************************************************************************
close all; clear all;
N=1024; %length of one symbol
L=128; %length of CP
SNR=15;
Symbol_num=6;
Bit_sym=4; %16_QAM
s=randint(1,N*Symbol_num*Bit_sym);
s_map=qammod(2.^(Bit_sym-1:-1:0)*reshape(s,Bit_sym,N*Symbol_num),16);
%Reflecting to the 16_QAM constallation
t=ifft(reshape(s_map,N,Symbol_num))*N; %OFDM modulation
t_add_CP=[t(N-L+1:N,:);t]; %Addition with CP
SNR_line=10^(SNR/10);
transmit=reshape(t_add_CP,1,(N+L)*Symbol_num);
sigmma=(1^2+3^2)/2/SNR_line;
Noise=(randn(1,(N+L)*Symbol_num)+j*randn(1,(N+L)*Symbol_num))*sqrt(sigmma/2);
recieve=zeros(1,Symbol_num*(N+L));
erro_rate=zeros(1,10);
index=1;
for e=0.02:0.01:0.12; %The offset of norminal carrier frequency
for i=1:Symbol_num;
k=1:N+L;
recieve((i-1)*(N+L)+1:(N+L)*i)=transmit((i-1)*(N+L)+1:(N+L)*i).*exp(j*2*pi*e*k/N);
end
r=reshape(recieve+Noise,N+L,Symbol_num);
r1=reshape(fft(r(L+1:end,:))/N,1,N*Symbol_num);
Out_symbol=qamdemod(r1,16);
Out_bit=zeros(4,N*Symbol_num);
for i=1:N*Symbol_num;
for k=1:Bit_sym
Out_bit(k,i)=floor(Out_symbol(i)/(2^(Bit_sym-k)));
if Out_bit(k,i)==1
Out_symbol(i)=Out_symbol(i)-2^(Bit_sym-k);
else
end
end
end
Out_bit=reshape(Out_bit,1,Bit_sym*N*Symbol_num);
erro_rate(index)=length(find(Out_bit~=s))/length(s);
index=index+1;
end
semilogy(0.02:0.01:0.12,erro_rate,'-*')
axis([0.01 0.12 10^(-5) 1])