1.transmit Diversity vs. Receive Diversity: Matlab Code With Output
1.transmit Diversity vs. Receive Diversity: Matlab Code With Output
load ostbcRes.mat;
% Set up a figure for visualizing BER results
%clf(h); grid on; hold on; set(h, 'renderer', 'zbuffer');
set(gca, 'yscale', 'log', 'xlim', [EbNo(1), EbNo(end)], 'ylim', [1e-5 1]);
xlabel('Eb/No (dB)');
ylabel('BER');
%set(h,'Name','Orthogonal Space-Time Block Coding(2)');
title('MIMO 4x4 System and Other Comparisons');
hold on; grid on;
% Theoretical performance of fourth-order diversity for QPSK
BERthy4 = berfading(EbNo, 'psk', 4, 4);
% Plot results
semilogy(EbNo, ber11, 'r*', EbNo, ber41, 'ms', EbNo, ber22, 'c^', ...
EbNo, ber14, 'ko', EbNo, BERthy4, 'g');
legend('No Diversity (4Tx, 4Rx), QAM', 'OSTBC (4Tx, 4Rx), QAM', ...
'Alamouti (4Tx, 4Rx), QAM', 'Maximal-Ratio Combining (4Tx, 4Rx), QAM', ...
'Theoretical 4th-Order Diversity, QAM');
% Perform curve fitting
fitBER11 = berfit(EbNo, ber11);
fitBER41 = berfit(EbNo(1:9), ber41(1:9));
fitBER22 = berfit(EbNo(1:8), ber22(1:8));
fitBER14 = berfit(EbNo(1:7), ber14(1:7));
semilogy(EbNo, fitBER11, 'r', EbNo(1:9), fitBER41, 'm', ...
EbNo(1:8), fitBER22, 'c', EbNo(1:7), fitBER14, 'k'); hold off;
3 . COMPARISON OF BER vs. SNR (4-QAM) FOR AN OFDM
%OFDM
% close all
% clear all
% clc
tt = tic();
%%
% Initialisations
Single_frame_size = 96;
Total_no_of_Frames = 100;
scatter_plot_frame = 48;
x=1; %Frame distinction xx=1; %Scatter plot distinction
si=1; %for BER rows
pilt=3+3j; % Pilot complex insertion data
no_of_Carriers = 64; % Data to be transmitted without CP/CE
initial_test_snr = -2;
snr_step_size = 2;
final_test_snr = 50;
BER = zeros( Total_no_of_Frames ,floor( (final_test_snr+snr_step_size)/snr_step_size )); % To store
final Bit error rate results; here it is 100*26
no_of_pilots = 4;
no_of_data_without_carriers = (Single_frame_size*2/no_of_pilots) + no_of_pilots; % 52 in this case ;
derived from line "x"
cyclic_extension = 16;
choice_snr = 14; % choose a valid snr value to plot the result ---- see below
%%
% Generating data
t_data = floor(2*rand(1,Single_frame_size*Total_no_of_Frames));
t_rxed_data=zeros(2,Single_frame_size*Total_no_of_Frames);
% Time averaging for optimum results
ber = zeros(1,26);
BER = BER';
for col=1:26; %%%change if SNR loop Changed
ber(1,col)=ber(1,col)+sum(BER(col,:));
end
%ber=ber/(Single_frame_size*Total_no_of_Frames*log2(M)); % Normalisation
%%% RESULTS
%%
% Scatter Plot
% Create scatter plot of noisy signal and transmitted
% signal on the same axes. h = scatterplot(scatter_plot_requirement(2,:),1,0,'g.');
hold on;
%scatterplot(scatter_plot_requirement(1,:),1,0,'k*',h);
choice_snr = num2str(choice_snr);
title_print = strcat('received Signal of SNR = ',choice_snr);
title(title_print);
legend('Noisy received Signal','Signal Constellation');
axis([-5 5 -5 5 ]); % Set axis ranges.
hold on;%%
% Plot for comparison between original signal wrt processed rxed signal
figure;
space = 10;
t = 1:space:Single_frame_size*Total_no_of_Frames;
subplot(211);
y=[t_rxed_data(1,1:space:Single_frame_size*Total_no_of_Frames);t_data(1:space:Single_frame_size*To
tal_no_of_Frames)]';
h = stem(t,y);
set(h(1),'MarkerFaceColor','blue') ;
set(h(2),'MarkerFaceColor','G','Marker','square');
title('Blue --> Processed received Signal at SNR = 50 & Red --> Original generated data');
subplot(212);
y=[t_rxed_data(2,1:space:Single_frame_size*Total_no_of_Frames);t_data(1:space:Single_frame_size*To
tal_no_of_Frames)]';
h = stem(t,y);
set(h(1),'MarkerFaceColor','blue') ;
set(h(2),'MarkerFaceColor','red','Marker','square') ;
title_print = strcat('Blue --> Processed received Signal of SNR = ',choice_snr,' & Red --> Original
generated data');
title(title_print);%%
% BER vs SNR graph
figure;
i=0:2:16;
theoryBer = (1/4)*3/2*erfc(sqrt(4*0.1*(10.^(i/10))));
semilogy(i,theoryBer,'bs-','LineWidth',2);
hold on;
%semilogy(i,ber(1:9),'mx-','LineWidth',2);
title('BER vs SNR');
ylabel('Normalised BER');
xlabel('SNR (dB)');
grid on;
legend('OFDM technique', '-');
%%
toc(tt); % Processing time on my laptop was ~2 seconds
4. BER and SNR (4-QAM) for the proposed technique for MIMO-OFDM system
clear
N = 10^6; % number of bits or symbols
Eb_N0_dB = (0:25); % multiple Eb/N0 values
nTx = 2;
nRx = 2;
for ii = 1:length(Eb_N0_dB)
% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
sMod = kron(s,ones(nRx,1)); %
sMod = reshape(sMod,[nRx,nTx,N/nTx]); % grouping in [nRx,nTx,N/NTx ] matrix
h = 1/sqrt(2)*(randn(nRx,nTx,N/nTx) + 1i*randn(nRx,nTx,N/nTx)); % Rayleigh channel
n = 1/sqrt(2)*(randn(nRx,N/nTx) + 1i*randn(nRx,N/nTx)); % white gaussian noise, 0dB variance
% Channel and noise Noise addition
y = squeeze(sum(h.*sMod,2)) + 10^(-Eb_N0_dB(ii)/20)*n;
% Receiver
% Forming the MMSE equalization matrix W = inv(H^H*H+sigma^2*I)*H^H
% H^H*H is of dimension [nTx x nTx]. In this case [2 x 2]
% Inverse of a [2x2] matrix [a b; c d] = 1/(ad-bc)[d -b;-c a]
hCof = zeros(2,2,N/nTx) ;
hCof(1,1,:) = sum(h(:,2,:).*conj(h(:,2,:)),1) + 10^(-Eb_N0_dB(ii)/10); % d term
hCof(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) + 10^(-Eb_N0_dB(ii)/10); % a term
hCof(2,1,:) = -sum(h(:,2,:).*conj(h(:,1,:)),1); % c term
hCof(1,2,:) = -sum(h(:,1,:).*conj(h(:,2,:)),1); % b term
hDen = ((hCof(1,1,:).*hCof(2,2,:)) - (hCof(1,2,:).*hCof(2,1,:))); % ad-bc term
hDen = reshape(kron(reshape(hDen,1,N/nTx),ones(2,2)),2,2,N/nTx); % formatting for division
hInv = hCof./hDen; % inv(H^H*H)
hMod = reshape(conj(h),nRx,N); % H^H operation
yMod = kron(y,ones(1,2)); % formatting the received symbol for equalization
yMod = sum(hMod.*yMod,1); % H^H * y
yMod = kron(reshape(yMod,2,N/nTx),ones(1,2)); % formatting
yHat = sum(reshape(hInv,2,N).*yMod,1); % inv(H^H*H)*H^H*y
% receiver - hard decision decoding
ipHat = real(yHat)>0;
% counting the errors
% nErr(ii) = size(find(ip- ipHat),2);
end
%simBer = nErr/N; % simulated ber
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin).^(-0.5));
p = 1/2 - 1/2*(1+1./EbN0Lin).^(-1/2);
theoryBerMRC_nRx2 = p.^2.*(1+2*(1-p));
close all
figure
semilogy(Eb_N0_dB,theoryBer_nRx1,'bp-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBerMRC_nRx2,'kd-','LineWidth',2);
%semilogy(Eb_N0_dB,simBer,'mo-','LineWidth',2);
axis([0 25 10^-5 0.5])
grid on
legend(' 4-QAM system with model', ' effect of noise On 4-QAM system', 'sim (nTx=2, nRx=2, MMSE)');
xlabel('SNR,dB');
ylabel('Bit Error Rate');
title('BER vs SNR for QAM modulation with 2x2 MIMO-OFDM equalizer (Rayleigh channel)');
5. Linear Equalization for Frequency-selective Fading