SIgnal Space Diversity with Alamouti transmit diversity

Status
Not open for further replies.

Msahisto

Newbie level 1
Joined
May 6, 2019
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
Good day everyone I have a problem in using the CRC code to check for errors on my code here it's my code running I just wanna retransmit if i get errors so that's why im using the CRC........can anyone kindly assist me your help will be highly appreciated please find the attached Code below

Code:
%%#########################################################################
% Author Muzi Lubisi
% Signal Space Diversity with Alamouti Transmit Diversity  
% Nr = 4
% Nt = 2;
% Number of Symbols (four)
%##########################################################################
%%

% clear
% close all

M = 16; %size of the signal constellation
k = log2(M);  %number of bits per symbol
%nbits = k*4; % total number of bits 
dec_symbols = [0:15];
Theta = 31.7;  %Rotation Angle
alpha = Theta*pi/180; % rotation angle in radians
averg = sum(abs(qammod([0:M-1],M,0,'gray')).^2)/M;

Mapper = (modulate(modem.qammod('M',16,'SymbolOrder','Gray'),dec_symbols))/sqrt(averg);

%___Rotate the constelation and find the real and imaginary part
Map_real_R = real(Mapper)*cos(alpha) - imag(Mapper)*sin(alpha);
Map_imag_R = real(Mapper)*sin(alpha) + imag(Mapper)*cos(alpha);




%%
SNR_db = 0:2:16;
SNR_dec = 10.^(SNR_db/10);

Num_error = zeros(1,length(SNR_db));
frame_counter = zeros(1,length(SNR_db));
arg = zeros(length(Mapper),1);
No_of_symbls =4;
Nr = 4;
L = 100; %No of bits to be considered

LUT=[0 0 0 0;0 0 0 1;0 0 1 0;0 0 1 1;0 1 0 0;0 1 0 1;0 1 1 0;0 1 1 1;1 0 0 0;1 0 0 1;
     1 0 1 0;1 0 1 1;1 1 0 0;1 1 0 1;1 1 1 0;1 1 1 1];

errorLimit = 3*[1800 1500 1300 1000 900 500 300 200 100 100 100 100 100 100];

%%

for ii=1:length(SNR_db)
     while (Num_error(ii)<errorLimit(ii))
            frame_counter(ii) = frame_counter(ii) + 16; %bits considered per cycle
            
            %Generate random bits_
             b_ip = randi([0,1],1,k*No_of_symbls*L);
             
             for k_m = 1:L
            
                 %Generate four pointers_
                 Pointer_1 = 8*b_ip((k_m)*16-15) + 4*b_ip((k_m)*16-14) + 2*b_ip((k_m)*16-13) + b_ip((k_m)*16-12) + 1;
                 Pointer_2 = 8*b_ip((k_m)*16-11) + 4*b_ip((k_m)*16-10) + 2*b_ip((k_m)*16-9) + b_ip((k_m)*16-8) + 1;
                 Pointer_3 = 8*b_ip((k_m)*16-7) + 4*b_ip((k_m)*16-6) + 2*b_ip((k_m)*16-5) + b_ip((k_m)*16-4) + 1;
                 Pointer_4 = 8*b_ip((k_m)*16-3) + 4*b_ip((k_m)*16-2) + 2*b_ip((k_m)*16-1) + b_ip((k_m)*16-0) + 1;
            
                 %Generate four symbols_
                 X_1 = Mapper(Pointer_1);
                 X_2 = Mapper(Pointer_2);
                 X_3 = Mapper(Pointer_3);
                 X_4 = Mapper(Pointer_4);
            
                 %spliting the four symbols into real and imaginary_
                 X1_real = real(X_1);
                 X1_imag = imag(X_1);
            
                 X2_real = real(X_2);
                 X2_imag = imag(X_2);
            
                 X3_real = real(X_3);
                 X3_imag = imag(X_3);
            
                 X4_real = real(X_4);
                 X4_imag = imag(X_4);
            
                 %Rotation matrix_
                 R = [cosd(Theta) sind(Theta);-sind(Theta) cosd(Theta)];
            
                 U1 = [X1_real X1_imag ]*R;
                 U2 = [X2_real X2_imag ]*R;
                 U3 = [X3_real X3_imag ]*R;
                 U4 = [X4_real X4_imag ]*R;
             
                 %Rotation of the symbol pairs_
                 U1_rotated = U1(1) + 1i*U1(2);
                 U2_rotated = U2(1) + 1i*U2(2);
                 U3_rotated = U3(1) + 1i*U3(2);
                 U4_rotated = U4(1) + 1i*U4(2);
             
                 %interleave the four symbol pairs_
                 S1 = real(U1_rotated) + 1i*imag(U3_rotated);
                 S2 = real(U2_rotated) + 1i*imag(U4_rotated);
                 S3 = real(U3_rotated) + 1i*imag(U1_rotated);
                 S4 = real(U4_rotated) + 1i*imag(U2_rotated);
            
            
                 %generate AWGN
                 n1 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 n2 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 n3 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 n4 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
           
                 %fading channel 
                 h1 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 h2 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 h3 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
                 h4 = sqrt(0.5)*(randn(Nr,1)+1i*randn(Nr,1));
         
                 %Received Signal vectors at t and (t+T) respectively
                 Y1 = (h1*S1 + h2*S2) + n1/sqrt(SNR_dec(ii)/2);
                 Y2 = (-h1*conj(S2) + h2*conj(S1)) + n2/sqrt(SNR_dec(ii)/2);
                 Y3 = (h3*S3 + h4*S4) + n3/sqrt(SNR_dec(ii)/2);
                 Y4 = (-h3*conj(S4) + h4*conj(S3)) + n4/sqrt(SNR_dec(ii)/2);
            
                 g_1 = norm(h1,'fro').^2 + norm(h2,'fro').^2;  
                 g_2 = norm(h3,'fro').^2 + norm(h4,'fro').^2;
            
        
                 %combine the signals according to Alamouti Scheme for four
                 %time slots
                 r1 = ((h1)'*Y1) + ((Y2)'*h2);
                 r2 = ((h2)'*Y1) - ((Y2)'*h1);
                 r3 = ((h3)'*Y3) + ((Y4)'*h4);
                 r4 = ((h4)'*Y3) - ((Y4)'*h3);
            
                 %De-interleaver the combined signals
                 Z1 = real(r1) + 1i*imag(r3);
                 Z2 = real(r2) + 1i*imag(r4);
                 Z3 = real(r3) + 1i*imag(r1);
                 Z4 = real(r4) + 1i*imag(r2);
            
            
                %Maximum Likelihood detection...........................
                   
                for jj = 1:M
                
                    Xk_I = Map_real_R(jj);
                    Xk_Q = Map_imag_R(jj);
                
                    arg1(jj,1) = g_2*abs(real(Z1) - g_1*Xk_I)^2 + g_1*abs(imag(Z1)- g_2*Xk_Q)^2;
                
                    arg2(jj,1) = g_2*abs(real(Z2) - g_1*Xk_I)^2 + g_1*abs(imag(Z2)- g_2*Xk_Q)^2;
                
                    arg3(jj,1) = g_1*abs(real(Z3) - g_2*Xk_I)^2 + g_2*abs(imag(Z3)- g_1*Xk_Q)^2;
                
                    arg4(jj,1) = g_1*abs(real(Z4) - g_2*Xk_I)^2 + g_2*abs(imag(Z4)- g_1*Xk_Q)^2;   
                end
            
                 [di,idx1] = min(arg1);
                 [d2,idx2] = min(arg2);
                 [d3,idx3] = min(arg3);
                 [d4,idx4] = min(arg4);
                
                 est_bip((k_m)*16-15:(k_m)*16-12)= LUT(idx1,:);
                 est_bip((k_m)*16-11:(k_m)*16-8)= LUT(idx2,:);
                 est_bip((k_m)*16-7:(k_m)*16-4)= LUT(idx3,:);
                 est_bip((k_m)*16-3:(k_m)*16-0)= LUT(idx4,:);
             end
             
             Num_error(ii) = Num_error(ii)+ length(find(b_ip~=est_bip));
     end
             
     BER(ii) = Num_error(ii)./(frame_counter(ii)*k*L);
     fprintf('%6.2e   ', BER(ii));
end

figure
semilogy(SNR_db(1:length(BER)),BER,'ko-','LineWidth',2);
axis([0 22 10^-6 1]) 
grid on
legend('16QAM SSD+Alamouti phase1 simulation ');
xlabel('Eb/No, (dB)');
ylabel('Bit error rate');
%title('ALAMOUTI-SSD-16QAM SIMULATION for 4 SYMBOLS');
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…