AkanshaKhandelwalMCA (SE) 2ndsem

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

UNIVERSITY SCHOOL OF INFORMATION,

COMMUNICATION AND TECHNOLOGY

MOBILE COMPUTING PROGRAMS

MENTOR: MENTEE:

PROF. BHARTI SURI KATYAYNY RAGHUVANSHI


Dr. M. Bala Krishnan Akansha Khandelwal
MCA(SE)
(Assistant Professor) MCA(SE)
ENROLL: 01416404521
ENROLL: 03216404521
Question 1: Modulation Techniques: QPSK and FSK
%QPSK TECHNIQUE DEMONSTRATION
clc;
close all;
data=[0 1 0 1 1 1 0 0 1 1]; % information
%Number_of_bit=1024;
%data=randint(Number_of_bit,1);
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting ');
axis([ 0 11 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for QPSK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion of data
br=10.^6; %Let us transmission bit rate 1000000
f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit information
% XXXXXXXXXXXXXXXXXXXXXXX QPSK modulatio
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
y=[];
y_in=[];
y_qd=[];
for(i=1:length(data)/2)
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal vector
y=[y y1+y2]; % modulated signal vector
end
Tx_sig=y; % transmitting signal after modulation
tt=T/99:T/99:(T*length(data))/2;
figure(2)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(' wave form for inphase component in QPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(' wave form for Quadrature component in QPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('QPSK modulated signal (sum of inphase and Quadrature phase signal)');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
% XXXXXXXXXXXXXXXXXXXXXXXXXXXX QPSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXX
Rx_data=[];
Rx_sig=Tx_sig; % Received signal
for(i=1:1:length(data)/2)
%%XXXXXX inphase coherent dector XXXXXXX
Z_in=Rx_sig((i-1)*length(t)+1:i*length(t)).*cos(2*pi*f*t);
% above line indicat multiplication of received & inphase carred signal

Z_in_intg=(trapz(t,Z_in))*(2/T);% integration using trapizodial rull


if(Z_in_intg>0) % Decession Maker
Rx_in_data=1;
else
Rx_in_data=0;
end

%%XXXXXX Quadrature coherent dector XXXXXX


Z_qd=Rx_sig((i-1)*length(t)+1:i*length(t)).*sin(2*pi*f*t);
%above line indicat multiplication ofreceived & Quadphase carred signal

Z_qd_intg=(trapz(t,Z_qd))*(2/T);%integration using trapizodial rull


if (Z_qd_intg>0)% Decession Maker
Rx_qd_data=1;
else
Rx_qd_data=0;
end
Rx_data=[Rx_data Rx_in_data Rx_qd_data]; % Received Data vector
end
figure(3)
stem(Rx_data,'linewidth',3)
title('Information after Receiveing ');
axis([ 0 11 0 1.5]), grid on;
%% FSK Modulation and Demodulation
clc
%% Define Data bits
data=[1 0 1 0 1 1 1 0 0 1];
%% Define carrier signal
f=1000;
fs=f*100;
Ts=1/fs;
T=1/f;
M=10;
n=M*length(data);
t=0:Ts:n*T;
car=sin(2*pi*t*f);
figure;
subplot(3,1,1);
plot(car,'r');
xlabel('Samples(Carrier signal)');
ylabel('Amplitude');
%% Converting data bits into pulse
tp=0:Ts:M*T;
exData=[];
for i=1:length(data)
for j=1:length(tp)-1
exData=[exData data(i)];
end
end
exData(1,size(exData)+1)=exData(1,size(exData));
subplot(3,1,2)
plot(exData,'g','Linewidth',2)
xlabel('Samples(Message signal)');
ylabel('Amplitude');

%% FSK Modulation schemes


deltaf=.5;
fh=f + (f*deltaf);
fl=f - (f*deltaf);

t=0:Ts:(T*M);
carh=sin(2*pi*t*fh); %High frequency carrier for data bit 1
carl=sin(2*pi*t*fl); %Low frequency carrier for data bit 0

modSig=[];

for i=1:length(data)
if(data(i)==1)
modSig=[modSig carh];
else
modSig=[modSig carl];
end
end
subplot(3,1,3);
plot(modSig,'b');
xlabel('Samples(FSK Modulated signal)');
ylabel('Amplitude');

%% Transmitting over awgn channel


SNR=10;
sampleValue=mod(randi(20),10)+10;
rx=awgn(modSig,SNR);
figure;
subplot(2,1,1);
plot(modSig,'b');
xlabel('Samples(FSK Modulated signal)');
ylabel('Amplitude');
subplot(2,1,2);
plot(rx,'r');
xlabel('Samples(FSK Recieved signal)');
ylabel('Amplitude');
%% Demodulation of recieved signal
% Finding no of zeros in interval of tp i.e finding frequency of signal at every
interval
negative=0;
positive=0;

totalBits=length(rx)/length(tp);
sdiff=0;
noofzeros=0;
zeroSample=[];
k=1;
for i=1:totalBits
for j=1:length(tp)
if(sdiff>sampleValue)
if(rx(1,k)>0)
positive=1;
end
if(rx(1,k)<0)
negative=1;
end
end
k=k+1;
sdiff=sdiff+1;
if(positive==1 && negative==1)
noofzeros=noofzeros+1;
positive=0;
sdiff=0;
negative=0;
end
end
zeroSample=[zeroSample noofzeros];
noofzeros=0;
end
firstZeroSample=zeroSample(1,1);
zeroSample=zeroSample/firstZeroSample;

% Generating data according to given frequency samples or given zero samples


filtData=[];
for i=1:length(zeroSample)
if(zeroSample(i)>=1)
filtData=[filtData 1];
else
filtData=[filtData 0];
end
end
figure;
subplot(3,1,1);
stem(data,'b','Linewidth',2);
xlabel('Samples(Message signal)');
ylabel('Amplitude');
subplot(3,1,2);
stem(filtData,'g','Linewidth',2);
xlabel('Samples(Recieved signal)');
ylabel('Amplitude');
subplot(3,1,3);
stem(abs(data-filtData),'r','Linewidth',2);
xlabel('Samples(Error signal)');
ylabel('Amplitude');

%% Finding Bit error rate


[BER NOR]=biterr(data,filtData)
Question 2: FDMA, CDMA, TDMA
% Simulation of Frequency Division Multiplexing
clc;
clear all
close all
samples=1000;
% number of users
nos=8;
% modulating signal frequency in Hz
mfreq=[30 40 50 60 70 80 90 100];
% carrier frequency allocated to the different users in Hz
cfreq=[300 600 900 12000 1500 1800 2100 2400];
% choose frequency deviation
freqdev=10;
% generate modulating signal
t=linspace(0,1000,samples);
parfor i=1:nos
m(i,:)=sin(2*pi*mfreq(1,i)*t)+2*sin(pi*8*t);
end
% Generate the modulated signal
parfor i=1:nos
y(i,:)=fmmod(m(i,:),cfreq(1,i),10*cfreq(1,i),freqdev);
end
% pass the modulated signal through the channel
ch_op=awgn(sum(y),0,'measured');
% demodulate the received signal at the base station
parfor i=1:nos
z(i,:)=fmdemod(y(i,:),cfreq(1,i),10*cfreq(1,i),freqdev);
end
% display the transmitted signal and received signal at the base station
% figure
C = {'k','b','r','g','y',[.5 .6 .7],[.8 .2 .6],[.3 .2 .2]}; % Cell array of colros.
for i=1:nos
figure (1)
hold on
plot(y(i,:),'color',C{i});
xlabel('time index'); ylabel('amplitude'); title('Signal from different users
combined in the channel');
figure
subplot(3,1,1)
plot(m(i,:)) % modulating signal
xlabel('time index'); ylabel('amplitude'); title('modulating Signal from user');
subplot(3,1,2)
plot(y(i,:),'color',C{i}); % modulated signal
xlabel('time index'); ylabel('amplitude'); title('modulated Signal from user');
subplot(3,1,3)
plot(z(i,:),'color',C{i}); % demodulated signal
xlabel('time index'); ylabel('amplitude'); title('demodulated Signal from user at
the base station');
end
figure
plot(ch_op) % combination of all modulated signals passed through the channel
xlabel('time index'); ylabel('amplitude'); title('Signal after passing through the
channel');
% Simulation of Time Division Multiplexing
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi
sig1=8*sin(x); % generate 1st sinusoidal signal
l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal
% Display of Both Signal
subplot(2,2,1);
plot(sig1);
title('Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,2);
plot(sig2);
title('Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Display of Both Sampled Signal
subplot(2,2,3);
stem(sig1);
title('Sampled Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,4);
stem(sig2);
title('Sampled Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
l1=length(sig1);
l2=length(sig2);
for i=1:l1
sig(1,i)=sig1(i); % Making Both row vector to a matrix
sig(2,i)=sig2(i);
end
% TDM of both quantize signal
tdmsig=reshape(sig,1,2*l1);
% Display of TDM Signal
figure
stem(tdmsig);
title('TDM Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Demultiplexing of TDM Signal
demux=reshape(tdmsig,2,l1);
for i=1:l1
sig3(i)=demux(1,i); % Converting The matrix into row vectors
sig4(i)=demux(2,i);
end

% display of demultiplexed signal


figure
subplot(2,1,1)
plot(sig3);
title('Recovered Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,1,2)
plot(sig4);
title('Recovered Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Simulation of Code Division Multiplexing
close all;
clc;
%N=6;
%data=input('Enter Binary Data In Form of 0 and 1 in [ ] : ');
data=[1 0 0 1 1 0 1 1];
figure('Name','Message BPSK Modulation','NumberTitle','off')
subplot(2,2,1);
plot(rectpulse(data,100));
axis([0 length(rectpulse(data,100)) -0.2 1.2]);
title('Message Signal');
xlabel('n');
ylabel('x(n)');
grid on;
data(data(:)==0)=-1;
length_data=length(data);
fc1=10;
eb=2;
tb=1;
T=1;
msg=rectpulse(data,100);
subplot(2,2,2);
plot(msg);
title('Message Signal in NRZ form');
xlabel('n');
ylabel('x(n)');
axis([0 100*length_data -1.2 1.2]);
grid on;
N=length_data;
Tb = 0.0001;
nb=100;
br = 1/Tb;
Fc = br*10;
t2 = Tb/nb:Tb/nb:Tb;
t1=0.01:0.01:length_data;
bpskmod=sqrt(2/T)*cos(2*pi*fc1*t1);
bpsk_data=msg.*bpskmod;
subplot(2,2,3)
plot(bpsk_data)
title(' BPSK signal');
xlabel('Time Period(t)');
ylabel('x(t)');
axis([0 100*length_data -2 2]);
grid on;
subplot(2,2,4);
plot(real(fft(bpsk_data)));
title('FFT of BPSK signal');
xlabel('Frequency');
ylabel('PSD');
grid on;
sr=[1 -1 1 -1];
pn1=[];
for i=1:length_data
for j=1:10
pn1=[pn1 sr(4)];
if sr (4)==sr(3)
temp=-1;
else temp=1;
end
sr(4)=sr(3);
sr(3)=sr(2);
sr(2)=sr(1);
sr(1)=temp;
end
end
figure('Name','PN Generation and CDMA','NumberTitle','off');
subplot(2,2,1);
stem(pn1);
axis([0,length(pn1),-1.2,1.2])
title('PN sequence for data')
xlabel('n');
ylabel('x(n)');
grid on;
pnupsampled1=[];
len_pn1=length(pn1);
for i=1:len_pn1
for j=0.1:0.1:tb
pnupsampled1=[pnupsampled1 pn1(i)];
end
end
length_pnupsampled1=length(pnupsampled1);
subplot(2,2,2)
stem(pnupsampled1);
axis([0,length(pnupsampled1),-1.2,1.2])
title('PN sequence for data upsampled');
xlabel('n');
ylabel('x(n)');
grid on;
subplot(2,2,3);
sigtx1=bpsk_data.*pnupsampled1;
plot(sigtx1);
title('CDMA Signal');
xlabel('Time Period(t)');
ylabel('x(t)');
subplot(2,2,4);
plot(real(fft(sigtx1)));
title('FFT of spreaded CDMA Signal');
xlabel('Frequency');
ylabel('PSD');
grid on;
sigtonoise=20;
composite_signal=awgn(sigtx1,sigtonoise);
figure('Name','CDMA Reciever','NumberTitle','off')
subplot(2,2,1);
plot(sigtx1);
title(' Tx Signal');
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
subplot(2,2,2);
plot(composite_signal);
title(sprintf('Tx signal + noise\n SNR=%ddb',sigtonoise));
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
%Rx
rx=composite_signal.*pnupsampled1;
subplot(2,2,3);
plot(rx);
title('CDMA Demodulated signal');
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
%BPSK Demodulation
y=[];
bpskdemod=rx.*bpskmod;
for i=1:100:size(bpskdemod,2)
y=[y trapz(t1(i:i+99),bpskdemod(i:i+99))];
end
y(y(:)<=0)=-1;
y(y(:)>=0)=1;
rxdata=y;
subplot(2,2,4);
plot(rectpulse(rxdata,100));
axis([0 length(rectpulse(rxdata,100)) -1.2 1.2]);
title('Recieved Message Signal in NRZ');
xlabel('n');
ylabel('x(n)');
grid on;
rxdata(rxdata(:)==-1)=0;
rxdata(rxdata(:)==1)=1;
rxmsg=rxdata;
figure('Name','Diffrent SNR','NumberTitle','off')
subplot(3,1,1)
plot(rectpulse(rxmsg,100));
axis([0 length(rectpulse(rxmsg,100)) -0.2 1.2]);
title('Recieved Message Signal');
xlabel('n');
ylabel('x(n)');
grid on;
sigtonoise1=5;
composite_signal1=awgn(sigtx1,sigtonoise1);
subplot(3,1,2);
plot(composite_signal);
title(sprintf('Tx signal + noise\n SNR=%ddb',sigtonoise1));
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
sigtonoise2=0;
composite_signal2=awgn(sigtx1,sigtonoise2);
subplot(3,1,3);
plot(composite_signal2);
title(sprintf('Tx signal + noise\n SNR=%ddb',sigtonoise2));
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
scatterplot(composite_signal); grid minor;
title('Constellation Diagram of BPSK with Noise')
grid on
scatterplot(bpsk_data); grid minor;
title('Constellation Diagram of BPSK')
grid on
Question 3: Rayleigh and Ricean Fading channels
%Rayleigh and Rician Fading Channels Demonstration
clc
clear all;
close all;
n=100000;%no_of_samples
i=randi([0,1],1,n);%generates random integers 0's and 1's
i1=2*i-1;%bpsk modulation i.e, mapping 1's as 1 and 0's as -1
%scatterplot(i1);%scatterplot of bpsk modulation scheme
%rayleigh fading channel
a=randn(1,n);%generates samples of size 1xn which are gaussian distributed
b=randn(1,n);%generates samples of size 1xn which are gaussian distributed
rc=1/sqrt(2)*(sqrt(a.^2+b.^2));%rayleigh channel
for l=0:1:20
snr=10^((l/10)); % SNR values in absolute scale
sdev=sqrt(0.5/snr); % standard deviation of noise calculated from SNR
N=random('norm',0,sdev,[1,n]);% generation of noise sequence
yrc=rc.*i1+N; %signal received through rayleigh and awgn channel
yawgn=i1+N; %signal received through awgn channel
Yb=(yawgn>=0);% baseband signal detection from awgn channel
YR=(yrc>=0); %baseband detection from Rayleigh,AWGN channel
ErrorR=sum((xor(YR,i)));% no of errors in detected signal
ErrorA=sum((xor(Yb,i)));
ber_A(l+1)=ErrorA/n;% simulated BER for awgn channel
ber_R(l+1)=ErrorR/n;%simulated BER for AWGN,rayleigh channel
berthR(l+1)=0.5*(1-sqrt(snr/(snr+1)));%theoretical bit error rate of
% rayleigh,awgn channel
p=((1-2*ber_R(l+1))^2)/(4*(ber_R(l+1)-(ber_R(l+1)^2)));
outage(l+1)=1-exp(-3.16/p);%simulated ber computed from rayleigh channel
outageT(l+1)=1-exp(-3.16/snr);%theoretical ber computed from rayleigh
%channel
berthA(l+1)=0.5*erfc(sqrt(2*snr));%theoretical ber computed for awgn channel
end
% scatterplot(yawgn)
% scatterplot(yrc)
figure
%comparison plot generation of theoretical and calculated SNR
q=0:1:20 ;
semilogy(q,ber_A(q+1),'-^b');
hold on
semilogy(q,berthA(q+1),'->y');
hold on
semilogy(q,berthR(q+1),'+r');
hold on
semilogy(q,ber_R(q+1),'g-');
axis([0 20 10^-5 1]);
%title('BER PERFORMANCE OF BPSK MODULATION SCHEME IN AWGN,RAYLEIGH CHANNEL')
xlabel('SNR')
ylabel('BIT ERROR RATE')
%figure
% plot(q,outage(q+1),'-');
% hold on
% plot(q,outageT(q+1),'+g');
%title('OUTAGE PERFORMANCE OF BPSK MODULATION IN AWGN,RAYLEIGH CHANNEL')
xlabel('SNR')
ylabel('OUTAGE PROBABILITY')
%RICIAN FADING
k1=10; %Rician factor
mean=sqrt(k1/(k1+1));% mean
sigma=sqrt(1/(2*(k1+1)));%variance
Nr2=randn(1,length(i1))*sigma+mean;
Ni2=randn(1,length(i1))*sigma;
%To generate the Rician Random Variable
No3=sqrt(Nr2.^2+Ni2.^2); %Rician fading coefficient
for k=0:1:20
snrl=10^(k/10);%convert the SNR in dB value
Np=1/snrl;%To generate the noise power
sd=sqrt(Np/2);% standard deviation of guassian noise
No=random('Normal',0,sd,1,length(i1)); %Generates Gaussian noise
t1=i1.*No3+No; % s means transmitted signal...please take the value as u have
taken
z1=t1./No3;
op1=(z1>0); % threshold detection
Berr(k+1)=sum(xor(op1,i))/n; % observed BER
BerTr(k+1)=.5*erfc(sqrt(k1*snrl/(k1+snrl)));% theoretical BER
end;
%figure;
k=0:1:20;
semilogy(k,Berr(k+1),'-*');
hold on;
semilogy(k,BerTr(k+1),'-<');
% axis([0 10 10^-5 1]);
% % plot(k,Berr(k),'-');
% hold on;
% plot(k,BerTr(k),'+g');
title('BER PERFORMANCE OF BPSK MODULATION SCHEME IN AWGN RAYLEIGH RICIAN FADING')
xlabel('SNR')
ylabel('BIT ERROR RATE')
hleg=legend('BER AWGN','BERth AWGN','BER rayleigh','BERth rayleigh','BER
Rician','BERth Rician')

Question 4: Spread Spectrum Systems: DFSS and FHSS


%Direct Sequence Spread Spectrum with 5 bits

clc;
close all;
clear all;
b=input('Enter The input Bits : ');
ln=length(b);
% Converting bit 0 to -1
for i=1:ln
if b(i)==0
b(i)=-1;
end
end
% Generating the bit sequence with each bit 8 samples long
k=1;
for i=1:ln
for j=1:8
bb(k)=b(i);
j=j+1;
k=k+1;
end
i=i+1;
end
len=length(bb);
subplot(2,1,1);
stairs(bb,'linewidth',2); axis([0 len -2 3]);
title('ORIGINAL BIT SEQUENCE b(t)');
% Generating the pseudo random bit pattern for spreading
pr_sig=round(rand(1,len));
for i=1:len
if pr_sig(i)==0
pr_sig(i)=-1;
end
end
subplot(2,1,2);
stairs(pr_sig,'linewidth',2); axis([0 len -2 3]);
title('PSEUDORANDOM BIT SEQUENCE pr_sig(t)');
% Multiplying bit sequence with Pseudorandom Sequence
for i=1:len
bbs(i)=bb(i).*pr_sig(i);
end
% Modulating the hopped signal
dsss=[];
t=0:1/10:2*pi;
c1=cos(t);
c2=cos(t+pi);
for k=1:len
if bbs(1,k)==-1
dsss=[dsss c1];
else
dsss=[dsss c2];
end
end
figure,
subplot(2,1,1);
stairs(bbs,'linewidth',2); axis([0 len -2 3]);
title('MULTIPLIER OUTPUT SEQUENCE b(t)*pr_sig(t)');
subplot(2,1,2);
plot(dsss);
title(' DS-SS SIGNAL...');
%Frequency Hopping Spread Spectrum
clc
clear
% Generation of bit pattern
s=round(rand(1,25)); % Generating 20 bits
signal=[];
carrier=[];
t=[0:2*pi/119:2*pi]; % Creating 60 samples for one cosine
for k=1:25
if s(1,k)==0
sig=-ones(1,120); % 120 minus ones for bit 0
else
sig=ones(1,120); % 120 ones for bit 1
end
c=cos(t);
carrier=[carrier c];
signal=[signal sig];
end
subplot(4,1,1);
plot(signal);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Original Bit Sequence');
% BPSK Modulation of the signal
bpsk_sig=signal.*carrier; % Modulating the signal
subplot(4,1,2);
plot(bpsk_sig)
axis([-100 3100 -1.5 1.5]);
title('\bf\it BPSK Modulated Signal');
% Preparation of 6 new carrier frequencies
t1=[0:2*pi/9:2*pi];
t2=[0:2*pi/19:2*pi];
t3=[0:2*pi/29:2*pi];
t4=[0:2*pi/39:2*pi];
t5=[0:2*pi/59:2*pi];
t6=[0:2*pi/119:2*pi];
c1=cos(t1);
c1=[c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1];
c2=cos(t2);
c2=[c2 c2 c2 c2 c2 c2];
c3=cos(t3);
c3=[c3 c3 c3 c3];
c4=cos(t4);
c4=[c4 c4 c4];
c5=cos(t5);
c5=[c5 c5];
c6=cos(t6);
% Random frequency hopps to form a spread signal
spread_signal=[];
for n=1:25
c=randint(1,1,[1 6]);
switch(c)
case(1)
spread_signal=[spread_signal c1];
case(2)
spread_signal=[spread_signal c2];
case(3)
spread_signal=[spread_signal c3];
case(4)
spread_signal=[spread_signal c4];
case(5)
spread_signal=[spread_signal c5];
case(6)
spread_signal=[spread_signal c6];
end
end
subplot(4,1,3)
plot([1:3000],spread_signal);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Spread Signal with 6 frequencies');
% Spreading BPSK Signal into wider band with total of 12 frequencies
freq_hopped_sig=bpsk_sig.*spread_signal;
subplot(4,1,4)
plot([1:3000],freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Frequency Hopped Spread Spectrum Signal');
% Expressing the FFTs
figure,subplot(2,1,1)
plot([1:3000],freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Frequency Hopped Spread Spectrum signal and its FFT');
subplot(2,1,2);
plot([1:3000],abs(fft(freq_hopped_sig)));

Question 5: GSM transmitter and receiver


% Set random number generator for repeatability
rng('default');
gmskMod = comm.GMSKModulator( ...
'BitInput', true, ...
'SamplesPerSymbol', 8);

% Modulate random bits using the GMSK object


x = gmskMod(randi([0 1], 1e4, 1));
v = 120*1e3/3600; % Mobile speed (m/s)
fc = 1.8e9; % Carrier frequency
fd = v*fc/physconst('lightspeed'); % Maximum Doppler shift
Rsym = 270.833e3; % GSM symbol rate
Rsamp = gmskMod.SamplesPerSymbol * Rsym; % GSM sample rate
gsmChan = stdchan('gsmHTx12c1', Rsamp, fd);
gsmChan.Visualization = 'Impulse response';
gsmChan(x);

Question 6: GPRS transmitter and receiver


cnavData = HelperGPSNAVDataEncode(cnavConfig);
% Initialize the trellis for convolutional encoder
trellis = poly2trellis(7,{'1+x+x^2+x^3+x^6','1+x^2+x^3+x^5+x^6'});
cenc = comm.ConvolutionalEncoder('TrellisStructure',trellis, ...
"TerminationMethod","Continuous");
encodedCNAVData = cenc(cnavData);
lnavData = HelperGPSNAVDataEncode(lnavConfig);
CLCodeResetIdx = 75; % CL-code spans over 75 data bits before resetting
numBBSamplesPerDataBit = 204600;
CLCodeIdx = mod(NavDataBitStartIndex-1,CLCodeResetIdx);
IQContent = [IBranchContent,QBranchContent];
pgen = gpsPCode("PRNID",PRNID,"InitialTime", ...
lnavConfig.CEIDataSet.ReferenceTimeOfEphemeris, ...
"OutputCodeLength",numBBSamplesPerDataBit);
% Pre-initialize the baseband waveform for speed
gpsBBWaveform = zeros(numBBSamplesPerDataBit*NumNavDataBits,1);
if WriteWaveformToFile == 1
bbWriter = comm.BasebandFileWriter('Waveform.bb',10.23e6,0);
end
for iDataBit = 1:NumNavDataBits
dataBitIdx = iDataBit+NavDataBitStartIndex-1;
bbSamplesIndices = ((iDataBit-1)*numBBSamplesPerDataBit+1): ...
(iDataBit*numBBSamplesPerDataBit);
gpsBBWaveform(bbSamplesIndices) = HelperGPSBasebandWaveform(IQContent,pgen,PRNID,
...
CLCodeIdx,lnavData(dataBitIdx),encodedCNAVData(dataBitIdx));
CLCodeIdx = mod(CLCodeIdx+1,CLCodeResetIdx);
if WriteWaveformToFile == 1
bbWriter(gpsBBWaveform(bbSamplesIndices));
end
end
if WriteWaveformToFile == 1
release(bbWriter);
end
if ShowVisualizations
% Because P-code is 10 times faster than C/A-code or L2 CM-/L2 CL-code,
% initialise down sample factor to 10
downsampleFactor = 10;
IBranchData = real(gpsBBWaveform);
QBranchData = imag(gpsBBWaveform(1:downsampleFactor:end));
lags = (-1023:1023).';
plot(lags,xcorr(real(QBranchData(1:1023)),1023))
grid on
xlabel('Number of Samples Delayed')
ylabel('Autocorrelation Value')
title('Autocorrelation of GPS Spreading Code')
repeatFactor = 40;
% Repeat the generated BPSK signal of C/A-code to see the adjacent bands spectrum
QBranchUpsampled = repmat(QBranchData(:).',repeatFactor,1);
QBranchUpsampled = QBranchUpsampled(:);
% Repeat the generated BPSK signal of in-phase component to see the
% adjacent bands spectrum. Repeat the in-phase branch samples ten times less
% as every sample in quadrature-branch corresponds to 10 samples in in-phase
branch
IBranchUpsampled = repmat(IBranchData(:).',repeatFactor/10,1);
IBranchUpsampled = real(IBranchUpsampled(:));
iqScope = dsp.SpectrumAnalyzer('SampleRate',1.023e6*repeatFactor, ...
'PlotAsTwoSidedSpectrum',true, ...
'SpectrumType','Power density', ...
'AveragingMethod','Exponential', ...
'SpectrumUnits','dBW', ...
'YLimits',[-130, -50],'Title', ...
'Comparison of Power Spectral Density of GPS baseband I and Q Signals', ...
'ShowLegend',true,'ChannelNames', ...
{['Q-branch spectrum with content: ' char(QBranchContent)], ...
['I-branch spectrum with content: ' char(IBranchContent)]});

iqScope([QBranchUpsampled,IBranchUpsampled]);
repeatFactor = 4;
% Repeat the generated BPSK signal to see the adjacent bands spectrum
updata = repmat(gpsBBWaveform(:).',repeatFactor,1);
updata = updata(:);
bbscope = dsp.SpectrumAnalyzer('SampleRate',10*1.023e6*repeatFactor, ...
'PlotAsTwoSidedSpectrum',true, ...
'SpectrumType','Power density', ...
'AveragingMethod','Exponential', ...
'SpectrumUnits','dBW', ...
'YLimits',[-120,-50], ...
'Title','Power Spectral Density of Complex Baseband GPS Signal');
bbscope(updata);
end
Question 7: Softhandover and hardhandover
%SoftHandover Probablity
x=1:.1:10;
z=10.^(x/33.6);
w=(z+1).^2
y=1-(4./w);
plot (x,y)
xlabel('SHO Threshold (dB)')
ylabel('SHO Probability')
title('SHO Probability as a function of the Threshold Value')
grid

Question 8: UMTS transmitter and receiver (uplink and downlink)


openExample('lte/UMTSUplinkWaveformGenerationExample')
rc = 'RMC384kbps';
config = umtsUplinkReferenceChannels(rc);
waveform = umtsUplinkWaveformGenerator(config);
saScope = dsp.SpectrumAnalyzer('SampleRate', 3.84e6*config.OversamplingRatio);
saScope(waveform);
Question 9: IEEE 802.11 WLAN
%% IEEE 802.11 WLAN

EsNoRange=[0:2:10]; % Range of noice levels to calculate BER


NumPackets=2;
PacketSizeBytes=1024;
PacketSizeBits=PacketSizeBytes*8; % Here we ignore preamble and sync bits
clear BERResults;
%% System parameters and constants
% Specify a number of system constants.
% Spreading parameters
Barker=[1 -1 1 1 -1 1 1 1 -1 -1 -1]'; % Barker sequence
SpreadingRate=length(Barker); % Spreading rate
% Upsampling rate
SamplesPerChip=8;
% Filter order and coefficients - root raised cosine
FilterOrder=40; % Set to multiple of SamplesPerChip to make delay calculation easy
h=firrcos(FilterOrder,7e6,.7,88e6,'rolloff','sqrt',FilterOrder/2,kaiser(FilterOrder+1
,1));
%% Delay calculation
% Calclate (specify) the net number of bits delay in the link due
% to the filtering.
%
% * samples_delay = 2 filters x (40 coeffs / 2) = 40 samples
% * chips_delay = sample_delay/SamplesPerChip = 40/8 = 5 chips
% * Must recalculate delay if you change any of these parameters
% We must delay the signal 6 more chips to align it with the 11 chip
% boundary. This results in an 11 chip delay or one symbol/bit delay.
% You must recalculate total and additional delay if you change any of these
% parameters
BitDelay=1;
ChipDelayAdd=6;
%% Main BER loop
% Calculates the BER for each EsNo level.
NumEsNos=length(EsNoRange);
disp(' ');disp('Start Simulation');
for EsNoIndex =1:NumEsNos

EsNo=EsNoRange(EsNoIndex);
disp(['Simulating: EsNo=' num2str(EsNo) 'dB']);
SNR=EsNo+10*log10(1/SpreadingRate)+10*log10(1/SamplesPerChip);
% Initialize system and simulation measurements state
% Bits
TotalBits= false; % Bit count for BER calculation
ErrorBits=false; % Error count for BER calculation
LastTxSymbol=1; % Set DBPKS Modulator state
LastRxSymbol=1; % Set DBPKS Demodulator state
% Filters
Rx_chips_delayed_store=zeros(ChipDelayAdd,1);
Tx_bits_delayed_store=true;
Tx_Filter_State=h(1:end-1); % Fill filter with a +1 symbol
Rx_Filter_State=h(1:end-1); % Fill filter with a +1 symbol
% Main simulation loop
% Each packet is transmitted, and the recieved bits compared with the
% transmitted bits to calculate the BER.
for Packet=1:NumPackets
% Construct frame of bits
Tx_bits=rand(PacketSizeBits,1)>.5; % Random bits
% Modulate
Tx_bits_bp=(1-2*Tx_bits); % Convert to bipolar 0,1 --> 1,
-1
Tx_symbols=LastTxSymbol*cumprod(Tx_bits_bp); % New DBPSK symbol = previous *
1 or -1
LastTxSymbol=Tx_symbols(end); % Store modulator state (last
symbol)
% Spread symbols with Barker code, upsampling by spreading rate
Tx_chips=reshape(Barker*Tx_symbols',[],1); % Multiply by barker and reshape
to a columm
Tx_chips=complex(Tx_chips); % Make complex to ensure correct baseband
transmission
% Upsample chips by SamplesPerChip factor
Tx_samples=zeros(length(Tx_chips)*SamplesPerChip,1); % Create empty
Tx_samples
Tx_samples(1:SamplesPerChip:end,1)=sqrt(SamplesPerChip)*Tx_chips; % Normalize
power due to upsampling
% Tx Filter
[Tx_samples_filtered,Tx_Filter_State]=filter(h,1,Tx_samples,Tx_Filter_State);
% Filter
Tx_samples_filtered=Tx_samples_filtered*2.495; % Set output power to 1W
var(Tx_samples_filtered); % Calculate Tx signal power, view by removing ';'
% Transmit though AWGN Channel assuming 0dBW input power (check
% with line above)
Rx_samples_unfiltered = awgn(Tx_samples_filtered,SNR,0);
% Rx Filter

[Rx_samples_filtered,Rx_Filter_State]=filter(h,1,Rx_samples_unfiltered,Rx_Filter_Stat
e);
% Downsample - sample chips
Rx_chips=Rx_samples_filtered(1:SamplesPerChip:end);
% Add 1 chip delay to move signal to 11 chip boundary
Rx_chips_delayed=[Rx_chips_delayed_store; Rx_chips(1:end-ChipDelayAdd)];
Rx_chips_delayed_store=Rx_chips((end-ChipDelayAdd+1):end); % Store delayed
chips
% Despread - sample symbol
Rx_symbols=Barker'*reshape(Rx_chips_delayed,SpreadingRate,PacketSizeBits); %
Multiply by Barker
Rx_symbols=Rx_symbols(:)/SpreadingRate; % Make a column and normalize
% Demodulate
Rx_symbols_plus_last=[LastRxSymbol; Rx_symbols];
Rx_symbols_plus_last_mult=Rx_symbols_plus_last(1:end-
1).*conj(Rx_symbols_plus_last(2:end));
Rx_bits=Rx_symbols_plus_last_mult < 0;
LastRxSymbol=Rx_symbols(end); % Demodulator state
% Calculate BER
% Add BitDelay to Tx signal to align with Rx signal
Tx_bits_delayed=[Tx_bits_delayed_store; Tx_bits(1:end-BitDelay)];
Tx_bits_delayed_store=Tx_bits(end-BitDelay+1:end); % Store delayed symbol
if Packet==1 % Ignore delayed bits on first packet
TotalBits=TotalBits+length(Rx_bits)-BitDelay;

ErrorBits=ErrorBits+sum(Tx_bits_delayed(BitDelay+1:end)~=Rx_bits(BitDelay+1:end));
else
TotalBits=TotalBits+length(Rx_bits); % Calculate total bits
ErrorBits=ErrorBits+sum(Tx_bits_delayed~=Rx_bits); % Compare Tx and Rx
bits
end
end
BERResults(EsNoIndex)=ErrorBits/TotalBits; % Calculate BER
end
%% Plot BER Results
% Plot the BER results Vs EsNo.
semilogy(EsNoRange,BERResults,'*-');
grid;
title('802.11b 1Mbps');
ylabel('BER')
xlabel('EsNo');

You might also like