elec6141 august 15, 2014 - codelooker · web viewthe ber for rayleigh fading and awgn channel for...
TRANSCRIPT
ELEC6141 August 15, 2014
WIRELESS COMMUNICATION
PROJECT REPORT
Prepared by
Gurjot Singh (ID: 7144628)Vivek Kumar (ID: 7182422)
Maanvir Sidhu (ID: 6988474)
Instructor: Dr. Yousef R. Shayan
“We certify that this submission is the original work of members of the group andMeets the Faculty's Expectations of Originality”
ABSTRACT
Department of Electrical and Computer Engineering Page 1
ELEC6141 August 15, 2014
In this report we will be discussing the 16-QAM
(Quadrature amplitude Modulation) Communication
system. We will determine the Bit Error Rate (BER)
performance of 16-QAM scheme over AWGN channels
with and without coding (Gray Coding). System
performance will be evaluated on the bases of simulated
data compared to theoretical data. Fading is also considered
in this 16-QAM system with the Doppler Spread due to
mobile movement in the channel. Simulation for the BER
will be done with the mobile moving at certain speed
without using any equalization scheme. Later we will
discuss about the improvement in the coded performance of
the system by introducing an inter-leaver.
Keywords: 16QAM System, Hamming code (15, 11),
Rayleigh fading, Interleaver.
1. INTRODUCTION
Quadrature Amplitude Modulation (QAM) is both analog
and digital modulation scheme which transmits two analog
or digital bit streams by modulating the amplitudes of two
carrier waves, using amplitude shift keying and amplitude
modulation scheme [1].
QAM signal is implemented by mixing two sine waves
which are 90 degrees out of phase with one another. One
signal is called I_signal and the other one Q_signal. These
carriers are combined together during transmitting process
and the carriers are separated and information is extracted
from each carrier at the receiver side. For detection and
correction of errors, we use Hamming code. Hamming
codes are a family of linear error-correcting codes [2], we
have used [15, 11] hamming code which can detect and
correct up to two bit errors.
We are also using an Interleaver to improve the overall
system performance. The primary purpose of the
Interleaver is to read and write the data out of sequence
involving forward error correction coding. The coded data
(bits of codeword’s) gets Interleaved (scrambled) before
modulation and then transmitted. At the receiver side after
demodulation, received bit is de-interleaved.
2. UNCODED 16QAM SYSTEM
2.1 Background
In a Digital Communication System, Quadrature Amplitude
Modulation (QAM) is a digital modulation scheme that
conveys data by changing, or modulating the some aspect
of a carrier signal or the carrier wave. As shown in block
diagram Figure2.1, first we generate input bits, and then
these bits are divided into a matrix of four rows in mapping
[3]. The Mapper output then goes into a channel where
AWGN (Additive White Noise) is added to signal. The
signal with AWGN noise is delivered to detector. Lastly,
the initial input and the output of detector are compared to
find BER.
Figure 2.1 Base band Model for uncoded system
2.3Finding the Bit Error Rate
2.3.1 Simulated and Theoretical Calculation
The simulated bit error rate is obtained by comparing input
data and output data using the exclusive OR function
giving us the difference between the generated data and the
received data. After that, we find the number of errors
occurred by counting the number of different bits.
Therefore the probability of bit error, (where M= L^2) is
given by:
2.4 Plotting Theoretical and Simulated BER
We represent the simulated BER with BLUE color and
theoretical BER with GREEN color as shown in Figure 2.2
Department of Electrical and Computer Engineering Page 2
ELEC6141 August 15, 2014
Figure 2.2 Plot of BER vs Eb/No (dB) for uncoded 16QAM
3. CODED 16QAM SYSTEM
3.1 Background
The Coded 16QAM system is same as the uncoded
16QAM, but with two extra blocks. The encoder block.
before the mapper and the decorder block after the detector
as shown in Figure 3.1.
Figure 3.1 System Model for Coded 16 QAM
We use (15,11) hamming code as the coding channel of the
system, where n = 15 and k = 11.
The channel Bit Error Probability (Pc) of the uncoded
16QAM system is:
Formula of theoretical BER is:
In our simulation we are dividing the input bits into N/11
messages of 11 bits each. In the encoder, the generator
matrix is generated using the parity check matrix.
Thus, generator matrix can be written as:
3.2Simulated and Theoretical Bit Error Rate
To find the simulated bit error rate, the output of decoder is
entered to the comparator where it is compared with the 11
bit message inputs. Then by comparing input data and
output data using the exclusive OR function, we get the
difference between the generated data and the received
data.
3.3 Plotting the Theoretical and Stimulated BER
We represent the simulated BER for coded 16QAM by
GREEN and theoretical BER of Coded 16QAM by BLUE
as shown in Figure 3.2
Figure 3.2 Plot of BER vs Eb/No for 16QAM with Coding
Department of Electrical and Computer Engineering Page 3
ELEC6141 August 15, 2014
4. 16QAM WITH RAYLEIGH FADING
4.1 Background
Doppler spread causes channel fading, which we will
consider in this system. The type of fading (Slow or Fast) is
evaluated after calculating Coherence time (Tc) and
Symbol period (Ts) and we compare them.
Value of Ts= 2µs, to find Tc we need to calculate Doppler
spread (fm) first.
By comparing Tc and Ts, we find that Ts<<Tc which
means we have slow fading in the channel and the channel
will change after each Tc seconds or after each 450 bits.
Figure 4.1 Rayleigh Fading
We use Rayleigh distribution to introduce fading effect as
shown in Figure 4.1. The probability density function of
Rayleigh distribution is given as:
4.2 Theoretical and Simulated Bit Error Rate (BER)
The simulation for both Coded and Uncoded systems with
fading is done in the similar way.
4.3 Plotting Theoretical and Simulated BER
The BER for Rayleigh fading and AWGN channel for
16QAM uncoded is shown in Figure 4.1 and coded in
Figure 4.2 respectively.
Figure 4.1 Rayleigh fading channel for 16QAM without
coding
Figure4.2 Coded information of Rayleigh fading channel
for 16 QAM
5. 16QAM CODED SYSTEM WITH
INTERLEAVER
5.1 Background
An Interleaver is used to improve the overall system
performance. The primary purpose of the Interleaver is to
read and write the data out of sequence involving forward
Department of Electrical and Computer Engineering Page 4
ELEC6141 August 15, 2014
error correction coding. The coded data (bits of
codeword’s) gets interleaved (scrambled) before
modulation and then transmitted as shown in Figure 5.1
Figure 5.1 Interleaving
At the receiver side after demodulation, received bits are
de-interleaved as shown in Figure 5.2.
Figure 5.2 De-Interleaver
During transmission, bits in the same codeword are
separated by d-1 other bits/symbols. Bits in the same
codeword experiences independent fading if the separation
in time is greater than the channel coherence time (Tc).
Deep Interleaver happens when the condition dTb-coded
>Tc is satisfied, where d is the depth of the Interleaver.
In Interleaver, the data which is a matrix of n/11 with 15
bits will be read by columns instead of reading it by rows.
After the demodulator, the data is read by columns and the
result will be the same matrix of n/11 rows and 15 columns.
The output enters into the comparator where it is compared
with the inputs using XOR function. The average bit error
rate is then calculated and sketched versus Eb/No.
5.2 Plotting the theoretical and simulated bit error rate
The Figure 5.2 shows Rayleigh fading coded and uncoded
system along with the Interleaver.
Figure 5.2 Coded systems in Rayleigh fading with Interleaver
6. CONCLUSION
Compared to the Uncoded and the coded systems, we found
that the Bit Error Rate versus Eb/N0 of the coded system is
better than the uncoded system for the same SNR i.e. by
reducing the SNR to improve the reliability of the system
we get a better result. Whereas in the case of faded and
unfaded for both coded and uncoded system we found that
due to slow fading in the channel the signal undergoes large
distortion. In general, we need SNR to be much smaller
than the needed SNR in the case of slow fading which is
not a practical solution. Thus, there are various methods to
solve the fading problem such as by using OFDM system
and equalization filters.
Department of Electrical and Computer Engineering Page 5
ELEC6141 August 15, 2014
While comparing the Rayleigh fading in the uncoded and
coded system we observe that the performance of the coded
system is worse than Uncoded system since all the bits of
one codeword have the same fading coefficient. In the case
of the deep fading, all the codeword are corrupted while
(15,11) BCH code can correct only 1 bit error in each 15
bits. Thus this code would add even more errors and the
performance gets worse.
Finally, after comparing the entire system with and without
Interleaver we could observe that the difference between
both of them appears because bits in the same codeword
experience independent fading due to the greater separation
in time compared to the channel coherence time.
ACKNOWLEDGEMENT
We take this opportunity to express my profound gratitude
and deep regards to my guide Professor DR. YOUSEF R.
SHAYAN for his exemplary guidance, monitoring and
constant encouragement throughout the course.
The constructive efforts in this project, however, would not
have been possible without the kind of support and help
given by our project tutor Mr. Sepehr Khodadadi. His
cordial support, valuable information and guidance helped
me in completing this task through various stages.
References
[1]http://en.wikipedia.org/wiki/
Quadrature_amplitude_modulation
[2] "Digital Communications Fundamentals and
Applications”, 2nd edition, Bernard Sklar".
[3] “Introduction to Wireless Systems”, Prentice Hall,
2008, Bruce A. Black et al
[4] "Communication Systems 4Th Edition Simon Haykin".
APPENDIX: MATLAB CODE
PART A
clc;clear all; % clear screenNo_of_Bits =19800;% number of bitsrandom_variable_gen = rand(1,No_of_Bits); %generate random values
%Assumption %Eb=1% M=16 .... 16 QAM uncoded ... number of constellation pointsd=sqrt(10)/5; % Es = 10*d*d (Assumption)
%Generating random dataBinary_data= round(random_variable_gen); % rounding the random_variable to 0's and 1'sX_channel_data = Binary_data(1:4:No_of_Bits); %X branch data -- ODD bitsY_channel_data = Binary_data(2:4:No_of_Bits); %Y branch data -- EVEN bitsZ_channel_data = Binary_data(3:4:No_of_Bits); %Z branch data -- ODD bitsW_channel_data = Binary_data(4:4:No_of_Bits); %W branch data -- EVEN bits
I_Mapper_data = d*((2.*Y_channel_data)-1).*(3.*(not(W_channel_data))+W_channel_data); % Mapping the I channel data "0" to "-1" and "1" to "+1"Q_Mapper_data = d*((2.*X_channel_data)-1).*(3.*(not(Z_channel_data))+Z_channel_data); % Mapping the Q channel data "0" to "-1" and "1" to "+1"
%I_Mapper_data = 2*X_channel_data - 1 ; % Mapping the I channel data "0" to "-1" and "1" to "+1"%Q_Mapper__data = 2*Y_channel_data - 1 ; % Mapping the Q channel data "0" to "-1" and "1" to "+1"
Combined_mapped_data= I_Mapper_data+j* Q_Mapper_data; % will have the data in form of either (+/-)1 (+/-)j 1, (+/-)1(+/-)j3, (+/-)3(+/-)j1, (+/-)3(+/-)j3
SNR_simulated = 0:1:10; %simulated signal to noise ratiofor i=1:length(SNR_simulated);No = power(10,-(SNR_simulated(i)/10)); %defining the noise spectral density No
%Generating AWGN noisenoise= randn(1, No_of_Bits/4); I_channel_noise= (sqrt(No/2))* noise; % real part of noise in I channelQ_channel_noise = (sqrt(No/2))* noise; % imaginary part of noise in Q channel
Combined_Noise = I_channel_noise +j* Q_channel_noise;
Department of Electrical and Computer Engineering Page 6
ELEC6141 August 15, 2014
Data_Received = Combined_mapped_data + Combined_Noise; % received signal in Receiver sideData_received_I = real(Data_Received); %I component of received dataData_received_Q = imag(Data_Received); % Q component of received data
%Decoding% sepaprationg of X, Y, Z, W component of received dataX_channel_decoded_data =(sign(Data_received_Q)+1)/2;Y_channel_decoded_data =(sign(Data_received_I)+1)/2;Z_channel_decoded_data =(sign(abs(Data_received_Q)-2*d)-1)/(-2);W_channel_decoded_data =(sign(abs(Data_received_I)-2*d)-1)/(-2);
%Combining X, Y, Z, W data togetherCombined_decoded_data(1:1:No_of_Bits)= 0;Combined_decoded_data(1:4:No_of_Bits)= X_channel_decoded_data ;Combined_decoded_data(2:4:No_of_Bits)= Y_channel_decoded_data ;Combined_decoded_data(3:4:No_of_Bits)= Z_channel_decoded_data ;Combined_decoded_data(4:4:No_of_Bits)= W_channel_decoded_data ;signal_Rx= round(Combined_decoded_data);
%Checking error and measuring number of errorsError_check= xor(Binary_data,signal_Rx);Num_of_Errors(i) = sum(Error_check);endSimulated_BER= Num_of_Errors /No_of_Bits; % simluated value of Bit Error rate
%Theoretical simulation of 16 QAMSNR_theoretical = 0:1:10;for i=1:1:length(SNR_theoretical); Theoretical_BER= (3/8)*erfc(sqrt((2/5)*power(10,SNR_theoretical/10)));end
%==========BIT ERROR RATE FIGURE==========% figure subplot(2,1,1);
semilogy(SNR_simulated,Simulated_BER,'b--*'); title('Simulated Bit Error Rate (BER)for 16 QAM'); xlabel('Eb/No (in dB)'); ylabel('Bit error rate (BER)'); grid on;
subplot(2,1,2);
semilogy(SNR_theoretical,Theoretical_BER,'g--o'); hold on; grid on;
title('Theoretical Bit Error Rate (BER)for 16 QAM'); xlabel('Eb/No (in dB)') ylabel('Bit error rate (BER)'); figure
semilogy(SNR_simulated,Simulated_BER,'b--*'); hold on; grid on;
semilogy(SNR_theoretical,Theoretical_BER,'g--o'); title('Simulation of uncoded 16 QAM'); legend('Simulation','Theoretical'); xlabel('Eb/No (in dB)'); ylabel('Bit error rate (BER)');
PART B
close all;clear all;clc;
%Parametersn=15; %Codeword Bit as nk=7; %Information Bit as kt=2; %Error Correction Bit as t
%Parity Matrix of G_sys (generator matrix) where number of column is n-k P=[ 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1];
Identity_G=diag(ones(1,k)); %Identity matrix of G_sys (Generator matrix)G=[P Identity_G]; % generator matrix
Identity_H=diag(ones(1,n-k)); %Identity matrix of H (Parity check matrix)H=[Identity_H P']; %Parity check matrix
%Preparing the error pattern matrixerror_pat_matrix=diag(ones(1,n));Increment_counter=0;for i=1:n-1 for jj=i+1:n Increment_counter=Increment_counter+1;
error_pat_matrix(n+Increment_counter,:)=error_pat_matrix(i,:)+error_pat_matrix(jj,:); endendb=zeros(1,n);Error_Pattern=[b' error_pat_matrix']';
Syndrome_mat=mod(Error_Pattern*H',2); %S is syndrome
Department of Electrical and Computer Engineering Page 7
ELEC6141 August 15, 2014
Comparison_Table=horzcat(Error_Pattern,Syndrome_mat);
Error_Pattern_Number=121;
%Assumptions%Eb = 1; %Bit energy%M = 16; % 16 QAM Constellation Size%k = log2(M); %Number of bits per symbol%Es = k*Eb ; % Symbol Energy%Es=10*d*d;
d = sqrt(10)/5; % AssumptionNumOfBits =4200;% number of bits to transmitCounter = 0;
for SNRindb=0:1:11; Counter=Counter+1;
Number_Of_Error(Counter)=0; Eb_No(Counter)=SNRindb; Total_Num_Of_Bits=0;
while Number_Of_Error(Counter)<30
Total_Num_Of_Bits=Total_Num_Of_Bits+NumOfBits; %Generation of Data to be transmitted Data_Tx_Gen = round(rand(1,NumOfBits));
%Reorganize the data , make a matrix whose each row has 7 data for num=1:NumOfBits/k
Data_Tx_k(num,:)=Data_Tx_Gen((num-1)*k+1:(num*k)); end
%Data_Tx_Matrix_n=mod(Data_Tx_Matrix_k*G,2); Data_Tx_Matrix_n=mod(Data_Tx_k*G,2);% transfer to new matrix with 15 column
% each row represent data as codewords Binary_Data_Tx=[];
%transfer all rows to single row for num=1:NumOfBits/k
Data_Rearrange=Data_Tx_Matrix_n(num,:); Binary_Data_Tx=[Binary_Data_Tx Data_Rearrange]; end
NumOfBitsCoded=NumOfBits*n/k;
Tx_x = Binary_Data_Tx(1:4:NumOfBitsCoded); %x-component Tx_y = Binary_Data_Tx(2:4:NumOfBitsCoded); %y-component Tx_z = Binary_Data_Tx(3:4:NumOfBitsCoded); %z-component Tx_w = Binary_Data_Tx(4:4:NumOfBitsCoded); %w-component
% I component of modulated signal for 16QAM Data_Tx_Modulated_I = d*((2.*Tx_y)-1).*(3.*(not(Tx_w))+Tx_w); % Q component of modulated signal for 16QAM Data_Tx_Modulated_Q = d*(2.*Tx_x - 1).*(3.*(not(Tx_z))+Tx_z);
% Prepare the Modulated signal to be transmitted Data_Tx_Modulated = Data_Tx_Modulated_I +sqrt(-1)*Data_Tx_Modulated_Q;
%AWGN generation for 16 QAM Sigma2 = (n/k)*0.5*10^(-Eb_No(Counter)/10); %Variance (Sigma squared) of Noise Noise_Real=sqrt(Sigma2)*randn(1,(NumOfBitsCoded/4)); Noise_Imag=sqrt(Sigma2)*randn(1,(NumOfBitsCoded/4));
Noise=Noise_Real+sqrt(-1)*Noise_Imag;
% Addition of white noise to the signal Data_Rx = Data_Tx_Modulated + Noise; % Received signal in Rx side
Data_Rx_Real = real(Data_Rx); % I component of received Data Data_Rx_Imag = imag(Data_Rx); % Q component of received Data
%Seperating x y z & w component of received data as 16 QAM is used for modulation Rx_x = (sign(Data_Rx_Imag) + 1)/2 ; Rx_y = (sign(Data_Rx_Real) + 1)/2; Rx_z =(sign(abs(Data_Rx_Imag) - 2*d) - 1)/(-2); Rx_w = (sign(abs(Data_Rx_Real) - 2*d) - 1)/(-2);
% Arrenging the received Data bit or streem
Esimated_Data_Rx(1:1:NumOfBitsCoded)=0;
Esimated_Data_Rx(1:4:NumOfBitsCoded)=Rx_x;
Department of Electrical and Computer Engineering Page 8
ELEC6141 August 15, 2014
Esimated_Data_Rx(2:4:NumOfBitsCoded)=Rx_y;
Esimated_Data_Rx(3:4:NumOfBitsCoded)=Rx_z;
Esimated_Data_Rx(4:4:NumOfBitsCoded)=Rx_w;
%From the received bit stream taking n number of bit at a time and %find the error sybdrom and find the corresponding syndrom from the %table and find the corrected bit. for num=1:NumOfBits/k r=Esimated_Data_Rx((num-1)*n+1:num*n); Syn_rht=r*H'; Syn_rht=mod(Syn_rht,2);
for m=1:Error_Pattern_Number if Syn_rht==Comparison_Table(m,n+1:n+k+1) % Comparing with syndrom table
r=r+Comparison_Table(m,1:n); r=mod(r,2); rr=r(k+2:n); else rr=r(k+2:n); % if can't match S, which means bit error over 2 end end %Finding the number of error Errors=xor(rr,Data_Tx_k(num,:));
Number_Of_Error(Counter)=sum(Errors)+Number_Of_Error(Counter) ; end end %Calculation of simulated bit error rate Simulated_BER(Counter)= Number_Of_Error(Counter)/Total_Num_Of_Bits % The Bit Error Rate BER
%calculation of theoretical bit error rate EBNO=(k/n)*10^(Eb_No(Counter)/10); Pc=(3/4)*(1/2)*erfc(sqrt((4/10)*EBNO));
Pb=0; for jj=t+1:n Pb(jj)= jj*(factorial(n)/(factorial(jj)*factorial(n-jj)))*(Pc^jj)*(1-Pc)^(n-jj); end Theoretical_BER(Counter) =sum(Pb)/n;end
semilogy(Eb_No,Simulated_BER,'g--*'); % Plot the simulated results.axis([0.01 12 10^(-6) 10^(-0)]);hold on;
semilogy(Eb_No,Theoretical_BER,'b--o'); % Plot the theoretical results.hold on;
xlabel('Eb/No (dB)');ylabel('Bit Error Rate (BER)');title('Theoretical and Simulated Bit Error Rate (BER) for 16 QAM with Coding');legend('Simulated BER(Coded)','Theoretical BER(Coded)');grid on;
PART C
clear all;close all;clc;
%AssumptionsEb = 1; %bit energy%Es = 4; %symbol energyd = (sqrt(10))/5; % Assumption
%Given%Rb=2*(10^6);% Information rate 2Mb/s;%Fc=12*(10^9); % Carrier frequency 12GHz%V=(42.3*(10^3))/3600; %Speed 42.3Km/Hour%Tc=380.95*(10^(-6));% Coherence time of the channel%Ts=2*(10^(-6)); %Symbol rateTc_by_Ts=191; %Number of symbol in one block of slow fading
Num_Of_Bits=4*191*7; %nummber of input bits
Counter=0;
for SNR=0:3:18;
Total_No_Of_Bits=0; Counter=Counter+1; % Used as Index or Counter Eb_No(Counter)=SNR; Total_Error=0;
while Total_Error<1000
Total_No_Of_Bits=Total_No_Of_Bits+Num_Of_Bits;
%Generation of Data to be transmitted Data_Tx=round(rand(1,Num_Of_Bits));
% Seperating x y z & w component of data for 16 QAM Modulation
Department of Electrical and Computer Engineering Page 9
ELEC6141 August 15, 2014
x_channel_data = Data_Tx(1:4:Num_Of_Bits); y_channel_data = Data_Tx(2:4:Num_Of_Bits); z_channel_data = Data_Tx(3:4:Num_Of_Bits); w_channel_data = Data_Tx(4:4:Num_Of_Bits);
% I component of modulated signal for 16QAM Data_Tx_I_channel = d*(((2.*y_channel_data) - 1).*(3.*(not(w_channel_data))+w_channel_data)); % Q component of modulated signal for 16QAM Data_Tx_Q_channel = d*(((2.*x_channel_data) - 1).*(3.*(not(z_channel_data))+z_channel_data)); % Prepare the Modulated signal to be transmitted Combined_Data_Tx = Data_Tx_I_channel + j*Data_Tx_Q_channel; %this will make the sent signal as complet number
%AWGN generation for 16 QAM AWGN_noise = 0.5*10^(-(Eb_No(Counter))/10); %Variance of AWGN Noise
Noise_Real_component=sqrt(AWGN_noise)*randn(1,(Num_Of_Bits/4));
Noise_Imag_component=sqrt(AWGN_noise)*randn(1,(Num_Of_Bits/4));
Combined_Noise=Noise_Real_component+Noise_Imag_component*sqrt(-1);
%Rayleigh fadding generation for 16 QAM
Rayleigh_Real_component=sqrt(1/2)*randn(1,Num_Of_Bits/Tc_by_Ts);
Rayleigh_Imag_component=sqrt(1/2)*randn(1,Num_Of_Bits/Tc_by_Ts); Rayleigh_combined =Rayleigh_Real_component+j*Rayleigh_Imag_component;
% Addition of Rayleigh fadding effect Signal_Rayleigh_Faded= [];
for i= 1:Num_Of_Bits/(4*Tc_by_Ts) BlockOfSignal_RayleighFaded = Rayleigh_combined(i)*Combined_Data_Tx(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts)); Signal_Rayleigh_Faded = [Signal_Rayleigh_Faded,BlockOfSignal_RayleighFaded];
end
% Addition of white noise to the signal Data_Rx_Rayleigh_AWGN = Signal_Rayleigh_Faded + Combined_Noise;
%Removing Rayleigh fading effect Data_Rx = []; for i = 1:Num_Of_Bits/(4*Tc_by_Ts) Block_Data_Rx = Data_Rx_Rayleigh_AWGN(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts))/Rayleigh_combined(i); Data_Rx = [Data_Rx,Block_Data_Rx]; end
Data_Rx_Real_component= real(Data_Rx); %I part of the recived signal Data_Rx_Imag_component= imag(Data_Rx); %Q part of the recived signal
%Seperating x y z & w component of received data Rx_x_channel_data = (sign(Data_Rx_Imag_component) + 1)/2 ; Rx_y_channel_data = (sign(Data_Rx_Real_component) + 1)/2; Rx_z_channel_data =(sign(abs(Data_Rx_Imag_component) - 2*d) - 1)/(-2); Rx_w_channel_data = (sign(abs(Data_Rx_Real_component) - 2*d) - 1)/(-2);
% Arrenging the received Data bit or streem Esimated_Data_Rx(1:1:Num_Of_Bits)=0;
Esimated_Data_Rx(1:4:Num_Of_Bits)=Rx_x_channel_data;
Esimated_Data_Rx(2:4:Num_Of_Bits)=Rx_y_channel_data;
Esimated_Data_Rx(3:4:Num_Of_Bits)=Rx_z_channel_data;
Esimated_Data_Rx(4:4:Num_Of_Bits)=Rx_w_channel_data;
%Comparing the Tx and Rx Data Error=xor(Esimated_Data_Rx,Data_Tx); %this will find the errors Total_Error=Total_Error+sum(Error);
end %Calculation of Simulated BER
Simulated_BER(Counter)=Total_Error/Total_No_Of_Bits %this will calculate the probilty of bit errors rate
Department of Electrical and Computer Engineering Page 10
ELEC6141 August 15, 2014
%Calculation of theoretical BER EBNO(Counter)=10.^(Eb_No(Counter)/10);
Theoretical_BER(Counter)=(3/4)*(1/2)*erfc(sqrt(4/5*EBNO(Counter))/(2^0.5));end
semilogy(Eb_No,Simulated_BER,'b--*')axis([0.01 18 10^(-14) 10^(-0)]);hold on
semilogy(Eb_No,Theoretical_BER,'g--o');hold on
xlabel('Eb/No (dB)');ylabel('Bit Error Rate (BER)');title('Rayleigh fading Channel for 16 QAM Without Coding');legend('BER for Rayleigh fading channel(Simulated)','BER for AWGN Channel(Theoretical)','Location','SouthEast');grid on;
PART D
clear all;close all;clc;%Parametersn=15; %Codeword Bit as nk=7; %Information Bit as kt=2; %Error Correction Bit as t
%Parity Matrix of G_sys (generator matrix) where number of column is n-k P =[ 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1];
%Identity matrix of G_sys (Generator matrix)Identity_G=diag(ones(1,k));G=[P Identity_G];
%Identity matrix of H (Parity check matrix)Identity_H=diag(ones(1,n-k));
%Parity check matrixH=[Identity_H P'];
%Preparing the error pattern matrixerror_pattern_mat=diag(ones(1,n));Increment_counter=0;for i=1:n-1 for jj=i+1:n
Increment_counter=Increment_counter+1;
error_pattern_mat(n+Increment_counter,:)=error_pattern_mat(i,:)+error_pattern_mat(jj,:); endendb=zeros(1,n);Error_Pattern=[b' error_pattern_mat']';
S=mod(Error_Pattern*H',2); %S is syndrome
Comparison_Table=horzcat(Error_Pattern,S);
Error_Pattern_Number=121;
Eb = 1; % We Assume that the energy per bit is 1Es = 4 ; % Energy per symbol%M = 16; %Constellation Size - 16-QAM%k = log2(M); %Number of bits per symbol
%Given%Rb=2*(10^6);% Information rate 2Mb/s;%Fc=12*(10^9); % Carrier frequency 12GHz%V=(42.3*(10^3))/3600; %Speed 42.3Km/Hour%Tc=380.95*(10^(-6));% Coherence time of the channel%Ts=2*(10^(-6)); %Symbol rateTc_by_Ts=191; %Number of symbol in one block of slow fading
d = sqrt(10)/5;Num_Of_Bits=4*191*7;%nummber of input bits
Counter=0;
for SNR=0:3:18; Total_No_OfBits=0; Counter=Counter+1; % Used as Index or Counter EbNo(Counter)=SNR; Total_Error=0; Number_of_Error_Coded=0; while Total_Error<1000
Total_No_OfBits=Total_No_OfBits+Num_Of_Bits; Binary_Data_Tx = round(rand(1,Num_Of_Bits));%%%%%%%%%%%%%%%%%%%%%%%%%%%Coded Start%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for num=1:Num_Of_Bits/k %transfer to matrix, each row has 7 data
Data_Tx_Matrix_k(num,:)=Binary_Data_Tx((num-1)*k+1:(num*k)); end
Data_Tx_Matrix_n=mod(Data_Tx_Matrix_k*G,2);% transfer to new matrix with 15 data each row with coding
Data_Tx_Coded=[];
Department of Electrical and Computer Engineering Page 11
ELEC6141 August 15, 2014
for num=1:Num_Of_Bits/k %transfer to a row
Data_Input=Data_Tx_Matrix_n(num,:); Data_Tx_Coded=[Data_Tx_Coded Data_Input]; end
Num_OfBits_Coded=Num_Of_Bits*n/k; x_channel_Coded_data = Data_Tx_Coded(1:4:Num_OfBits_Coded); %x-component y_channel_Coded_data = Data_Tx_Coded(2:4:Num_OfBits_Coded); %y-component z_channel_Coded_data = Data_Tx_Coded(3:4:Num_OfBits_Coded); %z-component w_channel_Coded_data = Data_Tx_Coded(4:4:Num_OfBits_Coded); %w-component
% I component of modulated signal Data_Tx_I_channel_Coded = d*(((2.*y_channel_Coded_data) - 1).*(3.*(not(w_channel_Coded_data))+w_channel_Coded_data)); % Q component of modulated signal y Data_Tx_Q_channel_Coded = d*((2.*x_channel_Coded_data - 1).*(3.*(not(z_channel_Coded_data))+z_channel_Coded_data));
% Addition of white noise Data_Tx_Modulated_Coded = Data_Tx_I_channel_Coded + j*Data_Tx_Q_channel_Coded;
Noise_Coded = (n/k)*0.5*10^(-EbNo(Counter)/10); %Variance (Sigma squared) of Noise
Noise_Real_Coded=sqrt(Noise_Coded)*randn(1,(Num_OfBits_Coded/4)); %I
Noise_Imag_Coded=sqrt(Noise_Coded)*randn(1,(Num_OfBits_Coded/4)); %Q
combined_Noise_Coded=Noise_Real_Coded+j*Noise_Imag_Coded;
Signal_Rayleigh_Faded_Coded=[];
Number_Fading_Coeff=Num_OfBits_Coded/(4*Tc_by_Ts);
Rayleigh_Coded=sqrt(1/2)*randn(1,Number_Fading_Coeff)+j*sqrt(1/2)*randn(1,Number_Fading_Coeff);
for num=1:Num_OfBits_Coded/(4*Tc_by_Ts)
Faded_Signal=Rayleigh_Coded(num)*Data_Tx_Modulated_Coded(((num-1)*Tc_by_Ts)+1:(num*Tc_by_Ts));
Signal_Rayleigh_Faded_Coded=[Signal_Rayleigh_Faded_Coded Faded_Signal]; end
Data_Rx_Rayleigh_AWGN_Coded = Signal_Rayleigh_Faded_Coded+combined_Noise_Coded;
Data_Rx_Coded=[];
for q=1:Num_OfBits_Coded/(4*Tc_by_Ts)
Remainder_Rayleigh=Data_Rx_Rayleigh_AWGN_Coded((((q-1)*Tc_by_Ts)+1:(q*Tc_by_Ts)))/Rayleigh_Coded(q); Data_Rx_Coded=[Data_Rx_Coded Remainder_Rayleigh]; end
%Demodulation & Error Detection
Data_Rx_Coded_I_component = real(Data_Rx_Coded); % I component Data_Rx_Coded_Q_component = imag(Data_Rx_Coded); % Q component
Rx_x_channel_Coded_data= (sign(Data_Rx_Coded_Q_component) + 1)/2 ; Rx_y_channel_Coded_data = (sign(Data_Rx_Coded_I_component) + 1)/2 ; Rx_z_channel_Coded_data =(sign(abs(Data_Rx_Coded_Q_component) - 2*d) - 1)/(-2); Rx_w_channel_Coded_data = (sign(abs(Data_Rx_Coded_I_component) - 2*d) - 1)/(-2);
Estimated_Data_in_Coded(1:4:Num_OfBits_Coded)=Rx_x_channel_Coded_data; Estimated_Data_in_Coded(2:4:Num_OfBits_Coded)=Rx_y_channel_Coded_data;
Estimated_Data_in_Coded(3:4:Num_OfBits_Coded)=Rx_z_channel_Coded_data;
Estimated_Data_in_Coded(4:4:Num_OfBits_Coded)=Rx_w_channel_Coded_data;
for numm=1:Num_Of_Bits/k r=Estimated_Data_in_Coded((numm-1)*n+1:numm*n); rh_transpose=r*H'; rh_transpose=mod(rh_transpose,2); for m=1:Error_Pattern_Number
Department of Electrical and Computer Engineering Page 12
ELEC6141 August 15, 2014
if rh_transpose==Comparison_Table(m,16:23)
r=r+Comparison_Table(m,1:15); r=mod(r,2); rr=r(9:15); else rr=r(9:15); % if can't match S, which means bit error over 2 end end
error=xor(rr,Data_Tx_Matrix_k(numm,:));
Number_of_Error_Coded=Number_of_Error_Coded+sum(error); end%%%%%%%%%%%%%%%%%%%%%%%%%Coded End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%Uncoded start%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Seperating x y z & w component of data for 16 QAM Modulation x_uncoded_data = Binary_Data_Tx(1:4:Num_Of_Bits); y_uncoded_data = Binary_Data_Tx(2:4:Num_Of_Bits); z_uncoded_data = Binary_Data_Tx(3:4:Num_Of_Bits); w_uncoded_data = Binary_Data_Tx(4:4:Num_Of_Bits);
% I component of modulated signal for 16QAM Data_Tx_Modulated_I_channel_uncoded = d*(((2.*y_uncoded_data) - 1).*(3.*(not(w_uncoded_data))+w_uncoded_data)); % Q component of modulated signal for 16QAM Data_Tx_Modulated_Q_channel_uncoded = d*(((2.*x_uncoded_data) - 1).*(3.*(not(z_uncoded_data))+z_uncoded_data)); % Prepare the Modulated signal to be transmitted Data_Tx_Modulated = Data_Tx_Modulated_I_channel_uncoded + j*Data_Tx_Modulated_Q_channel_uncoded; %this will make the sent signal as complet number
%AWGN generation for 16 QAM Noise2_AW = 0.5*10^(-(EbNo(Counter))/10); %Variance of AWGN Noise
Noise_Real=sqrt(Noise2_AW)*randn(1,(Num_Of_Bits/4)); Noise_Imag=sqrt(Noise2_AW)*randn(1,(Num_Of_Bits/4)); Noise=Noise_Real+Noise_Imag*sqrt(-1);
%Rayleigh fadding generation for 16 QAM
Rayleigh_Real=sqrt(1/2)*randn(1,Num_Of_Bits/Tc_by_Ts);
Rayleigh_Imag=sqrt(1/2)*randn(1,Num_Of_Bits/Tc_by_Ts); Rayleigh =Rayleigh_Real+j*Rayleigh_Imag;
% Addition of Rayleigh fadding effect Signal_RayleighFaded = [ ];
for i = 1:Num_Of_Bits/(4*Tc_by_Ts) BlockOfSignal_RayleighFaded = Rayleigh(i)*Data_Tx_Modulated(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts)); Signal_RayleighFaded = [Signal_RayleighFaded,BlockOfSignal_RayleighFaded]; end
% Addition of white noise to the signal Data_Rx_Rayleigh_AWGN = Signal_RayleighFaded + Noise;
%Removing Rayleigh fading effect Data_Rx = []; for i = 1:Num_Of_Bits/(4*Tc_by_Ts) BlockOfData_Rx = Data_Rx_Rayleigh_AWGN(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts))/Rayleigh(i); Data_Rx = [Data_Rx,BlockOfData_Rx]; end
Data_Rx_Real= real(Data_Rx); %I part of the recived signal Data_Rx_Imag= imag(Data_Rx); %Q part of the recived signal
%Seperating x y z & w component of received data Rx_x = (sign(Data_Rx_Imag) + 1)/2 ; Rx_y = (sign(Data_Rx_Real) + 1)/2; Rx_z =(sign(abs(Data_Rx_Imag) - 2*d) - 1)/(-2); Rx_w = (sign(abs(Data_Rx_Real) - 2*d) - 1)/(-2);
% Arrenging the received Data bit or streem Esimated_Data_Rx(1:1:Num_Of_Bits)=0;
Esimated_Data_Rx(1:4:Num_Of_Bits)=Rx_x;
Esimated_Data_Rx(2:4:Num_Of_Bits)=Rx_y;
Esimated_Data_Rx(3:4:Num_Of_Bits)=Rx_z;
Esimated_Data_Rx(4:4:Num_Of_Bits)=Rx_w;
Department of Electrical and Computer Engineering Page 13
ELEC6141 August 15, 2014
%Comparing the Tx and Rx Data
Error=xor(Esimated_Data_Rx,Binary_Data_Tx); %this will find the errors Total_Error=Total_Error+sum(Error);
%%%%%%%%%%%%%%%%%%%%%%%%%Uncoded End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end BER_Coded(Counter)= Number_of_Error_Coded/Total_No_OfBits
BER_Uncoded(Counter)=Total_Error/Total_No_OfBitsend;
semilogy(EbNo,BER_Coded,'b--*'); % Plot the results.axis([0.01 18 10^(-4) 10^(-0)]);hold on;
semilogy(EbNo,BER_Uncoded,'g--o'); % Plot the results.hold on;
xlabel('Eb/No (dB)');ylabel('Bit Error Rate (BER)');title('Coded information of Rayleigh fading Channel for 16 QAM Modulation scheme');legend('Rayleigh Fading Coded System','Rayleigh Fading Uncoded System','Location','SouthEast');grid on;
PART E
clear all;close all;clc;%Parameters
n=15;%Codeword Bit as nk=7; %Information Bit as kt=2; %Error Correction Bit as t
%Parity Matrix of G_sys (generator matrix) where number of column is n-k P=[ 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 0
0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 1];
%Identity matrix of G_sys (Generator matrix)Identity_G= diag(ones(1,k));G=[P Identity_G];
%Identity matrix of H (Parity check matrix)Identity_H=diag(ones(1,n-k));
%Parity check matrixH=[Identity_H P'];
%Preparing the error pattern matrixa=diag(ones(1,n));Increment_counter=0;for i=1:n-1 for jj=i+1:n Increment_counter=Increment_counter+1; a(n+Increment_counter,:)=a(i,:)+a(jj,:); endendb=zeros(1,n);ErrorPattern=[b' a']';
Syndrome_mat=mod(ErrorPattern*H',2); %S is syndrome
Comparison_Table=horzcat(ErrorPattern,Syndrome_mat);Error_Pattern_Number=121;
Eb = 1; % We Assume that the energy per bit is 1%Es = 4 ; % Energy per symbol%M = 16; %Constellation Size - 16-QAM%k = log2(M); %Number of bits per symbol
%Given%Rb=2*(10^6);% Information rate 2Mb/s;%Fc=12*(10^9); % Carrier frequency 12GHz%V=(42.3*(10^3))/3600; %Speed 42.3Km/Hour%Tc=380.95*(10^(-6));% Coherence time of the channel%Ts=2*(10^(-6)); %Symbol rateTc_by_Ts=191; %Number of symbol in one block of slow fading
d = sqrt(10)/5;d_Row=1528;%8*Tc_by_Ts;NumOfBits=d_Row*7; %nummber of input bits
Counter=0;
for SNR=0:3:18;
Total_No_OfBits=0; Counter=Counter+1; % Used as Index or Counter EbNo(Counter)=SNR;
Department of Electrical and Computer Engineering Page 14
ELEC6141 August 15, 2014
TotalError(Counter)=0; Number_Error_Coded(Counter)=0; Number_Error_Inter(Counter)=0; while TotalError(Counter)<1000
Total_No_OfBits=Total_No_OfBits+NumOfBits;
Data_Tx = round(rand(1,NumOfBits));%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Coded Start%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for num=1:NumOfBits/k %transfer to matrix, each row has 7 data
Data_Tx_Matrix_k(num,:)=Data_Tx((num-1)*k+1:(num*k)); end
Data_Tx_Matrix_n=mod(Data_Tx_Matrix_k*G,2);% transfer to new matrix with 15 data each row with coding
Data_Tx_Coded=[];
for num=1:NumOfBits/k %transfer to a row
Data_Input=Data_Tx_Matrix_n(num,:); Data_Tx_Coded=[Data_Tx_Coded Data_Input]; end
NumOfBitsCoded=NumOfBits*n/k; x_channel_data_Coded = Data_Tx_Coded(1:4:NumOfBitsCoded); %x-component y_channel_data_Coded = Data_Tx_Coded(2:4:NumOfBitsCoded); %y-component z_channel_data_Coded = Data_Tx_Coded(3:4:NumOfBitsCoded); %z-component w_channel_data_Coded = Data_Tx_Coded(4:4:NumOfBitsCoded); %w-component
% I component of modulated signal Data_Tx_I_Coded = d*(((2.*y_channel_data_Coded) - 1).*(3.*(not(w_channel_data_Coded))+w_channel_data_Coded)); % Q component of modulated signal y Data_Tx_Q_Coded = d*((2.*x_channel_data_Coded - 1).*(3.*(not(z_channel_data_Coded))+z_channel_data_Coded));
% Addition of white noise Data_Tx_Modulated_Coded = Data_Tx_I_Coded + j*Data_Tx_Q_Coded;
Noise2_Coded = (n/k)*0.5*10^(-EbNo(Counter)/10); %Variance (Sigma squared) of Noise
Noise_Real_Coded=sqrt(Noise2_Coded)*randn(1,(NumOfBitsCoded/4)); %I
Noise_Imag_Coded=sqrt(Noise2_Coded)*randn(1,(NumOfBitsCoded/4)); %Q
Noise_Coded=Noise_Real_Coded+j*Noise_Imag_Coded;
Signal_Rayleigh_Faded_Coded=[];
Number_of_Fading_Coeff=NumOfBitsCoded/(4*Tc_by_Ts);
Rayleigh_Coded=sqrt(1/2)*randn(1,Number_of_Fading_Coeff)+j*sqrt(1/2)*randn(1,Number_of_Fading_Coeff);
for num=1:NumOfBitsCoded/(4*Tc_by_Ts)
FadingSignal=Rayleigh_Coded(num)*Data_Tx_Modulated_Coded(((num-1)*Tc_by_Ts)+1:(num*Tc_by_Ts));
Signal_Rayleigh_Faded_Coded=[Signal_Rayleigh_Faded_Coded FadingSignal]; end
Data_Rx_Rayleigh_AWGN_Coded = Signal_Rayleigh_Faded_Coded+Noise_Coded;
Data_Rx_Coded=[];
for q=1:NumOfBitsCoded/(4*Tc_by_Ts)
RemRayleigh=Data_Rx_Rayleigh_AWGN_Coded((((q-1)*Tc_by_Ts)+1:(q*Tc_by_Ts)))/Rayleigh_Coded(q); Data_Rx_Coded=[Data_Rx_Coded RemRayleigh]; end
%Demodulation & Error Detection
Data_Rx_Coded_Real = real(Data_Rx_Coded); % I component Data_Rx_Coded_Imag = imag(Data_Rx_Coded); % Q component
Rx_x_channel_data_Coded = (sign(Data_Rx_Coded_Imag) + 1)/2 ; Rx_y_channel_data_Coded = (sign(Data_Rx_Coded_Real) + 1)/2 ;
Department of Electrical and Computer Engineering Page 15
ELEC6141 August 15, 2014
Rx_z_channel_data_Coded =(sign(abs(Data_Rx_Coded_Imag) - 2*d) - 1)/(-2); Rx_w_channel_data_Coded = (sign(abs(Data_Rx_Coded_Real) - 2*d) - 1)/(-2);
Estimated_Data_in_Coded(1:4:NumOfBitsCoded)=Rx_x_channel_data_Coded;
Estimated_Data_in_Coded(2:4:NumOfBitsCoded)=Rx_y_channel_data_Coded;
Estimated_Data_in_Coded(3:4:NumOfBitsCoded)=Rx_z_channel_data_Coded;
Estimated_Data_in_Coded(4:4:NumOfBitsCoded)=Rx_w_channel_data_Coded;
for numm=1:NumOfBits/k r=Estimated_Data_in_Coded((numm-1)*n+1:numm*n); rht=r*H'; rht=mod(rht,2); for m=1:Error_Pattern_Number if rht==Comparison_Table(m,16:23)
r=r+Comparison_Table(m,1:15); r=mod(r,2); rr=r(9:15); else rr=r(9:15); % if can't match S, which means bit error over 2 end end
error_check=xor(rr,Data_Tx_Matrix_k(numm,:));
Number_Error_Coded(Counter)=Number_Error_Coded(Counter)+sum(error_check); end%%%%%%%%%%%%%%%%%%%%%%%%%%%%Coded End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%Coded with Interleaving Start%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data_in_inter=[]; for num=1:n for jj=1:d_Row
data_input=Data_Tx_Matrix_n(jj ,num); data_in_inter=[data_in_inter data_input]; end end
x_interleaver = data_in_inter(1:4:NumOfBitsCoded); %x-component
y_interleaver = data_in_inter(2:4:NumOfBitsCoded); %y-component z_interleaver = data_in_inter(3:4:NumOfBitsCoded); %z-component w_interleaver = data_in_inter(4:4:NumOfBitsCoded); %w-component
% I component of modulated signal data_modulated_I_interleaver = d*(((2.*y_interleaver) - 1).*(3.*(not(w_interleaver))+w_interleaver)); % Q component of modulated signal y data_modulated_Q_interleaver = d*((2.*x_interleaver - 1).*(3.*(not(z_interleaver))+z_interleaver));
% Addition of white noise data_in_modulated_interleaver = data_modulated_I_interleaver + j*data_modulated_Q_interleaver;
rrr=[];
for tk=1:NumOfBitsCoded/(4*Tc_by_Ts)
fadsignal=Rayleigh_Coded(tk)*data_in_modulated_interleaver(((tk-1)*Tc_by_Ts)+1:(tk*Tc_by_Ts)); rrr=[rrr,fadsignal]; end
data_out1 = rrr+Noise_Coded; sss=[];
for q=1:NumOfBitsCoded/(4*Tc_by_Ts) divh=data_out1((((q-1)*Tc_by_Ts)+1:(q*Tc_by_Ts)))/Rayleigh_Coded(q); sss=[sss,divh]; end data_out=sss;
% data_out_real_I_component = real(data_out); % I component data_out_imag_Q_component = imag(data_out); % Q component
Rx_x_channel_data_inter = (sign(data_out_imag_Q_component) + 1)/2 ; Rx_y_channel_data_inter = (sign(data_out_real_I_component) + 1)/2 ; Rx_z_channel_data_inter =(sign(abs(data_out_imag_Q_component) - 2*d) - 1)/(-2); Rx_w_channel_data_inter = (sign(abs(data_out_real_I_component) - 2*d) - 1)/(-2);
Department of Electrical and Computer Engineering Page 16
ELEC6141 August 15, 2014
Estimated_data_in_inter(1:4:NumOfBitsCoded)=Rx_x_channel_data_inter;
Estimated_data_in_inter(2:4:NumOfBitsCoded)=Rx_y_channel_data_inter;
Estimated_data_in_inter(3:4:NumOfBitsCoded)=Rx_z_channel_data_inter;
Estimated_data_in_inter(4:4:NumOfBitsCoded)=Rx_w_channel_data_inter;
data_rx_inter=[]; for i=1:d_Row
data_rx_inter(i,:)=Estimated_data_in_inter(i:d_Row:d_Row*15); end% data_rx_inter; Estimated_data_in_inter=[]; for jj=1:d_Row data_input=data_rx_inter(jj ,:);
Estimated_data_in_inter=[Estimated_data_in_inter data_input]; end
for numm=1:NumOfBits/7 r=Estimated_data_in_inter((numm-1)*15+1:numm*15); rht=r*H'; rht=mod(rht,2); for m=1:Error_Pattern_Number if rht==Comparison_Table(m,16:23)
r=r+Comparison_Table(m,1:15); r=mod(r,2); rr=r(9:15); else rr=r(9:15); % if can't match S, which means bit error over 2 end end
error_check=xor(rr,Data_Tx_Matrix_k(numm,:));
Number_Error_Inter(Counter)=Number_Error_Inter(Counter)+sum(error_check); end %%%%%%%%%%%%%%%%%%%%%%%Coded with Interleaving End%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%Uncoded start%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Seperating x y z & w component of data for 16 QAM Modulation x = Data_Tx(1:4:NumOfBits); y = Data_Tx(2:4:NumOfBits); z = Data_Tx(3:4:NumOfBits); w = Data_Tx(4:4:NumOfBits);
% I component of modulated signal for 16QAM Data_Tx_Modulated_I = d*(((2.*y) - 1).*(3.*(not(w))+w)); % Q component of modulated signal for 16QAM Data_Tx_Modulated_Q = d*(((2.*x) - 1).*(3.*(not(z))+z)); % Prepare the Modulated signal to be transmitted Data_Tx_Modulated = Data_Tx_Modulated_I + j*Data_Tx_Modulated_Q; %this will make the sent signal as complet number
%AWGN generation for 16 QAM Noise2_uncoded = 0.5*10^(-(EbNo(Counter))/10); %Variance of AWGN Noise
Noise_Real_I=sqrt(Noise2_uncoded)*randn(1,(NumOfBits/4));
Noise_Imag_Q=sqrt(Noise2_uncoded)*randn(1,(NumOfBits/4));
Combined_Noise=Noise_Real_I+Noise_Imag_Q*sqrt(-1);
%Rayleigh fadding generation for 16 QAM Rayleigh_Real_I= sqrt(1/2)*randn(1,NumOfBits/Tc_by_Ts); Rayleigh_Imag_Q= sqrt(1/2)*randn(1,NumOfBits/Tc_by_Ts); Rayleigh= Rayleigh_Real_I + j*Rayleigh_Imag_Q;
% Addition of Rayleigh fadding effect Signal_Rayleigh_Faded = [ ];
for i = 1:NumOfBits/(4*Tc_by_Ts) BlockOfSignal_RayleighFaded = Rayleigh(i)*Data_Tx_Modulated(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts)); Signal_Rayleigh_Faded = [Signal_Rayleigh_Faded,BlockOfSignal_RayleighFaded]; end
% Addition of white noise to the signal Data_Rx_Rayleigh_AWGN = Signal_Rayleigh_Faded + Combined_Noise;
%Removing Rayleigh fading effect Data_Rx = []; for i = 1:NumOfBits/(4*Tc_by_Ts) BlockOfData_Rx = Data_Rx_Rayleigh_AWGN(((i-1)*Tc_by_Ts)+1:(i*Tc_by_Ts))/Rayleigh(i);
Department of Electrical and Computer Engineering Page 17
ELEC6141 August 15, 2014
Data_Rx = [Data_Rx,BlockOfData_Rx]; end
Data_Rx_Real= real(Data_Rx); %I part of the recived signal Data_Rx_Imag= imag(Data_Rx); %Q part of the recived signal
%Seperating x y z & w component of received data Rx_x = (sign(Data_Rx_Imag) + 1)/2 ; Rx_y = (sign(Data_Rx_Real) + 1)/2; Rx_z =(sign(abs(Data_Rx_Imag) - 2*d) - 1)/(-2); Rx_w = (sign(abs(Data_Rx_Real) - 2*d) - 1)/(-2);
% Arrenging the received Data bit or streem Esimated_Data_Rx(1:1:NumOfBits)=0; Esimated_Data_Rx(1:4:NumOfBits)=Rx_x; Esimated_Data_Rx(2:4:NumOfBits)=Rx_y; Esimated_Data_Rx(3:4:NumOfBits)=Rx_z; Esimated_Data_Rx(4:4:NumOfBits)=Rx_w;
%Comparing the Tx and Rx Data Error=xor(Esimated_Data_Rx,Data_Tx); %this will find the errors
TotalError(Counter)=TotalError(Counter)+sum(Error);
%%%%%%%%%%%%%%%%%%%%%%%%%%Uncoded End%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end BER_Coded(Counter)= Number_Error_Coded(Counter)/Total_No_OfBits BER_Inter(Counter)= Number_Error_Inter(Counter)/Total_No_OfBits
BER_Uncoded(Counter)=TotalError(Counter)/Total_No_OfBits
end;
semilogy(EbNo,BER_Coded,'b--*'); % Plot the results.axis([0.01 18 10^(-4) 10^(-0)]);hold on;
semilogy(EbNo,BER_Inter,'g--o'); % Plot the results.hold on;
semilogy(EbNo,BER_Uncoded,'r--*'); % Plot the results.hold on;
xlabel('Eb/No (dB)');ylabel('Bit Error Rate (BER)');
title('Coded System in Rayleigh fading Channel with Interleaver');legend('Rayleigh Fading Coded System','Rayleigh Fading Coded System with Interleaver','Rayleigh Fading Uncoded System','Location','SouthEast');grid on;
Department of Electrical and Computer Engineering Page 18