It seems that there is some problem in simulation as you are getting 0 BER just after 1e-5. Just plot them on one graph using plot but it wont be a water fall curve.anyone can help me with that ?
function NumErrors=OurLDPCEncandDec_without_MMSE(itertion,Rate,Modulation,SNRdB)
% close all; clc ; clear
% Rate=2;Modulation=4;SNRdB=3
% Rate: 2 for 1/2, 4 for 3/4, 6 for 5/6, 8 for 7/8
NumErrors=zeros(1,itertion);
for iter=1:itertion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters Section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load 802_16e_4512_d5_H H -mat;
H1=H(:,1:2256);
H2=H(:,2257:4512);
H=[H2 H1];
if Rate==2
ParityLength=2256;
elseif Rate==4
ParityLength=2256/3;
elseif Rate==6
ParityLength=464;
elseif Rate==8
ParityLength=320;
elseif Rate==10
ParityLength=240;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create Signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xt_long_with_CP=[];
xt_long_bits=[];
N_sym=100;
henc = fec.ldpcenc(H);
for k=1:N_sym
InfoBits=randsrc(1,2256,[1 0]); % Generate 2256 information bits
xt_long_bits=[xt_long_bits InfoBits];
% Encode and Modulate
CodedBits= encode(henc,InfoBits);
% Rate Matching
ParityLocations=2256+randperm(2256);
ParityLocations=ParityLocations(1:ParityLength);
TotalLocations(:,k)=[1:2256,ParityLocations]; % Should be an output of the encoder
CodedBits=CodedBits(TotalLocations(:,k));
Symbols=ModulateQAM(CodedBits,Modulation);
FFTsize=2^(ceil(log2(length(Symbols))));
ActiveSCs=length(Symbols);
PilotLocations=1:4:FFTsize; %pilot loc /for mod=4,16 spacing = 3. /for mod=64 spacing =4
SC_loc=setdiff(1:FFTsize,PilotLocations); SC_loc=SC_loc(1:ActiveSCs); %info location
%%%%pilots%%%%
x_f=zeros(FFTsize,1); x_f(SC_loc)=Symbols;
Xp=randsrc(1,length(PilotLocations),[-1 1]); %Pilot generation
Pilots_PRBS(:,k)=Xp.'; % PRBS patterns
x_f(PilotLocations)=Xp.'; %insertion of the pilots
xt=ifft(x_f);
xt_withCP=[xt(end-1023:end);xt];
xt_long_with_CP=[xt_long_with_CP;xt_withCP];
end
%%%%%%%%%%%%%%%%%%%%%%%%Channel%%%%%%%%%%%%%%%%%%%%%%%%%%
Fs=10e6; %Sampling rate
f_m=10; %Doppler spread
N_samples=length(xt_long_with_CP);
T=N_samples/Fs; %Sample time
SNR=10^(SNRdB/10);
% Taking channel parameters from ITU table
TapPowerdB=[0 -9.7 -19.2 -22.8]; % in dB
Delay=[1 110 190 410]*1e-9; % in Sec
% ChannelLength=length(TapPower);
a_samples=[];
%%%%Tap power in dB to linear%%%%
TapPower=10.^(TapPowerdB/10);
% TapPower=TapPower/norm(TapPower); % Normalize to unit channel power
F_low=f_m*10; % usaully 10*f_m the low sampling
% freq of the channel coefficients
N_low=ceil(T*F_low);
%%%%Gausssian random process pass throw filter(flat/U-shaped)%%%%
h=firpm(64,[0 2*f_m/F_low 2*f_m/F_low*1.2 1],[1 1 0 0 ]);
h=h/norm(h);
% channel_length=length(h);
for k=1:length(TapPower)
a_low_temp=conv((randn(1,N_low+64)+1i*randn(1,N_low+64))/sqrt(2),h);%was ...,h)*TapPower(k);
a_low_temp=a_low_temp(65:N_low+64); % Generate first tap sampled at low freq
a_low(k,:)=a_low_temp;
channel_length=6;
%%%%Upsample To Fs%%%%
a_samples(k,:)=resample(a_low(k,:),Fs,F_low);
Sigvar=var(a_samples(k,:));
a_samples(k,:)=a_samples(k,:)*sqrt((TapPower(k)/Sigvar));
end
%%%%Initilaize Delay Vector%%%%
DelayInSamples=ceil(Delay*Fs);
DelayInSamples=DelayInSamples-DelayInSamples(1);
y=zeros(1,length(xt_long_with_CP));
%%%%Convolution%%%%
for k=max(DelayInSamples)+1:length(xt_long_with_CP)
for j=1:length(TapPower)
a(j)=xt_long_with_CP(k-DelayInSamples(j))*a_samples(j,k);
end
y(k)=sum(a);
end
% Add Noise
SNR_corrected=SNR*(1366+2256)/FFTsize; %need to generic fit for qpsk 2256 infobits + 1366 pilots
sigma_noise=norm(xt_long_with_CP)/sqrt(length(y)*SNR_corrected);
y=y+sigma_noise*(randn(size(y))+1i*randn(size(y)))/sqrt(2);
yBeforeCP_RemoveMatrix=reshape(y.',FFTsize+1024,N_sym);
yCP_RemoveMatrix=yBeforeCP_RemoveMatrix(1025:end,:);
Y_matrix_PostFFT=fft(yCP_RemoveMatrix);
for kk=1:N_sym,
% H_est = MMSE_CE(Y_matrix_PostFFT(:,kk),Pilots_PRBS(:,kk),PilotLocations,FFTsize,4,h,SNR);
% h_est = ifft(H_est); h_DFT = h_est(1:channel_length);
% H_DFT = fft(h_DFT,FFTsize);
Y_Pilots=Y_matrix_PostFFT(PilotLocations,kk);
EstTimeDomainChannel=ifft(Y_Pilots.*Pilots_PRBS(:,kk));%Taking only pilots
EstTimeDomainChannel=EstTimeDomainChannel(1:(channel_length)); % Kill contibutions outside the CP duration
H_est=fft(EstTimeDomainChannel,FFTsize); % est. channel
demodulatedSCs=Y_matrix_PostFFT(:,kk)./H_est;
Y_equalized_withoutPilots(:,kk)=demodulatedSCs(SC_loc);
ppSNR(:,kk)=abs(H_est(SC_loc)).^2/(sigma_noise^2*FFTsize);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Decode Signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DecodedBits_long=[];
for kk=1:N_sym,
LLRs=SISO_LLR(Y_equalized_withoutPilots(:,kk),ppSNR(:,kk),Modulation);
LLR_rate_matched=zeros(1,2*2256);
LLR_rate_matched(TotalLocations(:,kk))=LLRs;
hdec=fec.ldpcdec(H);
DecodedBits=decode(hdec, LLR_rate_matched);
DecodedBits_long=[DecodedBits_long DecodedBits];
end
NumErrors(1,iter)=sum(DecodedBits_long ~=xt_long_bits); % Count errors
end
%-------------------------------------------------------
function QAM_Symbols=ModulateQAM(CodedBits,Modulation)
% QPSK mapping
MapQPSK= ([1+i 1-i -1+i -1-i])/sqrt(2);
% 16QAM mapping
Map_16QAM= ((2/sqrt(10))* ...
[ 0.5+0.5*i 0.5+1.5*i 0.5-0.5*i 0.5-1.5*i ...
1.5+0.5*i 1.5+1.5*i 1.5-0.5*i 1.5-1.5*i ....
-0.5+0.5*i -0.5+1.5*i -0.5-0.5*i -0.5-1.5*i ....
-1.5+0.5*i -1.5+1.5*i -1.5-0.5*i -1.5-1.5*i]);
% 64QAM mapping
Map_64QAM= ((2/sqrt(42))* ...
[ 1.5+1.5*i 1.5+0.5*i 1.5+2.5*i 1.5+3.5*i ...
1.5-1.5*i 1.5-0.5*i 1.5-2.5*i 1.5-3.5*i ...
0.5+1.5*i 0.5+0.5*i 0.5+2.5*i 0.5+3.5*i ...
0.5-1.5*i 0.5-0.5*i 0.5-2.5*i 0.5-3.5*i ...
2.5+1.5*i 2.5+0.5*i 2.5+2.5*i 2.5+3.5*i ...
2.5-1.5*i 2.5-0.5*i 2.5-2.5*i 2.5-3.5*i ...
3.5+1.5*i 3.5+0.5*i 3.5+2.5*i 3.5+3.5*i ...
3.5-1.5*i 3.5-0.5*i 3.5-2.5*i 3.5-3.5*i ...
-1.5+1.5*i -1.5+0.5*i -1.5+2.5*i -1.5+3.5*i ...
-1.5-1.5*i -1.5-0.5*i -1.5-2.5*i -1.5-3.5*i ...
-0.5+1.5*i -0.5+0.5*i -0.5+2.5*i -0.5+3.5*i ...
-0.5-1.5*i -0.5-0.5*i -0.5-2.5*i -0.5-3.5*i ...
-2.5+1.5*i -2.5+0.5*i -2.5+2.5*i -2.5+3.5*i ...
-2.5-1.5*i -2.5-0.5*i -2.5-2.5*i -2.5-3.5*i ...
-3.5+1.5*i -3.5+0.5*i -3.5+2.5*i -3.5+3.5*i ...
-3.5-1.5*i -3.5-0.5*i -3.5-2.5*i -3.5-3.5*i]);
if Modulation==4
Map=MapQPSK;
elseif Modulation==16
Map=Map_16QAM;
elseif Modulation==64
Map=Map_64QAM;
end;
BitsPerCarrier=log2(Modulation);
CodedBitMat=reshape(CodedBits.',BitsPerCarrier,length(CodedBits)/BitsPerCarrier);
SymbolIndices=bi2de(fliplr(CodedBitMat.'))+1;
QAM_Symbols=Map(SymbolIndices);
Hi,
Yes to simulate ber=10^-6, you must send 10^7 bits but the incertitude is big. If you sen 10^8 you will have ber=10^-6 with 1% incertitude.
You can encode a matrix. This is an example :
N_sym=4512;
n = 6; k = 4; % Set codeword length and message length.
x_Tx_Bits=randsrc(N_sym,4,[0 1]); % Message is a binary matrix.
code = encode(x_Tx_Bits,n,k,'cyclic');
But, you don't give enough parameters of LDPC coder. henc ?
berfit is doing more than you want to do. To plot those three vectors in one graph just use:
figure(1);
subplot(311), plot(snr, ber_qpsk);
subplot(312), plot(snr, ber_16qam);
subplot(313), plot(snr, ber_64qam);
Then, you can use the bertool command to create vectors of the theoretical BER curves for psk and qam, and plot them next to those.
- Ryan
- Why you are using the iterative loop ? could be for iterative decoding of LDPC code ?!
- encode(henc,InfoBits) doesn't support Matrix input.
function NumErrors=OurLDPCEncandDec_without_MMSE(itertion,Rate,Modulation,SNRdB)
% close all; clc ;
%clear all ;
% Rate=2;
% Modulation=4;
% SNRdB=3;
% itertion=5;
% Rate: 2 for 1/2, 4 for 3/4, 6 for 5/6, 8 for 7/8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters Section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Symbols_length=2256;
CP_lenght=1024;
N_sym=100;
if Rate==2
ParityLength=2256;
elseif Rate==4
ParityLength=2256/3;
elseif Rate==6
ParityLength=464;
elseif Rate==8
ParityLength=320;
elseif Rate==10
ParityLength=240;
end;
load 802_16e_4512_d5_H H -mat;
H1=H,1:2256);
H2=H,2257:4512);
H=[H2 H1];
henc = fec.ldpcenc(H);
hdec = fec.ldpcdec(H);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IFFT/FFT Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FFTsize=2^(ceil(log2(Symbols_length)));
ActiveSCs=Symbols_length;
PilotLocations=1:4:FFTsize; %pilot loc /for mod=4,16 spacing = 3. /for mod=64 spacing =4
SC_loc=setdiff(1:FFTsize,PilotLocations); SC_loc=SC_loc(1:ActiveSCs); %info location
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fs=10e6; %Sampling rate
f_m=10; %Doppler spread
N_samples=N_sym*(FFTsize+CP_lenght);
T=N_samples/Fs; %Sample time
% Taking channel parameters from ITU table
TapPowerdB=[0 -9.7 -19.2 -22.8]; % in dB
Delay=[1 110 190 410]*1e-9; % in Sec
% ChannelLength=length(TapPower);
a_samples=[];
%%%%Tap power in dB to linear%%%%
TapPower=10.^(TapPowerdB/10);
% TapPower=TapPower/norm(TapPower); % Normalize to unit channel power
F_low=f_m*10; % usaully 10*f_m the low sampling
% freq of the channel coefficients
N_low=ceil(T*F_low);
%%%%Gausssian random process pass throw filter(flat/U-shaped)%%%%
h=firpm(64,[0 2*f_m/F_low 2*f_m/F_low*1.2 1],[1 1 0 0 ]);
h=h/norm(h);
% channel_length=length(h);
for k=1:length(TapPower)
a_low_temp=conv((randn(1,N_low+64)+1i*randn(1,N_low+64))/sqrt(2),h);%was ...,h)*TapPower(k);
a_low_temp=a_low_temp(65:N_low+64); % Generate first tap sampled at low freq
a_low(k,=a_low_temp;
channel_length=6;
%%%%Upsample To Fs%%%%
a_samples(k,=resample(a_low(k, ,Fs,F_low);
Sigvar=var(a_samples(k,);
a_samples(k,=a_samples(k, *sqrt((TapPower(k)/Sigvar));
end
%%%%Initilaize Delay Vector%%%%
DelayInSamples=ceil(Delay*Fs);
DelayInSamples=DelayInSamples-DelayInSamples(1);
%%% Noise parameters
SNR=10^(SNRdB/10);
SNR_corrected=SNR*(1366+2256)/FFTsize; %need to generic fit for qpsk 2256 infobits + 1366 pilots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Began iteration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NumErrors=zeros(1,itertion);
for iter=1:itertion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Transmitter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xt_long_with_CP=[];
xt_long_bits=[];
for k=1:N_sym
InfoBits=randsrc(1,2256,[1 0]); % Generate 2256 information bits
xt_long_bits=[xt_long_bits InfoBits];
% Encode and Modulate
CodedBits= encode(henc,InfoBits);
% Rate Matching
ParityLocations=2256+randperm(2256);
ParityLocations=ParityLocations(1arityLength);
TotalLocations,k)=[1:2256,ParityLocations]; % Should be an output of the encoder
CodedBits=CodedBits(TotalLocations,k));
Symbols=ModulateQAM(CodedBits,Modulation);
%%%%pilots%%%%
x_f=zeros(FFTsize,1); x_f(SC_loc)=Symbols;
Xp=randsrc(1,length(PilotLocations),[-1 1]); %Pilot generation
Pilots_PRBS,k)=Xp.'; % PRBS patterns
x_f(PilotLocations)=Xp.'; %insertion of the pilots
xt=ifft(x_f);
xt_withCP=[xt(end-1023:end);xt];
xt_long_with_CP=[xt_long_with_CP;xt_withCP];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y=zeros(1,length(xt_long_with_CP));
%%%%Convolution%%%%
for k=max(DelayInSamples)+1:length(xt_long_with_CP)
for j=1:length(TapPower)
a(j)=xt_long_with_CP(k-DelayInSamples(j))*a_samples(j,k);
end
y(k)=sum(a);
end
%%%Noise%%%
sigma_noise=norm(xt_long_with_CP)/sqrt(length*SNR_corrected);
y=y+sigma_noise*(randn(size)+1i*randn(size ))/sqrt(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Receiver
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yBeforeCP_RemoveMatrix=reshape(y.',FFTsize+1024,N_sym);
yCP_RemoveMatrix=yBeforeCP_RemoveMatrix(1025:end,;
Y_matrix_PostFFT=fft(yCP_RemoveMatrix);
for kk=1:N_sym,
% H_est = MMSE_CE(Y_matrix_PostFFT,kk),Pilots_PRBS ,kk),PilotLocations,FFTsize,4,h,SNR);
% h_est = ifft(H_est); h_DFT = h_est(1:channel_length);
% H_DFT = fft(h_DFT,FFTsize);
Y_Pilots=Y_matrix_PostFFT(PilotLocations,kk);
EstTimeDomainChannel=ifft(Y_Pilots.*Pilots_PRBS,kk));%Taking only pilots
EstTimeDomainChannel=EstTimeDomainChannel(1channel_length)); % Kill contibutions outside the CP duration
H_est=fft(EstTimeDomainChannel,FFTsize); % est. channel
demodulatedSCs=Y_matrix_PostFFT,kk)./H_est;
Y_equalized_withoutPilots,kk)=demodulatedSCs(SC_loc);
ppSNR,kk)=abs(H_est(SC_loc)).^2/(sigma_noise^2*FFTsize);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Decode Signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DecodedBits_long=[];
for kk=1:N_sym,
LLRs=SISO_LLR(Y_equalized_withoutPilots,kk),ppSNR ,kk),Modulation);
LLR_rate_matched=zeros(1,2*2256);
LLR_rate_matched(TotalLocations,kk))=LLRs;
DecodedBits=decode(hdec, LLR_rate_matched);
DecodedBits_long=[DecodedBits_long DecodedBits];
end
NumErrors(1,iter)=sum(DecodedBits_long ~=xt_long_bits); % Count errors
end
_For Channel effect, why you don't apply effects to one symbol. It is long enough 2256.
This loop will eliminate the send off 1000 symbol every simulation.while ((i_frame<FrameNb)&&(NumErrors<MaxErrorBits))
N_sym=100;
Frame=10*N_sym;
FrameNb=100;
i_frame=1;
ErrorBits=0;
MaxErrorBits=100;
while ((i_frame<FrameNb)&&(ErrorBits<MaxErrorBits))...
for k=1:Frame
function NumErrors=OurLDPCEncandDec_without_MMSE(itertion,Rate,Modulation,SNRdB)
% % close all; clc ;
% clear all ;
% Rate=2;
% Modulation=4;
% SNRdB=3;
% itertion=5;
% Rate: 2 for 1/2, 4 for 3/4, 6 for 5/6, 8 for 7/8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters Section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Symbols_length=2256;
CP_lenght=1024;
N_sym=100;
Frame=10*N_sym;
FrameNb=100;
MaxErrorBits=1000;
if Rate==2
ParityLength=2256;
elseif Rate==4
ParityLength=2256/3;
elseif Rate==6
ParityLength=464;
elseif Rate==8
ParityLength=320;
elseif Rate==10
ParityLength=240;
end;
load 802_16e_4512_d5_H H -mat;
H1=H(:,1:2256);
H2=H(:,2257:4512);
H=[H2 H1];
henc = fec.ldpcenc(H);
hdec = fec.ldpcdec(H);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IFFT/FFT Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FFTsize=2^(ceil(log2(Symbols_length)));
ActiveSCs=Symbols_length;
PilotLocations=1:4:FFTsize; %pilot loc /for mod=4,16 spacing = 3. /for mod=64 spacing =4
SC_loc=setdiff(1:FFTsize,PilotLocations); SC_loc=SC_loc(1:ActiveSCs); %info location
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fs=10e6; %Sampling rate
f_m=10; %Doppler spread
N_samples=N_sym*(FFTsize+CP_lenght);
T=N_samples/Fs; %Sample time
% Taking channel parameters from ITU table
TapPowerdB=[0 -9.7 -19.2 -22.8]; % in dB
Delay=[1 110 190 410]*1e-9; % in Sec
% ChannelLength=length(TapPower);
a_samples=[];
%%%%Tap power in dB to linear%%%%
TapPower=10.^(TapPowerdB/10);
% TapPower=TapPower/norm(TapPower); % Normalize to unit channel power
F_low=f_m*10; % usaully 10*f_m the low sampling
% freq of the channel coefficients
N_low=ceil(T*F_low);
%%%%Gausssian random process pass throw filter(flat/U-shaped)%%%%
h=firpm(64,[0 2*f_m/F_low 2*f_m/F_low*1.2 1],[1 1 0 0 ]);
h=h/norm(h);
% channel_length=length(h);
for k=1:length(TapPower)
a_low_temp=conv((randn(1,N_low+64)+1i*randn(1,N_low+64))/sqrt(2),h);%was ...,h)*TapPower(k);
a_low_temp=a_low_temp(65:N_low+64); % Generate first tap sampled at low freq
a_low(k,:)=a_low_temp;
channel_length=6;
%%%%Upsample To Fs%%%%
a_samples(k,:)=resample(a_low(k,:),Fs,F_low);
Sigvar=var(a_samples(k,:));
a_samples(k,:)=a_samples(k,:)*sqrt((TapPower(k)/Sigvar));
end
%%%%Initilaize Delay Vector%%%%
DelayInSamples=ceil(Delay*Fs);
DelayInSamples=DelayInSamples-DelayInSamples(1);
%%% Noise parameters
SNR=10^(SNRdB/10);
SNR_corrected=SNR*(1366+2256)/FFTsize; %need to generic fit for qpsk 2256 infobits + 1366 pilots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Began iteration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NumErrors=zeros(1,itertion);
for iter=1:itertion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Transmitter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i_frame=1;
ErrorBits_all_frame=0;
while ((i_frame<FrameNb)&&(ErrorBits_all_frame<MaxErrorBits))
xt_long_with_CP=[];
xt_long_bits=[];
for k=1:N_sym
InfoBits=randsrc(1,2256,[1 0]); % Generate 2256 information bits
xt_long_bits=[xt_long_bits InfoBits];
% Encode and Modulate
CodedBits= encode(henc,InfoBits);
% Rate Matching
ParityLocations=2256+randperm(2256);
ParityLocations=ParityLocations(1:ParityLength);
TotalLocations(:,k)=[1:2256,ParityLocations]; % Should be an output of the encoder
CodedBits=CodedBits(TotalLocations(:,k));
Symbols=ModulateQAM(CodedBits,Modulation);
%%%%pilots%%%%
x_f=zeros(FFTsize,1); x_f(SC_loc)=Symbols;
Xp=randsrc(1,length(PilotLocations),[-1 1]); %Pilot generation
Pilots_PRBS(:,k)=Xp.'; % PRBS patterns
x_f(PilotLocations)=Xp.'; %insertion of the pilots
xt=ifft(x_f);
xt_withCP=[xt(end-1023:end);xt];
xt_long_with_CP=[xt_long_with_CP;xt_withCP];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Channel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y=zeros(1,length(xt_long_with_CP));
%%%%Convolution%%%%
for k=max(DelayInSamples)+1:length(xt_long_with_CP)
for j=1:length(TapPower)
a(j)=xt_long_with_CP(k-DelayInSamples(j))*a_samples(j,k);
end
y(k)=sum(a);
end
%%%Noise%%%
sigma_noise=norm(xt_long_with_CP)/sqrt(length(y)*SNR_corrected);
y=y+sigma_noise*(randn(size(y))+1i*randn(size(y)))/sqrt(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Receiver
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yBeforeCP_RemoveMatrix=reshape(y.',FFTsize+1024,N_sym);
yCP_RemoveMatrix=yBeforeCP_RemoveMatrix(1025:end,:);
Y_matrix_PostFFT=fft(yCP_RemoveMatrix);
for kk=1:N_sym,
% H_est = MMSE_CE(Y_matrix_PostFFT(:,kk),Pilots_PRBS(:,kk),PilotLocations,FFTsize,4,h,SNR);
% h_est = ifft(H_est); h_DFT = h_est(1:channel_length);
% H_DFT = fft(h_DFT,FFTsize);
Y_Pilots=Y_matrix_PostFFT(PilotLocations,kk);
EstTimeDomainChannel=ifft(Y_Pilots.*Pilots_PRBS(:,kk));%Taking only pilots
EstTimeDomainChannel=EstTimeDomainChannel(1:(channel_length)); % Kill contibutions outside the CP duration
H_est=fft(EstTimeDomainChannel,FFTsize); % est. channel
demodulatedSCs=Y_matrix_PostFFT(:,kk)./H_est;
Y_equalized_withoutPilots(:,kk)=demodulatedSCs(SC_loc);
ppSNR(:,kk)=abs(H_est(SC_loc)).^2/(sigma_noise^2*FFTsize);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Decode Signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DecodedBits_long=[];
for kk=1:N_sym,
LLRs=SISO_LLR(Y_equalized_withoutPilots(:,kk),ppSNR(:,kk),Modulation);
LLR_rate_matched=zeros(1,2*2256);
LLR_rate_matched(TotalLocations(:,kk))=LLRs;
DecodedBits=decode(hdec, LLR_rate_matched);
DecodedBits_long=[DecodedBits_long DecodedBits];
end
ErrorBits_one_frame=sum(DecodedBits_long ~=xt_long_bits); % Count errors
ErrorBits_all_frame=ErrorBits_all_frame+ErrorBits_one_frame;
i_frame=i_frame+1;
end % End while loop (all frame send or 100 errors bits detected)
NumErrors(1,iter)=ErrorBits_all_frame;
all_transmitted_bits=(i_frame-1)*N_samples;
ber_values(1,iter)=ErrorBits_all_frame/all_transmitted_bits;
end % End iter loop
NumErrors(1,iter)=ErrorBits_all_frame;
all_transmitted_bits=(i_frame-1)*N_samples;
ber_values(1,iter)=ErrorBits_all_frame/all_transmitted_bits;
(i_frame-1)*N_samples
SNR_corrected=SNRdB*(1366 pilots + 2256 data bins)/FFTsize
EbNo = 0:2:15;
EsNo= EbNo+10*log10(Used_subcarrier/len_fft)+ 10*log10(len_fft/Symbol_interval) + 10*log10(k);
snr=EsNo - 10*log10(len_fft/Symbol_interval);
chan_awgn = awgn(ser_data,snr(ii),'measured');
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?