You are on page 1of 9

1.

Simulate the channel model for Free Space Propagation Loss and Log-Normal Shadowing Model
using MATLAB. Fill the missed lines of the program with the variable name given below and
plot the result (received power(in dB) vs the distance(in meters). (Assume: Pr1 - Free Space, Pr2
- Urban area cellular radio, Pr3 - Shadowed urban cellular radio, Pr4 - In building line-of-sight,
Pr5 - Obstructed in factories, Pr6 - Obstructed in building.)

clc;
clear all;
close all;
%%%%Parameters Setting%%%%%
d0=1;%1 meter
d=1;%meter
LightSpeedC=3e8;
WCDMACellular=2100*1000000;%hz
% LTECellular=2000*1000000;%hz
Freq=WCDMACellular
TXAntennaGain=1; %db
RXAntennaGain=1; %db
PTx=1e-03; % i.e. .001 watt assumptation
PathLossExponent=2; %Line Of sight
PTxdBm=10*log10(PTx*1000);
e=input ('Enter type of Environment (1 - Free Space, 2 - Urban area cellular radio, 3 -
Shadowed urban cellular radio, 4 - In building line-of-sight, 5 - Obstructed in factories, 6 -
Obstructed in building)--:');
% u=input ('Enter type of city (1 - urban , 2 - suburban, 3-rural)--:');
ht=input('Enter height of transmitting antenna(30 to 200m)--:');
hr=input('Enter height of receiving antenna(1 to 10m)--:');
d=input('Enter Distance in meter from 100 to 200--:');
display('The Received Power for your given data is Pr0 in dB is');
if e==1
PathLossExponent=2;
elseif e==2
PathLossExponent=3.1;
elseif e==3
PathLossExponent=4;
elseif e==4
PathLossExponent=1.7;
elseif e==5
PathLossExponent=2.5;
else
PathLossExponent=5;
end
Wavelength=LightSpeedC/Freq;
Pr0=PTxdBm + TXAntennaGain + RXAntennaGain-
(10*PathLossExponent*log10(4*pi/Wavelength))
display(Pr0);
figure
d=1;
% plot for entire range of frequencies
display('The plot for entire range of Distance from 100 to 2000 is shown in the plot');
h = waitbar(0,'plotting the Received Power for the entire range of Distance please wait......');
% log normal Shadowing Radio Propagation model:
% Pr0 = friss(d0)
% Pr(db) = Pr0(db) - 10*PathLossExponent*log(d/d0) + n
% where n is a Gaussian random variable with zero mean and a variance in db
% Pt * Gt * Gr * (Wavelength^PathLossExponent) d0^PathLossExponent (n/10)
% Pr = ---------------------------------------------*-----------------------*10
% 4 *pi * d0^PathLossExponent d^PathLossExponent
% get power loss by adding a log-normal random variable (shadowing)
% the power loss is relative to that at reference distance d0
% reset rand does influcence random
rstate = randn('state');
randn('state', d);
%GaussRandom=normrnd(0,6)%mean+randn*sigma; %Help on randn
GaussRandom= (randn*0.1+0);
%disp(GaussRandom);
.
.
.
.
end
close(h);

2. Using MATLAB Simulate the channel access method used in some multiple-access protocols. That
allows multiple users to send data through a single communication channel, such as a coaxial
cable or microwave beam, by dividing the bandwidth of the channel into separate non-
overlapping frequency sub-channels and allocating each sub-channel to a separate user and plot the result

3. Verify and simulate the Direct sequence spread spectrum modulation and demodulation using
MATLAB and plot the result. Fill the missed lines of the program for the Demodulation and Despreading
of Received Signal.

% Direct Sequence Spread Spectrum

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc

clear

% Generating the bit pattern with each bit 20 samples long

b=round(rand(1,30));

pattern=[];

for k=1:30

if b(1,k)==0

sig=-ones(1,20);

else

sig=ones(1,20);

end

pattern=[pattern sig];

end

subplot(4,1,1)

plot(pattern);
axis([-1 620 -1.5 1.5]);

title( 'Original Bit Sequence');

% Generating the pseudo random bit pattern for spreading

d=round(rand(1,120));

pn_seq=[];

carrier=[];

t=[0:2*pi/4:2*pi]; % Creating 5 samples for one cosine

for k=1:120

if d(1,k)==0

sig=-ones(1,5);

else

sig=ones(1,5);

end

c=cos(t);

carrier=[carrier c];

pn_seq=[pn_seq sig];

end

% Spreading of sequence

spreaded_sig=pattern.*pn_seq;

subplot(4,1,2)

plot(spreaded_sig)

axis([-1 620 -1.5 1.5]);

title('Spreaded signal');

% BPSK Modulation of the spreaded signal

bpsk_sig=spreaded_sig.*carrier; % Modulating the signal


subplot(4,1,3);

plot(bpsk_sig)

axis([-1 620 -1.5 1.5]);

title('BPSK Modulated Signal');

%Plotting the FFT of DSSS signal

y=abs(fft(xcorr(bpsk_sig)));

subplot(4,1,4)

plot(y/max(y))

xlabel('Frequency')

ylabel('PSD')

4. Verify and simulate OFDM Transmitter and receiver systems using MATLAB and plot the result. In
this program, the parameters and the receiver part are given. Fill the missed lines of the program for the
transmitter system.

clear all

clc

close

% ---------------

% A: Setting Parameters

% ---------------

M = 4; % QPSK signal constellation

no_of_data_points = 64; % have 64 data points

block_size = 8; % size of each ofdm block

cp_len = ceil(0.1*block_size); % length of cyclic prefix

no_of_ifft_points = block_size; % 8 points for the FFT/IFFT

no_of_fft_points = block_size;
% ---------------------------------------------

% B: % +++++ TRANSMITTER +++++

% ---------------------------------------------

% ------------------------------------------

% E: % +++++ RECEIVER +++++

% ------------------------------------------

% 1. Pass the ofdm signal through the channel

recvd_signal = ofdm_signal;

% 4. Convert Data back to "parallel" form to perform FFT

recvd_signal_matrix = reshape(recvd_signal,rows_ifft_data, cols_ifft_data);

% 5. Remove CP

recvd_signal_matrix(1:cp_len,:)=[];

% 6. Perform FFT

for i=1:cols_ifft_data,

% FFT

fft_data_matrix(:,i) = fft(recvd_signal_matrix(:,i),no_of_fft_points);
end

% 7. Convert to serial stream

recvd_serial_data = reshape(fft_data_matrix, 1,(block_size*num_cols));

% 8. Demodulate the data

qpsk_demodulated_data = pskdemod(recvd_serial_data,M);

scatterplot(qpsk_modulated_data);title('qpsk modulated received data')

figure(5)

stem(qpsk_demodulated_data,'rx');

grid on;xlabel('data points');ylabel('received data phase representation');title('Received Data "X"')

7. Verify and Implement the MIMO including spatial multiplexing using MATLAB and plot the result.
Fill the missed lines of the program for the receiver.

% Script for computing the BER for BPSK modulation in a


% Rayleigh fading channel with 2 Tx, 2Rx MIMO channel
% Maximum Likelihood equalization

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) + 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;
% Maximum Likelihood Receiver
% ----------------------------
.
.
.
.
.
.
.
.
.
.
.
.
.

% finding the minimum from the four alphabet combinations


rVec = [J11;J10;J01;J00];
[jj dd] = min(rVec,[],1);

% mapping the minima to bits


ref = [1 1; 1 0; 0 1; 0 0 ];
ipHat = zeros(1,N);
ipHat(1:2:end) = ref(dd,1);
ipHat(2:2:end) = ref(dd,2);

% 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('theory (nTx=1,nRx=1)', 'theory (nTx=1,nRx=2, MRC)', 'sim (nTx=2, nRx=2, ML)');
xlabel('Average Eb/No,dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2x2 MIMO and ML equalizer (Rayleigh channel)');

You might also like