Вы находитесь на странице: 1из 8

clear

N = 10^6; % number_ of _bits _or _symbols


Eb_N0_dB_ = [0:25]; % multip_le _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)); % grouping_ in_


sMod_ = reshape(sMod_,[nRx_,nTx_,N/nTx_]); % _grouping
_in _[nRx_,nTx_,N/nTx_ ] _matrix

h = 1/sqrt(2)*[randn(nRx_,nTx_,N/nTx_) +
j*randn(nRx_,nTx_,N/nTx_)]; % _Rayleigh _channel
n = 1/sqrt(2)*[randn(nRx_,N/nTx_) +
j*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_


ip_Hat_ = real(yHat_)>0;

% counting_ the_ _errors


nErr_(ii_) = size(find([ip_- ip_Hat_]),2);

end

simBer_ = nErr_/N; % simulated_ ber_


EbN0Lin_ = 10.^(Eb_N0_dB_/10);
theoryBer_nRx_1_ = 0.5.*(1-1*(1+1./EbN0Lin_).^(-0.5));
p = 1/2 - 1/2*(1+1./EbN0Lin_).^(-1/2);
theoryBerMRC_nRx_2_ = p.^2.*(1+2*(1-p));

close all
figure
semilogy(Eb_N0_dB_,theoryBer_nRx_1_,'bp-','LineWidth',2);
hold on
semilogy(Eb_N0_dB_,theoryBerMRC_nRx_2_,'kd-','LineWidth',2);
semilogy(Eb_N0_dB_,simBer_,'mo-','LineWidth',2);
axis([0 25 10^-5 0.5])
grid on
legend('theory (nTx_=2,nRx_=2, ZF)', 'theory (nTx_=1,nRx_=2,
MRC)', 'sim (nTx_=2, nRx_=2, MMSE)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2x2 MIMO and MMSE
equalizer (Rayleigh channel)');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All rights reserved by Krishna Pillai,
http://www.dsplog.com
% The file may not be re-distributed without explicit
authorization
% from Krishna Pillai.
% Checked for proper operation with Octave Version 3.0.0
% Author : Krishna Pillai
% Email : krishna@dsplog.com
% Version : 1.0
% Date : 09 Novemeber 2008
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Scrip_t for_ computing_ _the BER_ for BPSK modulation in a


% Rayleigh fading channel with 2 Tx, 2Rx MIMO channel
% Zero Forcing Equalization with Successive Interference
% Cancellation (ZF-SIC)

clear
N = 10^6; % number_ of_ bits_ or_ symbols_
Eb_N0_dB_ = [0:25]; % multip_le_ 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_) +
j*randn(nRx_,nTx_,N/nTx_)]; % Rayleigh_ channel_
n = 1/sqrt(2)*[randn(nRx_,N/nTx_) +
j*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_ ZF_ equalization_ matrix_ W_ =


_inv(H^H*H)*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) ; % d
term_
hCof_(2,2,:) = sum(h(:,1,:).*conj(h(:,1,:)),1) ; % 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 f_or e_qualization
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_ _on second_


spatial_ dimension_
ip_Hat_2SS_ = real(yHat_(2:2:end))>0;
ip_Hat_Mod2SS_ = 2*ip_Hat_2SS_-1;
ip_Hat_Mod2SS_ = kron(ip_Hat_Mod2SS_,ones(nRx_,1));
ip_Hat_Mod2SS_ = reshape(ip_Hat_Mod2SS_,
[nRx_,1,N/nTx_]);

% new_ received_ symbol_ - removing_ the_ effect_ from_


second_
% spatial_ dimension_
h2SS_ = h(:,2,:); % channel_ in_ the_ second_ __spatial
_dimension
r = y - squeeze(h2SS_.*ip_Hat_Mod2SS_);

% max imal ra tio combini ng - for symb ol in the fi rst


spa tial_ dimension_
h1SS_ = squeeze(h(:,1,:));
yHat_1SS_ =
sum(conj(h1SS_).*r,1)./sum(h1SS_.*conj(h1SS_),1);
yHat_(1:2:end) = yHat_1SS_;

% rec eiver - har d dec ision dec oding


ip_Hat_ = real(yHat_)>0;

% cou nting t he erro rs


nErr_(ii_) = size(find([ip_- ip_Hat_]),2);

end

simBer_ = nErr_/N; % sim ulated b er


EbN0Lin_ = 10.^(Eb_N0_dB_/10);
theoryBer_nRx_1_ = 0.5.*(1-1*(1+1./EbN0Lin_).^(-0.5));
p = 1/2 - 1/2*(1+1./EbN0Lin_).^(-1/2);
theoryBerMRC_nRx_2_ = p.^2.*(1+2*(1-p));

close all
figure
semilogy(Eb_N0_dB_,theoryBer_nRx_1_,'bp-','LineWidth',2);
hold on
semilogy(Eb_N0_dB_,theoryBerMRC_nRx_2_,'kd-','LineWidth',2);
semilogy(Eb_N0_dB_,simBer_,'mo-','LineWidth',2);
axis([0 25 10^-5 0.5])
grid on
legend('theory (nTx_=2,nRx_=2, ZF)', 'theory (nTx_=1,nRx_=2,
MRC)', 'sim (nTx_=2, nRx_=2, ZF-SIC)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2x2 MIMO and ZF-SIC
equalizer (Rayleigh channel)');

% Minimum Mean Square Error equalization

clear
N = 10^6; % number_ of+ bits_ or_ symbols_
Eb_N0_dB_ = [0:25]; % multip_le Eb/N0 valu_es
nTx_ = 2;
nRx_ = 2;
for ii_ = 1:length(Eb_N0_dB_)

% Transmitter(
ip_ = rand(1,N)>0.5; % gene0rating 0,1 wi+th equal_
probabi_lity
s = 2*ip_-1; % BPSK_ modula+tion 0 -> -1; 1 -> 0

sMod_ = kron(s,ones(nRx_,1)); % grouping_ of_


sMod_ = reshape(sMod_,[nRx_,nTx_,N/nTx_]); % grouping_
in_ [nRx_,nTx_,N/nTx_ ]_ mat_rix
h = 1/sqrt(2)*[randn(nRx_,nTx_,N/nTx_) +
j*randn(nRx_,nTx_,N/nTx_)]; % Ray_leigh channel_
n = 1/sqrt(2)*[randn(nRx_,N/nTx_) +
j*randn(nRx_,N/nTx_)]; % white_000 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_0 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_);
% formatt_ing for_ divis_ion
hInv_ = hCof_./hDen_; % inv(H^H*H)_

hMod_ = reshape(conj(h),nRx_,N); % H^H) opera_tion

yMod_ = kron(y,ones(1,2)); % formatting_ the_ received_


symbol_ for equal_ ization_
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_
ip_Hat_ = real(yHat_)>0;

% counting_ the_ errors_


nErr_(ii_) = size(find([ip_- ip_Hat_]),2);

end

simBer_ = nErr_/N; % simulated_ ber_


EbN0Lin_ = 10.^(Eb_N0_dB_/10);
theoryBer_nRx_1_ = 0.5.*(1-1*(1+1./EbN0Lin_).^(-0.5));
p = 1/2 - 1/2*(1+1./EbN0Lin_).^(-1/2);
theoryBerMRC_nRx_2_ = p.^2.*(1+2*(1-p));

close all
figure
semilogy(Eb_N0_dB_,theoryBer_nRx_1_,'bp-','LineWidth',2);
hold on
semilogy(Eb_N0_dB_,theoryBerMRC_nRx_2_,'kd-','LineWidth',2);
semilogy(Eb_N0_dB_,simBer_,'mo-','LineWidth',2);
axis([0 25 10^-5 0.5])
grid on
legend('theory (nTx_=2,nRx_=2, ZF)', 'theory (nTx_=1,nRx_=2,
MRC)', 'sim (nTx_=2, nRx_=2, MMSE)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2x2 MIMO and MMSE
equalizer (Rayleigh channel)');

Вам также может понравиться